Skip to content

ST Examples

Every channel in IO Mapping is already exposed as a global variable through its DefaultMapping name — IN0–IN6, OUT0–OUT5, AN0–AN2, LED and TEMPERATURE are usable directly in any POU without declaring or mapping them.

PROGRAM PLC_PRG
VAR
blinker : TON;
END_VAR
blinker(IN := NOT blinker.Q, PT := T#500ms);
IF blinker.Q THEN
LED := NOT LED;
END_IF

Mirror each digital input onto the corresponding output:

PROGRAM PLC_PRG
OUT0 := IN0;
OUT1 := IN1;
OUT2 := IN2;
OUT3 := IN3;
OUT4 := IN4;
OUT5 := IN5;

AN0–AN2 are raw 12-bit ADC counts, 0…4095 over 0…3.3 V. Half scale is 2048:

PROGRAM PLC_PRG
OUT0 := AN0 > 2048; // above ~1.65 V

Converting to volts:

PROGRAM PLC_PRG
VAR
rVolt : REAL;
END_VAR
rVolt := WORD_TO_REAL(AN0) * 3.3 / 4095.0;

Any output can be switched to PWM at runtime — see IO Mapping › PWM outputs.

PROGRAM PLC_PRG
VAR
ramp : UINT;
END_VAR
PWM_ENABLE := 2#0000_0100; // OUT2 (GP8) becomes a PWM output
ramp := ramp + 256; // wraps on its own at 65535
PWM2 := ramp; // slow fade

To go back to on/off, clear the bit: PWM_ENABLE := 0; and OUT2 commands the pin again.

The carrier frequency is not set from ST: it is a device parameter (9200 for OUT0/OUT1, 9201 for OUT2/OUT3 and the LED, 9202 for OUT4/OUT5), applied when the application starts. The duty stays 0…65535 whatever frequency you pick.

PROGRAM PLC_PRG
OUT5 := TEMPERATURE > 70.0; // drive an alarm output past 70 °C

TEMPERATURE is the die temperature of the RP2350A, not the ambient temperature.

See Serial Ports for a complete open/write/read example over COM2 and COM3.