Example: Multi-channel Thermocouple#
The Thermocouple Monitoring example reads one channel. This variation reads all four channels of an SLM-THM-4 using a FOR loop and arrays, with per-channel burnout tracking.
Hardware#
Slot |
Module |
|---|---|
1 |
SLM-THM-4 (4-channel thermocouple input) |
Wire thermocouples on channels 1 through 4.
Backplane configuration#
Same as the base example. Configure each channel’s sensor type to match the fitted thermocouples.
Slot |
Channel |
Address |
Alias |
|---|---|---|---|
1 |
TC1 |
|
|
1 |
TC1 Burnout |
|
|
1 |
TC2 |
|
|
1 |
TC2 Burnout |
|
|
1 |
TC3 |
|
|
1 |
TC3 Burnout |
|
|
1 |
TC4 |
|
|
1 |
TC4 Burnout |
|
|
The program#
Variables#
Name |
Class |
Type |
Location |
Initial Value |
Documentation |
|---|---|---|---|---|---|
|
Local |
|
|
Channel 1 |
|
|
Local |
|
|
Channel 2 |
|
|
Local |
|
|
Channel 3 |
|
|
Local |
|
|
Channel 4 |
|
|
Local |
|
|
Channel 1 burnout |
|
|
Local |
|
|
Channel 2 burnout |
|
|
Local |
|
|
Channel 3 burnout |
|
|
Local |
|
|
Channel 4 burnout |
|
|
Local |
|
Gathered readings |
||
|
Local |
|
Gathered status bits |
||
|
Local |
|
Loop counter |
||
|
Local |
|
TRUE if any channel is in burnout |
VAR
tc1 : REAL AT TC1_Temp;
tc2 : REAL AT TC2_Temp;
tc3 : REAL AT TC3_Temp;
tc4 : REAL AT TC4_Temp;
tc1_bo : BOOL AT TC1_Burnout;
tc2_bo : BOOL AT TC2_Burnout;
tc3_bo : BOOL AT TC3_Burnout;
tc4_bo : BOOL AT TC4_Burnout;
temps : ARRAY [1..4] OF REAL;
burnouts : ARRAY [1..4] OF BOOL;
i : INT;
any_fault : BOOL;
END_VAR
Code body#
temps[1] := tc1; burnouts[1] := tc1_bo;
temps[2] := tc2; burnouts[2] := tc2_bo;
temps[3] := tc3; burnouts[3] := tc3_bo;
temps[4] := tc4; burnouts[4] := tc4_bo;
any_fault := FALSE;
FOR i := 1 TO 4 DO
IF burnouts[i] THEN
any_fault := TRUE;
END_IF;
END_FOR;
A located variable can also be declared as an array, bound to consecutive addresses (OpenPLC Editor 4.3.0 or newer):
temps AT %ID0 : ARRAY [1..4] OF REAL; (* %ID0 to %ID3 *)
burnouts AT %IX0.0 : ARRAY [1..4] OF BOOL; (* %IX0.0 to %IX0.3 *)
This example binds each channel through its alias instead and copies it into the array, so the program keeps reading the correct channels if the IEC addresses change. Arrays and other custom data types are covered in the OpenPLC data types documentation.