Analog scaling and bounds in Structured Text

The Core Idea

Analog scaling translates an instrument signal into an engineering value. Range checks decide whether that value is usable; limiting a display or command is a separate choice from declaring a measurement valid.

What you will learn

  • Scale a 4–20 mA signal to engineering units in one assignment.

  • Keep the scaled value for decisions, and limit only a copy for display.

  • Judge whether a signal is a measurement at all, and keep a failed signal out of decisions.

Why it matters

A number that fits on a human-machine interface (HMI) is not necessarily a trustworthy measurement. The control decision must account for the signal's meaning as well as its displayed range.

The problem

A level transmitter on a tank sends 4–20 mA: 4 mA is empty, 20 mA is full. A fill pump may run while the level is below 90 %.

SignalTypeMeaning
LEVEL_MAREALThe transmitter signal the input card measures, in mA. Starts at 12.0 mA.
LEVEL_PCTREALScaled level, in %.
DISPLAY_PCTREALLevel for the tank graphic, which can only draw 0–100 %.
FILL_PERMITBOOLTRUE lets the fill pump run.

The program scales the signal, keeps the level inside 0–100 %, and permits the fill below 90 %. The lesson simulator scans every 100 ms.

After you lock in your prediction, type 0 into Transmitter: that is what the input card reads when a wire in the loop breaks.

See it go wrong

Try 22 mA too, a level the transmitter cannot measure. Then type 12 to put the signal back.

Fix it

Change the program so a signal below 3.8 mA or above 20.5 mA turns on SIGNAL_BAD and blocks the fill. Keep LEVEL_PCT unlimited, and limit only DISPLAY_PCT to 0–100 %. Hidden checks try signals just outside 4–20 mA that are still measurements, and a transmitter that signals its own failure. Editing pauses the program, so press Run to try your version.

Passing the checks records Structured Text progress on the shared analog-scaling concept.

What happened and why

Limiting a value replaces it. Once LEVEL_PCT was limited, a broken wire and an empty tank both read 0 %, and nothing after that line could tell them apart. The fix keeps two values with different jobs:

ValueLimited?Used for
LEVEL_PCTNoDecisions, while the signal is good; diagnosis
DISPLAY_PCTYes, 0–100 %The tank graphic only

Whether the signal is a measurement is a question about the signal, so the program answers it in mA. This lesson uses the band from the 4–20 mA fault-handling lesson: 3.8–20.5 mA is a measurement. A healthy transmitter can read a little outside 4–20 mA when the process is just past its calibrated range. Below 3.8 mA the loop is broken or the transmitter is signalling a failure, and above 20.5 mA it is signalling a failure.

FILL_PERMIT now needs two things: a level below 90 % and a good signal. With a bad signal, the program does not know the level, so it does not permit the fill.

Common mistakes

  • Limiting the value that decisions use: a broken wire reads as an empty tank. Limit a display copy instead.

  • Flagging a bad signal without using the flag: the lamp lights, but the pump still runs. Every decision that uses the level needs NOT SIGNAL_BAD.

  • Judging the scaled value instead of the signal: testing LEVEL_PCT < 0.0 calls 3.9 mA a failure, although the transmitter is healthy. Test LEVEL_MA against the measurement band.

  • Forgetting the 4 mA live zero: LEVEL_MA * 100.0 / 20.0 reads 60 % at 12 mA and 20 % when the tank is empty. Subtract 4 mA first, then scale the 16 mA span.

  • Limiting only one end: at 22 mA the display tries to draw 112.5 %.

Platform notes

  • IEC 61131-3 (the international standard for programmable controller languages) defines LIMIT(MN, IN, MX), which returns IN held between MN and MX. Many platforms also have a scaling instruction that converts raw input counts to engineering units. This simulator has neither, so the lesson writes both with IF.

  • Many analog input cards detect a broken wire themselves and set a status bit. Use that bit where you have it, as well as the range check.

Enable JavaScript to run the embedded simulator and complete the interactive exercises.