Hysteresis and alarm memory in Structured Text
The Core Idea
Alarm condition, stored alarm state, and operator acknowledgement are different pieces of information. Hysteresis gives switching behavior a gap, while memory lets the program represent events that must outlast one scan.
What you will learn
Give an alarm separate on and off limits, so a noisy measurement cannot switch it on and off.
Write the band between the limits as memory: an
IFthat changes the alarm only at a limit.Sound a horn once per new alarm, and let acknowledgement silence the horn without clearing the alarm.
Why it matters
Operators need an indication they can interpret and an acknowledgement with a defined meaning. Those requirements need more than a single comparison.
The problem
A tank has a high-level alarm at 80 %. The lesson simulator runs the tank beside your program, and its level transmitter is noisy by up to ±1 %, like a real one on a sloshing tank. The tank starts at 80 %.
| Signal | Type | Meaning |
LEVEL_PCT | REAL | Measured level, in %. The tank writes it. |
ACK_PB | BOOL | TRUE while ACK is pressed (momentary). |
FILL_PB, DRAIN_PB | BOOL | Run the fill pump and open the drain valve while pressed. |
HIGH_ALARM | BOOL | The high-level alarm. |
HORN | BOOL | Sounds when the alarm turns on, until someone presses ACK. |
ALARM_MEM | BOOL | HIGH_ALARM from the previous scan. |
The horn logic compares HIGH_ALARM with ALARM_MEM to spot a new alarm, the edge from the edges lesson. The alarm itself is one comparison: LEVEL_PCT >= 80.0. The simulator scans every 100 ms.
After you lock in your prediction, watch the trend, the alarm, and the horn. Then press ACK (acknowledge) and keep watching.
See it go wrong
Hold DRAIN until the level is near 76 %: the alarm goes off, although the tank is still nearly full.
Fix it
Change the alarm so it turns on at or above 80 % and turns off only at or below 75 %. Leave the horn logic as it is. The checks run the same noisy tank: they press ACK while the level hovers at 80 %, drain the tank below 75 %, and fill it again. Editing pauses the program, so press Run to try your version.
Passing the checks records Structured Text progress on the shared hysteresis concept.
What happened and why
One threshold gives the alarm no memory. The program recalculated it from the latest reading on every scan, so noise of ±1 % turned one high level into dozens of alarms. Each one was a real edge, so the horn logic was right to sound for each.
The fix writes the alarm in two branches with a gap between them:
| Measured level | Branch that runs | HIGH_ALARM |
| 80 % or above | IF | Set TRUE |
| Between 75 % and 80 % | Neither | Keeps its last value |
| 75 % or below | ELSIF | Set FALSE |
When neither branch runs, the variable keeps the value the last scan left in it. That is the memory, and the gap between the limits is the hysteresis band. Make the band wider than the noise: ±1 % never moves a reading from 80 % to 75 %.
Acknowledgement is a separate piece of memory. ACK clears HORN and nothing else, so the alarm stays on while the tank is full, and the horn stays silent until the alarm clears and comes back.
Common mistakes
One threshold for on and off: the alarm follows every swing of the noise. Give it two limits.
Clearing just below the trip point:
ELSIF LEVEL_PCT < 80.0is the same single threshold written in two branches. The off limit must leave a band.Swapping the limits: the alarm turns on at 75 %, before the tank is too full.
Letting ACK clear the alarm: the next scan finds the level still high and raises a new alarm. ACK acknowledges; only the level clears the alarm.
Sounding the horn on the alarm, not on a new alarm:
IF HIGH_ALARM THEN HORN := TRUEsounds again on the scan after ACK is released.
Platform notes
Alarm systems usually call the band a deadband and set it per alarm, often with an on-delay as well. Many controllers and human-machine interfaces (HMIs) also have built-in alarm blocks that handle the deadband and acknowledgement for you.
Enable JavaScript to run the embedded simulator and complete the interactive exercises.