Even though the control properties can be set very accurately, the hardware limits the accuracy of the measured signal of the output pin. |
PWFM channels are provided to the application as software channels 1...X. The software channel number is needed when the access function IO_PWFM_SET_CONFIG (FUN) is called.
The channel numbers are listed in section 3724 PLCopen Addresses / 3720 PLCopen Addresses.
PWFM channels are disabled by default.
To disable the channel, set the pwfmMode as follows:
Name |
Area |
Data Type |
Range |
Description |
pwfmMode |
Config |
ENUM |
IO_MODE_DISABLED |
Used mode. |
pwfmChn |
Config |
WORD |
1-24 |
Configured channel. |
Definitions: |
|
error: WORD;
|
Init: |
|
error := IO_PWFM_SET_CONFIG(i_PwfmMode:=IO_MODE_DISABLED,i_PwfmChn:=1); IF error <> 0 THEN (*error*) ; END_IF
|
When the channel is used as digital output, the state of the output is set with the variable DoState.
Name |
Area |
Data Type |
Range |
Description |
DoState |
%Q |
BOOL |
TRUE/FALSE |
|
pwfmMode |
Config |
ENUM |
IO_PWFM_MODE_DIGITAL_OUTPUT |
Used mode. |
pwfmChn |
Config |
WORD |
1-24 |
Configured channel. |
Definitions: |
|
error: WORD; o_PwfmChn1_DoState AT %QX16.0:BOOL;
|
Init: |
|
error := IO_PWFM_SET_CONFIG(i_PwfmMode:=IO_PWFM_MODE_DIGITAL_OUTPUT,i_PwfmChn:=1); IF error <> 0 THEN (*error*) ; END_IF
|
Run: |
(* Change DO state every application cycle. *) if o_PwfmChn1_DoState then o_PwfmChn1_DoState := FALSE; else o_PwfmChn1_DoState := TRUE; end_if
|
When the channel is used as direct PWFM, the ratio and frequency of the output can be set freely.
PWM frequencies can be configured under software control in groups of outputs.
|
Name |
Area |
Data Type |
Range |
Description |
Frequency |
%Q |
WORD |
10 - 3000 Hz |
Frequency for the output signal. |
Ratio |
%Q |
WORD |
0 - 1000 |
Ratio for output signal. |
pwfmMode |
Config |
ENUM |
IO_PWFM_MODE_DIRECT_PWFM |
Used mode (direct PWFM). |
pwfmChn |
Config |
WORD |
1-24 |
Configured channel. |
Definitions: |
|
error: WORD; o_PwfmChn1_Frequency AT %QW112:WORD; o_PwfmChn1_PulseRatio AT %QW16:WORD;
|
Init: |
|
error := IO_PWFM_SET_CONFIG(i_PwfmMode:=IO_PWFM_MODE_DIRECT_PWFM, i_PwfmChn:=1);
IF error <> 0 THEN (*error*) ; END_IF
|
Run: |
(* Set channel to 100Hz with pulse ratio 50%. *) o_PwfmChn1_Frequency := 100; o_PwfmChn1_PulseRatio := 500;
|
When step motor mode is selected, the wanted amount of pulses are defined to the output pin. The output signal frequency and pulse width can be set freely.
PWM frequencies can be configured under software control in groups of outputs.
|
Name |
Area |
Data Type |
Range |
Description |
Frequency |
%Q |
WORD |
10 - 3000 Hz |
Frequency for the output signal. |
Ratio |
%Q |
WORD |
0 - 1000 |
Ratio for output signal. |
Requested Pulses |
%Q |
WORD |
0 - 5000 |
Needed steps. This value is added to generated pulse count. Undone pulses can be read from this variable. |
pwfmMode |
Config |
ENUM |
IO_PWFM_STEP_MOTOR |
Used mode (step motor). |
pwfmChn |
Config |
WORD |
1-24 |
Configured channel. |
Definitions: |
|
error: WORD; timer1:TON; o_PwfmChn1_Frequency AT %QW112:WORD; o_PwfmChn1_PulseRatio AT %QW16:WORD; o_PwfmChn1_NeededSteps AT %QW17:WORD;
|
Init: |
|
error := IO_PWFM_SET_CONFIG(i_PwfmMode:=IO_PWFM_MODE_STEP_MOTOR,i_PwfmChn:=1);
IF error <> 0 THEN (*error*) ; END_IF
|
Run: |
(* Set channel to 100Hz with pulse ratio 50% *) o_PwfmChn1_Frequency := 100; o_PwfmChn1_PulseRatio := 500;
(* Request 10 pulses every 1s*) timer1(IN:=TRUE); if timer1.Q then timer1(IN:=FALSE,PT:=T#1s); |
o_PwfmChn1_NeededSteps := 10; (* %Q value is set after every second. *) else ; end_if
|
Source file Topic000644.htm
Last updated 21-Feb-2025