How-to
Siren ring count ladder logic with a timer and counter
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
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 #
- 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_SoundandTON_Pause. - Selection rung: edge of
Request_3, then edge ofRequest_2, then edge ofRequest_1, in that fixed order. The first edge that fires moves 3, 2 or 1 intoRings_Wantedand inhibits the branches below it for that scan — that order is the priority rule. IfSeq_Busyis FALSE, setSeq_BusyTRUE and setOn_PhaseTRUE. - Sound phase: give
TON_Soundan IN ofSeq_BusyANDOn_Phaseand 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. WhenTON_Sound.Qrises, one ring is complete: clearOn_Phase. - 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 toRings_Wantedand R to NOTSeq_Busy, soRings_Doneclimbs 1, 2, 3 andCTU.Qmeans finished. Each S7-1200 counter keeps its instance structure in a data block. - Pause phase: give
TON_Pausean IN ofSeq_BusyAND NOTOn_Phaseand a PT of T#1s. When it times out, setOn_PhaseTRUE for the next ring — unless the counter is done, in which case clearSeq_Busyand the sequence is idle again. - Output rung:
Siren=Seq_BusyANDOn_Phase. The siren is on only inside a sound phase, never during a pause and never while idle. - 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_Busyis not gating it. The edge contact is missing, or it sits after the busy test. - Wrong ring count: read
Rings_Wantedwhen the sequence starts andRings_Donewhen 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 fromTON_Sound.Qnot arriving. - Siren sticks on:
On_Phasenever cleared, soTON_Soundnever 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.