FB_PWM (Function Block)
Generates a pulse-width modulated (PWM) signal.
The output switches between Amplitude and 0 at a fixed Period.
DutyCycle controls the proportion of the period the output is high,
as a value between -1 and 1.
For example, a duty cycle of 0.3 produces a high output for 30% of the period and a low output for the remaining 70%. A duty cycle of -0.3 inverts this, producing a low output for 30% and a high output for 70%.
A duty cycle of 0 keeps the output permanently low. A duty cycle of ±1 keeps it permanently high.
Phase shifts the wave horizontally in radians. Negative values shift
in the opposite direction.
Bias shifts the output vertically.
Note
The block is FINAL and must be instantiated, not extended.
Use FB_init to set tPeriod, fAmplitude, fBias,
and fDutyCycle at declaration time.
Extends: FB_PeriodicSignal
Properties
DutyCycle
Type: LREAL
Gets or sets the duty cycle as a value between -1 and 1.
This controls the proportion of the period the output is high. A value of 0.3 keeps the output high for 30% of the period. A negative value inverts the wave — -0.3 keeps the output low for 30% and high for the remaining 70%. Values outside -1..1 are clamped. Changes take effect immediately.
IsHigh
Type: BOOL
Gets whether the output is currently in its high state.
TRUE regardless of the values of Amplitude, Bias, or Phase.
Methods
FB_init
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
if TRUE, the retain variables are initialized (warm start / cold start) |
|
|
if TRUE, the instance afterwards gets moved into the copy code (online change) |
|
|
Duration of one full cycle. |
|
|
High-state output level. Low state is always 0. |
|
|
Shifts the output vertically. |
|
|
Proportion of the period the output is high. Clamped to -1..1. |
Reset
Restarts the wave from the beginning by resetting the accumulated time to zero. The duty cycle, phase, amplitude, and bias are unaffected.
Run
Advances the PWM signal by one time step.
Note
Must be called once per cycle on a single PLC task. If the measured cycle
time is zero or Period is zero, the method returns early without
updating the output.