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.
Blink the onboard LED
Section titled “Blink the onboard LED”PROGRAM PLC_PRGVAR blinker : TON;END_VAR
blinker(IN := NOT blinker.Q, PT := T#500ms);IF blinker.Q THEN LED := NOT LED;END_IFDigital pass-through
Section titled “Digital pass-through”Mirror each digital input onto the corresponding output:
PROGRAM PLC_PRGOUT0 := IN0;OUT1 := IN1;OUT2 := IN2;OUT3 := IN3;OUT4 := IN4;OUT5 := IN5;Analog threshold
Section titled “Analog threshold”AN0–AN2 are raw 12-bit ADC counts, 0…4095 over 0…3.3 V. Half scale is 2048:
PROGRAM PLC_PRGOUT0 := AN0 > 2048; // above ~1.65 VConverting to volts:
PROGRAM PLC_PRGVAR rVolt : REAL;END_VAR
rVolt := WORD_TO_REAL(AN0) * 3.3 / 4095.0;Dimming an output
Section titled “Dimming an output”Any output can be switched to PWM at runtime — see IO Mapping › PWM outputs.
PROGRAM PLC_PRGVAR ramp : UINT;END_VAR
PWM_ENABLE := 2#0000_0100; // OUT2 (GP8) becomes a PWM output
ramp := ramp + 256; // wraps on its own at 65535PWM2 := ramp; // slow fadeTo 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.
Temperature alarm
Section titled “Temperature alarm”PROGRAM PLC_PRGOUT5 := TEMPERATURE > 70.0; // drive an alarm output past 70 °CTEMPERATURE is the die temperature of the RP2350A, not the ambient temperature.
Serial communication
Section titled “Serial communication”See Serial Ports for a complete open/write/read example over COM2 and COM3.