How-to
How to Display a Time-Until-Closed Countdown on an HMI
Short answer
Display time until closed by computing the timer preset minus the accumulated value (.PRE - .ACC) in the PLC and binding the numeric display to that result. Clamp the value to zero when the done bit sets, keep the operator's duration in its own tag, and let the timer-done rung in the controller close the valve - never the panel.
On this page
A countdown to valve closure is a calculated tag, not something the timer gives you directly. An up-counting timer's .ACC rises from zero toward .PRE, so the panel must display .PRE minus .ACC, computed in the PLC every scan and clamped at zero when the done bit sets. The operator's numeric entry object writes a separate duration tag, and PLC logic copies it into the timer preset when the cycle starts. The panel takes the entry and shows the number; the timer-done rung in the controller closes the valve. The steps below build it for ControlLogix timers in a Studio 5000 project, and the structure transfers to any platform whose timer counts up.
Why .ACC displays the wrong number #
A TON instruction accumulates elapsed time in .ACC from zero up to .PRE, while its status bits .EN, .TT and .DN report rung energy, timing-in-progress and done. Displayed straight to the panel, .ACC answers 'how long has it been open' - the opposite of 'time until closed' - and no display format reverses an up-counter. Displaying .PRE shows the chosen duration and then sits still while the valve stays open. The remaining value has to be calculated. Before binding anything, a short read on timer status bits EN, TT, DN, ACC and PRE keeps the member names straight.
The tags behind the countdown #
Tag names below are illustrative; keep your site's naming convention and types.
Fill_Time_Req, DINT, milliseconds - the operator's requested open duration, written only by the HMI numeric entry. Initialize it to the process default.Fill_Timer, TON - the instruction, withFill_Timer.PREandFill_Timer.ACCholding millisecond values.Time_Until_Closed, DINT, milliseconds - the calculated countdown the panel displays.- The valve output rung, which references
Fill_Timer.DNand never a panel tag.
Validate Fill_Time_Req against your process minimum and maximum in the PLC before it reaches the preset; an entry-object range limit is operator convenience, not enforcement. If the chosen duration must survive a power cycle, retain the request tag the way keeping HMI-entered timer presets in PLC memory shows, instead of defaulting it at startup.
Compute the countdown in the PLC #
- At the start command, with process permissives true, copy
Fill_Time_ReqintoFill_Timer.PRE. - Run the TON on the valve-open condition. While the rung is true and
.DNis false,.ACCclimbs in milliseconds. - Every scan, subtract
Fill_Timer.ACCfromFill_Timer.PREand store the result inTime_Until_Closed. - Clamp in the same scan: if the subtraction result is negative or
Fill_Timer.DNis set, write 0 intoTime_Until_Closed. - Define the idle display. When the rung is false, either hold the last value, write 0, or blank the object with a visibility bit driven by
.EN. Choose one and document it, or the panel shows a stale number between cycles. - Close the valve from the rung: command AND permissives AND NOT
.DN. Nothing on this rung reads a panel tag.
Because step 1 is the only place the entry reaches the preset, a mid-cycle change to Fill_Time_Req does nothing until the next cycle - the safe default unless deliberately shortening an open valve is an intended operator action. When a preset is lowered under a running timer, the accumulator ends up larger than the preset; why an ACC value ends up larger than its PRE is exactly the case the clamp exists for, because without it the panel shows a negative number.
Point the two HMI objects at the right tags #
The numeric entry object binds to Fill_Time_Req; the numeric display object binds to Time_Until_Closed - never to .ACC or .PRE. Set three things on each:
- Entry: the range must match the PLC validation, and the units conversion must live in exactly one place. If the operator types seconds while the controller stores milliseconds, convert in the entry object or in the PLC, not both. A support-thread case from one controller vendor documents the trap: the panel showed 5.000 seconds while the controller held 5000 ms, and neither side owned the conversion.
- Display: one or two decimal places when showing seconds, so the value visibly moves between updates.
- Label: state the unit on screen. A bare number that means seconds on one screen and milliseconds on another is how countdowns get misread.
The millisecond-to-second conversion is the same job as scaling a PLC integer into an HMI display value. On Micro800 controllers, the ANY_TO_TIME instruction converts the numeric entry into the timer's time-format preset in place of a plain copy. If this screen also shows the tank the valve fills, animate the tank level graphic on the HMI screen from the level tag, not from the countdown tag.
Worked example: a 45-second fill on a millisecond timer #
Illustrative numbers, typical for a tank-fill valve; the application sets the real ones.
Inputs:
- Operator entry: 45 s, typed on the panel.
- Time base: 1 ms - ControlLogix TON instructions accumulate in milliseconds, so
.PREand.ACChold millisecond DINT values. - Conversion: 1000 ms per second.
- Check snapshot:
.ACC= 17,300 ms partway through the fill.
Rule in words: remaining time is the preset minus the accumulated value, both in milliseconds; the panel divides by 1000 to show seconds; the done bit forces zero.
Arithmetic:
- Preset: 45 s at 1000 ms/s is 45,000 ms, copied into
Fill_Timer.PRE. - Snapshot: 45,000 ms - 17,300 ms = 27,700 ms; 27,700 ms / 1000 = 27.7 s displayed.
- At done: 45,000 ms - 45,000 ms = 0 ms, so 0.0 s on the panel, and
.DNsets in the same scan - clamp and subtraction agree. - Cross-check: a display reading 17.3 s and rising is bound to
.ACC, not toTime_Until_Closed.
Result: the countdown leaves 45.0 s and lands on 0.0 s exactly when .DN sets.
Decision: accept the configuration when the first displayed value after start is 45.0 s, the last is 0.0 s with no negative in between, and the valve output drops on .DN. Any displayed value above 45.0 s or below 0.0 s is a binding or scaling error, not a timer fault.
Keep the closure in the controller #
The valve output rung belongs to the PLC: command AND permissives AND NOT .DN. A network dropout, a screen change or a panel restart must not be able to hold a tank valve open. Confirm the output's de-energized state is the valve's closed state before testing with fluid, and run one test with the panel disconnected - the valve must still close.
Test the sequence before it runs a process #
- Enter 45 s and start: online,
Fill_Time_Reqreads 45,000 andFill_Timer.PREreads 45,000 after the start scan. - Watch the countdown fall; at
.ACC= 17,300 the panel must read 27.7 s. - Confirm 0.0 s - never negative - at
.DN, with the valve output changing state in that scan. - Reset and start again: the idle behavior and the first displayed value repeat exactly.
- Change the entry mid-cycle: the countdown is either unaffected until the next cycle or shortens by design, and never goes negative.
- Wrong direction or frozen number: compare the four values online - request,
.PRE,.ACC,Time_Until_Closed- to separate a tag-mapping fault from a scaling fault.
Questions asked
Will a retentive timer work the same way for this countdown?
An RTO keeps its accumulated value when the rung goes false, and only the RES instruction clears it. The subtraction of preset minus accumulated still works, but you must define what the panel shows while the rung is false and the valve is idle, because the number freezes instead of resetting. For a plain valve-open duration, a TON restarted each cycle is easier to keep honest on the screen.
What happens if the operator lowers the duration while the valve is open?
If logic copies the new entry into the preset while the timer runs, the subtraction goes negative once the accumulated value passes the new preset, and the done condition turns on, closing the valve early. Copy the entry only at cycle start unless shortening an open valve is an intended operator action. Either way, the zero clamp keeps the display from showing a negative number.
How do I show the countdown as minutes and seconds?
Do it in the PLC, not with panel formatting. Divide the remaining milliseconds by 60000 for the minutes tag, then take the remainder of that division and divide it by 1000 for the seconds tag. At 83,500 ms remaining, that gives 83,500 / 60000 = 1 min with a remainder of 23,500, and 23,500 / 1000 = 23.5 s. Display the two tags side by side.
The display jumps in whole seconds. Is the timer wrong?
Usually the display scaling is rounding a millisecond value to whole seconds, not a timer fault. Keep the PLC tag in milliseconds and set the numeric display to one or two decimal places so the value visibly changes between updates; the tag itself changes every scan. If the number climbs instead of falling, the display object is bound to the accumulated value rather than to the remaining-time tag.