FB_SquareWave (Function Block)
Generates a square wave signal.
The raw wave alternates between +1 and -1 over one period. Amplitude
scales the wave and Bias shifts it vertically, giving an output that swings
between Bias + Amplitude and Bias - Amplitude.
Phase shifts the wave horizontally in radians. A phase of π starts the
wave in its low half-cycle, a phase of -π has the same effect.
Note
The block is FINAL and must be instantiated, not extended.
Use FB_init to set tPeriod, fAmplitude, fBias,
and fPhase at declaration time.
Extends: FB_PeriodicSignal
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. |
|
|
Scales the ±1 wave. Output swings between Bias ± Amplitude. |
|
|
Shifts the output up or down by a fixed value. |
|
|
Phase offset in radians. Shifts the wave horizontally. Negative values shift in the opposite direction. |
Reset
Restarts the wave from the beginning by resetting the accumulated time to zero. The phase, amplitude, and bias are unaffected.
Run
Advances the square wave 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.