Pro
20 min

Tank Level Alarms with Hysteresis

analogscalinglevelalarmhysteresis
Tank Level Alarms with Hysteresis scenario preview

Ready to build this?

Sign up free — no credit card required. This scenario requires the Pro plan.

Sign up to play this scenario →

Already have an account? Log in

Briefing

A level transmitter returns raw ADC counts (0–10 000) proportional to tank fill. The formula: **Level % = LT_RAW / 10 000 × 100** gives 0 = empty, 5 000 = 50%, 10 000 = full. Simple threshold detection chatters: if the level sits at exactly 90% the alarm fires and clears every scan. **Hysteresis** solves this by using two setpoints — the alarm **sets** above 90% but only **clears** below 80%. The physics engine computes and publishes four BOOL signals: - **HIGH_SET** (level > 90%) — use this to S= HIGH_ALARM - **HIGH_CLEAR** (level < 80%) — use this to R= HIGH_ALARM - **LOW_SET** (level < 10%) — use this to S= LOW_ALARM - **LOW_CLEAR** (level > 20%) — use this to R= LOW_ALARM Your task is to implement the four-rung latch logic.

Objectives

  • HIGH_ALARM latches when level rises above 90% (HIGH_SET), clears below 80% (HIGH_CLEAR)
  • LOW_ALARM latches when level falls below 10% (LOW_SET), clears above 20% (LOW_CLEAR)

Hints

  • Use SET/RESET latch pairs: | HIGH_SET | S= HIGH_ALARM ; and | HIGH_CLEAR | R= HIGH_ALARM ;
  • The SET rung must come BEFORE the RESET rung for correct scan-order behaviour
  • For LOW_ALARM: | LOW_SET | S= LOW_ALARM ; and | LOW_CLEAR | R= LOW_ALARM ;

I/O Table

Inputs

LT_RAW

Level transmitter raw counts (0–10000)

INT · %IW0

HIGH_SET

Physics: level > 90% — set high alarm

BOOL · %I0.0

HIGH_CLEAR

Physics: level < 80% — clear high alarm

BOOL · %I0.1

LOW_SET

Physics: level < 10% — set low alarm

BOOL · %I0.2

LOW_CLEAR

Physics: level > 20% — clear low alarm

BOOL · %I0.3

Outputs

HIGH_ALARM

High-level alarm (latching with hysteresis)

BOOL · %Q0.0

LOW_ALARM

Low-level alarm (latching with hysteresis)

BOOL · %Q0.1

Your program will be tested against:

All test cases run automatically when you submit. Assertions are hidden until you pass.

  1. #1Level rises above 90% → HIGH_ALARM latches

    LT_RAW = 9100 (91%) → HIGH_SET true → HIGH_ALARM latches on

  2. #2Level drops to 85% (inside hysteresis band) → HIGH_ALARM stays on

    After HIGH_ALARM latches, level drops to 85% (between 80 and 90) — alarm must remain on

  3. #3Level drops below 80% → HIGH_ALARM clears

    After HIGH_ALARM latches, level drops to 75% (below HIGH_CLEAR) — alarm clears

  4. #4Level drops below 10% → LOW_ALARM latches

    LT_RAW = 800 (8%) → LOW_SET true → LOW_ALARM latches on

  5. #5Level recovers above 20% → LOW_ALARM clears

    LOW_ALARM latched; level rises to 25% (above LOW_CLEAR) — alarm clears

Ready to build this?

Sign up free — no credit card required. This scenario requires the Pro plan.

Sign up to play this scenario →

Already have an account? Log in