PWM output
This instruction delivers a pulse width modulated output signal according to the specified DUT. Pulses are output from the specified channel when the control flag for this channel is FALSE and the execution condition is TRUE.
Input
Starting address of area containing the data table
Pulse output: 0 or 1
Use the following predefined DUT: F170_PulseOutput_PWM_DUT
The following parameters can be specified in the DUT:
Approximate frequency
Duty ratio (for pulse duration and period)
The ratio between the pulse duration and the period of a rectangular waveform. For a pulse train in which the pulse duration is 1ms and the pulse period is 4ms, the duty ratio is 0.25 or 25%.
As soon as you begin editing a program online (i.e., in RUN mode) using this instruction, pulse output will stop.
Set any high-speed counter allocated to a pulse output channel to "Unused" in the system registers.
If both the main program and the interrupt program contain code for the same channel, make sure both are not executed simultaneously.
The high-speed counter control flag (e.g. sys_bIsHscChannel0ControlActive) and the pulse output control flag (e.g. sys_bIsPulseChannel0Active) are assigned to the same special internal flag number (e.g. R903A). Therefore, when a high-speed counter instruction or a pulse output instruction is executed, both the high-speed counter control flag (e.g. sys_bIsHscChannel0ControlActive) and the pulse output control flag (e.g. sys_bIsPulseChannel0Active) for the channel used are TRUE. No other high-speed counter instruction or pulse output instruction can be executed as long as this flag is TRUE.
At a point close to the minimum or maximum duty ratio, the output is delayed, which may cause the duty ratio to differ from the specified value.
The duty ratio can be changed for each scan. The change becomes effective with the next pulse output. The frequency setting is only effective at the start of execution of an instruction.
We strongly recommend that you incorporate a forced stop option in your positioning program.
The status of the high-speed counter control flag or pulse output control flag may change while a scan is being carried out. For example, if the number of received bytes is read more than once different statuses may exist within one scan.
To run the FP0R in FP0 compatibility mode, you can download an FP0 program to the FP0R.
Channel and pulse output numbers
Channel no. | Pulse output | Pulse output method |
0 |
Y0 |
Pulse |
Y2 |
Direction | |
1 |
Y1 |
Pulse |
Y3 |
Direction |
System variables for memory areas used. Values in parentheses are valid for FP0 T32.
Description |
System variable |
|
---|---|---|
Pulse output: control flag for channel |
0 |
sys_bIsPulseChannel0Active |
1 |
sys_bIsPulseChannel1Active |
|
Pulse output: elapsed value for channel |
0 |
sys_diPulseChannel0ElapsedValue |
1 |
sys_diPulseChannel1ElapsedValue |
|
Pulse output: target value for channel |
0 |
sys_diPulseChannel0TargetValue |
1 |
sys_diPulseChannel1TargetValue |
|
High-speed counter or pulse output controlcode |
sys_wHscOrPulseControlCode |
In the global variable list you define variables that can be accessed by all POUs in the project.
The DUT F170_PulseOutput_PWM_DUT is predefined in the FP Library.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR_EXTERNAL
X6_bEnablePWM: BOOL:=FALSE;
END_VAR
VAR
dutPWMControl: F170_PulseOutput_PWM_DUT;
(*iFrequencyValue := 1: f=2.0Hz, T=502.5ms;*)
iPulseWidthModulationDuty: INT:=500;
(*500=50% duty*)
@'': @'';
END_VAR
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,E_MOVE!,Instance,15,1,21,5,,?DEN?D?AENO?C);
B(B_VARIN,,iPulseWidthModulationDuty,13,3,15,5,);
B(B_VAROUT,,dutPWMControl.iPulseWidthModulationDuty,21,3,23,5,);
B(B_CONTACT,,X6_bEnablePWM,4,2,6,4,);
L(6,3,15,3);
L(1,3,4,3);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_CONTACT,,X6_bEnablePWM,4,2,6,4,);
B(B_F,F170_PulseOutput_PWM!,Instance,13,1,26,6,,?DEN?Ds_dutDataTable?Hn_iPulseOutputChannel?AENO);
B(B_VARIN,,dutPWMControl,11,3,13,5,);
B(B_VARIN,,2,11,4,13,6,);
L(1,3,4,3);
L(6,3,13,3);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF (X6_bEnablePWM) then
dutPWMControl.iPulseWidthModulationDuty:=iPulseWidthModulationDuty;
END_IF;
IF (X6_bEnablePWM) then
F170_PulseOutput_PWM(s_dutDataTable := dutPWMControl,
n_iPulseOutputChannel := 2);
END_IF;