# Example: Thermocouple Monitoring

Read a thermocouple channel, inspect its status bit, and raise a fault flag when the sensor fails.

The SLM-THM-4 differs from other analog modules in two ways: readings are already linearised and reported as floating-point temperatures in the configured unit, and the module exposes a **burnout status bit** per channel that indicates an open-circuit condition independently of the reading itself.

## Hardware

| Slot | Module |
|---|---|
| 1 | **SLM-THM-4** (4-channel thermocouple input) |

Wire a Type K thermocouple on channel 1.

## Backplane configuration

Open **Device → Backplane Configuration**, select slot 1, and set:

| Field | Set to |
|---|---|
| **Channels Enabled** | CH1 - CH4 |
| **Burnout Detection / Units** | High burnout, degrees C |
| **CH1 Type** | Type K |
| **CH2 - CH4 Type** | as fitted |

Each channel's sensor type is set independently.

Thermocouple channels are always reported as `REAL` on `%ID`:

| Slot | Channel | Address | Alias |
|---|---|---|---|
| 1 | TC1 | `%ID0` | `Furnace_Temp` |
| 1 | TC1 Burnout | `%IX0.0` | `TC1_Burnout` |
| 1 | TC2 | `%ID1` | `Inlet_Temp` |
| 1 | TC2 Burnout | `%IX0.1` | `TC2_Burnout` |
| 1 | TC3 | `%ID2` | `Outlet_Temp` |
| 1 | TC3 Burnout | `%IX0.2` | `TC3_Burnout` |
| 1 | TC4 | `%ID3` | `Ambient_Temp` |
| 1 | TC4 Burnout | `%IX0.3` | `TC4_Burnout` |

## The program

### Variables

`````{tab-set}
````{tab-item} Variables table
| Name | Class | Type | Location | Initial Value | Documentation |
|---|---|---|---|---|---|
| `furnace_temp` | Local | `REAL` | `Furnace_Temp` | | Channel 1 temperature |
| `tc1_burnout` | Local | `BOOL` | `TC1_Burnout` | | Channel 1 burnout status bit |
| `sensor_valid` | Local | `BOOL` | | | TRUE while the reading is trusted |
| `last_valid_temp` | Local | `REAL` | | | Most recent trusted reading |
````

````{tab-item} Text mode
```pascal
  VAR
    furnace_temp : REAL AT Furnace_Temp; (* Channel 1 temperature *)
    tc1_burnout : BOOL AT TC1_Burnout; (* Channel 1 burnout status bit *)
    sensor_valid : BOOL; (* TRUE while the reading is trusted *)
    last_valid_temp : REAL; (* Most recent trusted reading *)
  END_VAR
```
````
`````

### Code body

```pascal
sensor_valid := NOT tc1_burnout;

IF sensor_valid THEN
  last_valid_temp := furnace_temp;
END_IF;
```

The `burnout` bit is read directly from the module; it is not inferred from the reading value. On a burnout condition, the program freezes `last_valid_temp` and the rest of the logic can test `sensor_valid` to decide how to respond.

## Burnout status bit

The **Burnout Detection** setting determines what the reading does when the thermocouple circuit opens:

- **High burnout** drives the reading to the top of the range. This is the safer choice for heating: a broken sensor reads as over-temperature, so control logic that acts on the reading turns the heat off.
- **Low burnout** drives the reading to the bottom of the range. In a heating application this is dangerous: a broken sensor reads as a cold process, the control logic calls for more heat, and the temperature can run away.

In general, choose the direction that drives your control logic toward its safe state when the sensor fails. This example monitors a furnace, so it uses **High burnout**.

The burnout status bit is set in either case. Do not rely on the burnout direction alone: read the bit and act on it, as the program above does. The bit is more reliable than inferring a fault from the value, because it is set directly by the module's open-circuit detection circuit.

## Related examples

- [Multi-channel Thermocouple](multi-channel-thermocouple.md) — a loop-based version that reads all four channels and their status bits.
