FB_TriangleWave (Function Block)

Generates a triangle wave signal.

The output rises linearly from -Amplitude to +Amplitude over the first half-cycle, then falls back to -Amplitude over the second half. Bias shifts the output vertically.

Phase shifts the wave horizontally in radians. A phase of π starts the wave at its peak rather than its trough.

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

bInitRetains

BOOL

if TRUE, the retain variables are initialized (warm start / cold start)

bInCopyCode

BOOL

if TRUE, the instance afterwards gets moved into the copy code (online change)

tPeriod

LTIME

Duration of one full cycle.

fAmplitude

LREAL

Scales the wave. Output swings between Bias ± Amplitude.

fBias

LREAL

Shifts the output vertically.

fPhase

LREAL

Phase offset in radians. Shifts the wave horizontally.

Reset

Restarts the wave from the beginning by resetting the accumulated time to zero. The phase, amplitude, and bias are unaffected.

Run

Advances the triangle 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.