Simulation signals generated using Structured Text (ST)

This chapter describes simulation signals, which can be used during development and testing of the programming code. The machine or the hardware panel is often not available, when the PLC code and program needs to be tested. The hardware has possibly not arrived onsite, the machine is not built yet, or the PLC equipment is already shipped to the customer. Therefore, it can be advantageous to be able to simulate ‘sensor’ signals to verify that the PLC program is working as expected.

Below are programming code examples for four simulation signals, where the frequency and amplitude can be adjusted to meet your requirements.

The signals can be combined to create new simulation signals like this:

MySignalWave:= TriangleWave + SineWave;

Sine wave

VAR
 SineWave:	REAL;	//Wave signal
 n:	REAL;	//Counter
 a:	REAL:= 1;	//Amplitude
 hz:	REAL := 0.001;	//Hz
 END_VAR
n:= n + hz;
SineWave:= SIN (n);

Sine wave

Triangle wave

VAR
 n:	REAL;	//Counter
 a:	REAL:= 1;	//Amplitude
 hz:	REAL:= 0.001;	//Hz
 TriangleWave:	REAL;	//Wave signal
 Length :	REAL := 2;	//Length on/off signal
END_VAR
n:= n + hz;
TriangleWave:= a + n;
IF n > Length THEN
 n:= 0;
END_IF;

Triangle wave

Square wave

VAR
 n:	REAL;	//Counter
 a:	REAL:= 1;	//Amplitude
 hz:	REAL:= 0.001;	//Hz
 SquareWave:	REAL;	//Wavesignal
 Length :	REAL := 2;	//Length on/off signal
END_VAR
n:= n + hz;
SquareWave:= 0;
IF n > Length/2 THEN //50% duty cycle
 SquareWave:= a;
END_IF;
IF n > Length THEN
 n:= 0;
END_IF;

Square wave

Square wave

Square wave (filtered)

VAR
 n:	REAL;	//Counter
 a:	REAL:= 1;	//Amplitude
 hz:	REAL:= 0.001;	//Hz
 SquareWave:	REAL;	//Wave signal
 Length :	REAL := 2;	//Length on/off signal
 Filter :	LP_Filter;	//Filter Function block *)
 FSquareWave:	REAL;	//Wave signal filtered
END_VAR
n:= n + hz;
SquareWave:= 0;
IF n > Length/2 THEN //50% duty cycle
 SquareWave:= a;
END_IF;
IF n > Length THEN
 n:= 0;
END_IF;
//Filter signal
Filter(ValueRaw:= SquareWave,
 k:= 0.01,
 ValueFiltered => FSquareWave);

Square wave (filtered)Square wave (filtered)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top