Example: Engineering Units#
The Analog Threshold Control 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 |
|
|
2 |
DO1 |
|
|
2 |
DO2 |
|
|
2 |
DO3 |
|
|
2 |
DO4 |
|
|
The program#
Variables#
The level_raw row from the base example is gone, replaced by level_volts mapped directly to the input.
Name |
Class |
Type |
Location |
Initial Value |
Documentation |
|---|---|---|---|---|---|
|
Local |
|
|
0.0 - 10.0 V directly |
|
|
Local |
|
|
First lamp |
|
|
Local |
|
|
Second lamp |
|
|
Local |
|
|
Third lamp |
|
|
Local |
|
|
Fourth lamp |
|
|
Local |
|
How many lamps should be lit |
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#
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.