IMDHMIControls LibraryShop main store

How-to

Siren ring count ladder logic with a timer and counter

PLC programming Published 6 min read

Short answer

Edge-detect each of the three signals, move its ring count into a stored tag once, and run the siren from two timers — one for sound, one for the pause between rings — while a counter totals completed rings. With the worked sound and pause presets, the three patterns sit 2.5 s apart, and a new request is accepted only while the sequence is idle.

On this page
  1. Fix the four gaps the request leaves open
  2. Treat each request as an event, not a level
  3. Build the rungs in this order
  4. Prove the pattern with the siren disconnected
  5. Trace a wrong pattern to its rung
  6. The decision for each case
  7. Questions asked

Edge-detect each of the three request signals, move its ring count into a stored tag exactly once, and run the siren from two timers — one for the sound of a ring, one for the pause between rings — while a counter totals the rings that have finished. The sequence ends when the counter reaches the stored count, and a new request is accepted only while the sequence is idle. In TIA Portal on an S7-1200 that is two TON timers, one CTU counter and five plain rungs; the same structure runs on any IEC 61131-3 controller. The two timer presets decide everything about how the pattern sounds, and the worked example below derives every duration from them.

Fix the four gaps the request leaves open #

The request fixes the ring counts — three, two and one — and nothing else. Before writing rungs, decide the sound time per ring, the pause between rings, whether each input is a momentary pulse or a signal that stays on until the event clears, and what a second request during a running pattern does. Define one ring as one complete sound interval plus the pause that follows it. For the worked program take 1.5 s of sound and 1.0 s of pause, agreed with whoever owns the panel. Call those two values sound and pause in the arithmetic below:

  • 1 ring: 1 × sound = 1.5 s
  • 2 rings: 2 × sound + 1 × pause = 4.0 s
  • 3 rings: 3 × sound + 2 × pause = 6.5 s

Each longer pattern adds one sound-and-pause pair, 2.5 s, so the three patterns sit 2.5 s apart and an operator can hear which one sounded. Commit the retrigger policy together with the times: this program ignores a request that arrives while a pattern is running, and when two requests are true in the same scan the three-ring request wins, decided by the fixed evaluation order in the next section rather than by rung-order accident.

Treat each request as an event, not a level #

Put a rising-edge contact (an R_TRIG, or the P contact in ladder) on each of the three inputs and let only the edge start a pattern. A signal that stays on until the event clears then produces one pattern per closure; a level-triggered start would re-launch the pattern every scan and sound the siren continuously. Watch each input online while operating its source: you want one clean low-to-high transition, and any pulse must last at least one scan — a pulse shorter than the scan time can be missed entirely and needs conditioning upstream. Acting once per event and ignoring a level that has already been acted on is the same discipline as latching two level inputs for pump start and stop control.

Build the rungs in this order #

  1. Create the tags — the names are illustrative, so keep your project convention: Request_1, Request_2, Request_3 (Bool, the field signals), Seq_Busy (Bool, starts FALSE), Rings_Wanted (Int, 0), On_Phase (Bool, FALSE), Siren (Bool, the coil behind the siren relay), Rings_Done (Int, read from the counter), and two TON instances, TON_Sound and TON_Pause.
  2. Selection rung: edge of Request_3, then edge of Request_2, then edge of Request_1, in that fixed order. The first edge that fires moves 3, 2 or 1 into Rings_Wanted and inhibits the branches below it for that scan — that order is the priority rule. If Seq_Busy is FALSE, set Seq_Busy TRUE and set On_Phase TRUE.
  3. Sound phase: give TON_Sound an IN of Seq_Busy AND On_Phase and a PT set to the sound preset as a TIME value. A TON holds Q off until IN has been true for the preset and resets when IN drops, so every ring re-times from zero. When TON_Sound.Q rises, one ring is complete: clear On_Phase.
  4. Count the ring: a CTU increments CV once per rising edge at CU, resets to zero while R is TRUE, and sets Q when CV reaches PV. Wire CU to TON_Sound.Q, PV to Rings_Wanted and R to NOT Seq_Busy, so Rings_Done climbs 1, 2, 3 and CTU.Q means finished. Each S7-1200 counter keeps its instance structure in a data block.
  5. Pause phase: give TON_Pause an IN of Seq_Busy AND NOT On_Phase and a PT of T#1s. When it times out, set On_Phase TRUE for the next ring — unless the counter is done, in which case clear Seq_Busy and the sequence is idle again.
  6. Output rung: Siren = Seq_Busy AND On_Phase. The siren is on only inside a sound phase, never during a pause and never while idle.
  7. To reuse the pattern, wrap steps 2 to 6 in a function block with an Int ring-count input, a Bool execute and a Bool siren output, placing the two timers and the counter as multi-instance data when the call dialog asks; one call per device then gives each device its own sequence.

