3720/3724 PWFM

 

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.

 

Code examples

Disabled

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

 

 

Digital Output

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

 

Direct PWFM

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.

  • The setting is done by a PWM channel, setting the frequency of one channel sets also the frequencies of all the other channels in the same group.

  • The groups are indicated with the same PWM frequency channel number in section 3724 PLCopen Addresses / 3720 PLCopen Addresses.

 

 

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;

 

Step Motor

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.

  • The setting is done by a PWM channel, setting the frequency of one channel sets also the frequencies of all the other channels in the same group.

  • The groups are indicated with the same PWM frequency channel number in section 3720 PLCopen Addresses / 3724 PLCopen Addresses.

 

 

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