# Example: Engineering Units

The [Analog Threshold Control](analog-threshold-control.md) example reads raw counts and scales them to volts in the program. Switching the module's **Reading Format** to **Engineering Units** moves that conversion into the HAL: the channel appears directly as a `REAL` in the engineering unit of the module (volts, milliamps, degrees).

## Hardware

| Slot | Module |
|---|---|
| 1 | **SLM-AI-8-V** (8-channel 0-10 V analog input) |
| 2 | **SLM-DCO-15P** (15-channel sourcing DC output) |

Same wiring as the base example.

## Backplane configuration

Add both modules in order. Set the analog module's **Reading Format** to **Engineering Units**.

With Engineering Units selected, the analog channel occupies a `%ID` location (double-word real) rather than `%IW` (word integer):

| Slot | Channel | Address | Alias |
|---|---|---|---|
| 1 | AI1 | `%ID0` | `Level_Volts` |
| 2 | DO1 | `%QX0.0` | `Bar_1` |
| 2 | DO2 | `%QX0.1` | `Bar_2` |
| 2 | DO3 | `%QX0.2` | `Bar_3` |
| 2 | DO4 | `%QX0.3` | `Bar_4` |

## The program

### Variables

The `level_raw` row from the base example is gone, replaced by `level_volts` mapped directly to the input.

`````{tab-set}
````{tab-item} Variables table
| Name | Class | Type | Location | Initial Value | Documentation |
|---|---|---|---|---|---|
| `level_volts` | Local | `REAL` | `Level_Volts` | | 0.0 - 10.0 V directly |
| `bar_1` | Local | `BOOL` | `Bar_1` | | First lamp |
| `bar_2` | Local | `BOOL` | `Bar_2` | | Second lamp |
| `bar_3` | Local | `BOOL` | `Bar_3` | | Third lamp |
| `bar_4` | Local | `BOOL` | `Bar_4` | | Fourth lamp |
| `segments` | Local | `INT` | | | How many lamps should be lit |
````

````{tab-item} Text mode
```pascal
  VAR
    level_volts : REAL AT Level_Volts; (* 0.0 - 10.0 V directly *)
    bar_1 : BOOL AT Bar_1; (* First lamp *)
    bar_2 : BOOL AT Bar_2; (* Second lamp *)
    bar_3 : BOOL AT Bar_3; (* Third lamp *)
    bar_4 : BOOL AT Bar_4; (* Fourth lamp *)
    segments : INT; (* How many lamps should be lit *)
  END_VAR
```
````
`````

### Code body

```pascal
IF    level_volts >= 7.9 THEN segments := 4;
ELSIF level_volts >= 6.0 THEN segments := 3;
ELSIF level_volts >= 4.0 THEN segments := 2;
ELSIF level_volts >= 2.0 THEN segments := 1;
ELSE                          segments := 0;
END_IF;

bar_1 := segments >= 1;
bar_2 := segments >= 2;
bar_3 := segments >= 3;
bar_4 := segments >= 4;
```

The code is identical to the base example apart from the removed scaling line.