If you later rewrite those two timers in structured text, read the account of when a CODESYS TON works in structured text but not ladder first — the timer edge cases that trip one language trip the other.

Prove the pattern with the siren disconnected #

Force Request_3 with a momentary toggle and watch Siren, On_Phase and Rings_Done online. The expected trace: sound for one sound-phase interval, CV reaches 1 when TON_Sound.Q rises, pause through the pause preset; sound again, CV 2; pause; sound a third time, CV 3 equals PV; one last pause, then Seq_Busy clears and CV resets to 0 — total 7.5 s from the start edge. Force Request_1 and you must see one single-ring burst with idle again at 2.5 s. Hold Request_2 on for ten seconds and you must see exactly one 4.0 s pattern — if it repeats, the start rung is seeing the level, not the edge. Test with the siren physically disconnected or a lamp on the point, and tell operations while it is, because the panel has no audible alarm during the test.

Trace a wrong pattern to its rung #

  • Nothing rings: watch the three request tags while operating each source. No transition reaching the logic is a field-signal or addressing problem — fix that before touching the sequence.
  • Pattern repeats: the selection rung is level-triggered or Seq_Busy is not gating it. The edge contact is missing, or it sits after the busy test.
  • Wrong ring count: read Rings_Wanted when the sequence starts and Rings_Done when it ends. A stored count that is wrong points at selection; a stored count that is right but a short CV points at the CU edge from TON_Sound.Q not arriving.
  • Siren sticks on: On_Phase never cleared, so TON_Sound never reached Q. Check the PT and that IN stayed true through the whole phase.
  • Logic commands the output but nothing sounds: stop editing logic and measure the output point and the siren supply path against the panel drawings.

The decision for each case #

  • Request 1: one single-ring burst; sequence idle again at 2.5 s.
  • Request 2: two bursts; a 4.0 s pattern, idle at 5.0 s.
  • Request 3: three bursts; a 6.5 s pattern, idle at 7.5 s.
  • A second request during any pattern: ignored until idle, and the input must drop and rise again to start a new one.
  • Two requests true in the same scan: three rings, by the written priority order.
  • Different timing wanted: change the two PT presets only; the counts and the rungs stay as built.

Questions asked

Do the sound and pause times have to be equal?

No, and they usually are not. The stored count only sets how many on and off phases run; the two presets set how long each phase lasts. The worked example derives the three pattern lengths from the sound and pause presets fixed in the first section. Change the presets to 2.0 s and 0.5 s and the same rungs give 2.0 s, 4.5 s and 7.0 s. Keep the pause long enough that an operator clearly hears the break between rings.

What happens if the button is pressed twice in a row?

In this program the second press is ignored: the selection rung only accepts a request while the sequence is idle, so nothing happens until the pattern finishes and the input drops and rises again. If the process needs requests to queue, add another counter to hold pending requests and decide how many it may hold. Settle this before commissioning, because an accidental retrigger in the middle of a three-ring pattern is what makes annunciation hard to read.

Can the same logic drive a beacon and a horn together?

Yes. The output rung is one Boolean, so branch it to as many physical points as the pattern needs, or keep the sequence as a function block with a ring-count input, an execute input and a siren output, and call it once per device. Each call keeps its own timers and counter instance, so a three-ring horn and a two-ring beacon can run from separate requests without interfering.

How long is the whole three-ring pattern including the last pause?

Three rings run 7.5 s from the rising edge to idle: the full audible pattern plus the trailing 1.0 s pause phase before the busy bit clears. The one-ring and two-ring requests go idle at 2.5 s and 5.0 s the same way. If an operator would read that trailing pause as a missed ring, end the sequence at the final sound phase instead and clear the busy bit one phase early.

Keep reading

  • How-to

    How to build ladder logic practice projects in STEP 7

    Get STEP 7 ladder practice projects from the vendor's own support portal and from the samples the installer already placed on your PC, not from a copy of a book's bundled disk. Then rebuild three circuits yourself: a start/stop latch with overload interlock, an on-delay timer sequence, and an up/down counter.

    PLC programming

  • How-to

    Latch two level inputs for pump start and stop control

    Use one reset-dominant latch: set the pump when the low level probe reads dry and reset it when the high probe reads wet, so the pump holds its state between the probes. A rung that only compares the inputs drops out the moment water covers the low probe; the latch turns the probe spacing into hysteresis.

    PLC programming

  • Troubleshooting

    Start a PID ramp soak profile from ladder logic

    The profile never starts from ladder because the JMP stage handoff leaves the old stage on for three more scans, which swallows the one-scan PD pulse that must set the ramp/soak start bit. Replace the jump with SET and RST stage logic, then verify bit 11, the +33 octal control word and the +35 error flags before touching the PID instruction or table values.

    PLC programming