IMDTouchKnowledge BaseShop main store

How-to

PLC timer value on an HMI: start, stop and show after a win

HMI and touchscreens Published 6 min read

Short answer

Time the run in the PLC, not on the panel. A TONR accumulator runs while Sensor 1's run-active bit is high, Sensor 2 copies the elapsed value into a result tag and sets the win bit, and the KTP600 shows that one tag on an I/O field while the PLC-driven screen change opens the winning screen.

On this page
  1. Divide the job between the CPU and the panel
  2. Build the timer logic in the CPU
  3. Show the value on the KTP600 Basic PN
  4. Open the winning screen from the CPU
  5. Worked example: displaying a 12,480 ms round in seconds on a KTP600 Basic
  6. Test the round before anyone plays
  7. Questions asked

Put the stopwatch in the CPU 1214C DC/DC/DC and use the KTP600 Basic color PN as a window onto it. A TONR time accumulator in the PLC adds to its elapsed value while its input is high, so Sensor 1 starts the measurement, Sensor 2 stops it, and the number stays correct no matter what the panel is doing. One timer serves both displays: the live screen reads the running value while a round is on, and the winning screen reads the same tag after the CPU copies and freezes it on a win. The winning screen itself opens because the CPU writes a screen number into an external tag the panel follows. Build it PLC first, panel second, then test the edge cases that decide whether a round counts.

Divide the job between the CPU and the panel #

Job Where it runs How
Start the round CPU Run-active bit set on Sensor 1's rising edge
Accumulate time CPU TONR input driven by the run-active bit
Stop and freeze CPU Sensor 2 during an active run copies the elapsed value into a result tag
Decide the win CPU Win bit set only when Sensor 2 fires during an active run
Show values HMI I/O fields bound to HMI tags
Open the winning screen HMI Screen change following an external tag

Measure in the CPU because the sensor signals land on its own inputs. A stopwatch built in the panel depends on the HMI runtime sampling the driver, and that sampling is why HMI operation records miss PLC start-stop transitions. The CPU also keeps timing while the operator wanders through screens or the link stutters, so the frozen result is right even if the panel was mid-redraw when Sensor 2 fired.

Build the timer logic in the CPU #

Both halves live in one STEP 7 project in TIA Portal; if you are sorting out which engineering tool your project needs, what STEP 7 is in a PLC project covers the tool choices first.

  1. Name Sensor 1 and Sensor 2 as PLC tags on two physical inputs of the CPU 1214C.
  2. Set the run-active bit on Sensor 1's rising edge, and only when no run is active, so a held Sensor 1 cannot restart the round.
  3. Call the TONR (Time accumulator) instruction in a cyclic block with its input driven by the run-active bit. The STEP 7 instruction description defines it as recording how long its input stays high, and it holds that elapsed value when the input drops.
  4. Every scan, copy the accumulator's elapsed output into a plain DInt data-block tag; that tag is the only thing the HMI ever reads, and timer internals stay out of the panel's reach.
  5. On Sensor 2 while run-active: copy the elapsed value into the result tag, clear run-active, set the win bit. That copy is what freezes the result the panel shows.
  6. Score only when Sensor 2 arrives during an active run. A Sensor 2 before any Sensor 1 sets nothing.
  7. For the next round, pulse the accumulator's reset input and clear the result tag, the win bit and the run-active bit.

For total machine hours rather than a single round, Siemens publishes an elapsedTimeMeter function block (support entry 45603743) that accumulates elapsed operation time from a start trigger.

One bench rule: disconnect the air and drive the sensor inputs from a test pattern or jumper while you prove the logic — never wave a hand into a live cylinder to make it count.

Show the value on the KTP600 Basic PN #

Create one HMI tag over the elapsed DInt tag and one over the result tag. On the play screen, bind an I/O field to the elapsed tag and give it a visibility condition driven by the run-active bit, so the live timer exists only while a round runs — the same trick that shows an HMI button only when a PLC bit is high. Put the result I/O field on the winning screen itself; the CPU opens that screen only on a win, so the frozen value appears with no extra animation logic. How fresh those fields look follows each tag's acquisition cycle setting in the HMI tag table, and that setting is the one to shorten if the play screen feels slow.

Open the winning screen from the CPU #

Configure the panel's screen-change control to follow an external tag: the number the CPU writes into that tag selects the screen carrying that number, which is the standard change-screen-by-number pattern. When Sensor 2 scores, the CPU writes the winning screen's number; when the reset clears the win bit, it writes the play screen's number back. Reserve those two numbers for the CPU and give the operator's own screen buttons different numbers, or the CPU and the operator will fight over the display. Keep the tag a plain numeric external tag in both projects and confirm both ends agree on its address and data type before blaming the logic.

Worked example: displaying a 12,480 ms round in seconds on a KTP600 Basic #

Inputs and where they come from:

  • Elapsed value 12,480 ms — the accumulator's value after a Sensor 1 to Sensor 2 round (example round; TIME values in STEP 7 count in 1 ms steps, so the accumulator holds 12480 as a DInt of milliseconds).
  • Conversion basis 1,000 ms/s — the definition of the second applied to the millisecond count.
  • Hardware CPU 1214C DC/DC/DC computing and KTP600 Basic color PN displaying — the setup this article works with.

Rule in words: the I/O field prints whatever number its tag holds, so convert once in the CPU — seconds = elapsed milliseconds divided by 1,000 ms/s.

Arithmetic:

  • Real path: convert the DInt to a Real, then 12,480 ms / 1,000 ms/s = 12.48 s.
  • Integer trap: 12,480 divided by 1,000 in integer math truncates to 12, and the panel reads 12 s while dropping 480 ms.

Result: the winning screen's I/O field shows 12.48 with a two-decimal format, and the live field on the play screen climbs through the same conversion.

Decision: for rounds of several seconds where hundredths decide ties, display seconds to two decimals — convert once in the CPU and every screen reads the same number. Display the raw DInt only when rounds run under a second and the raw milliseconds are the natural scoreboard.

Test the round before anyone plays #

  • Both sensors dark at start: accumulator zero, play screen shown.
  • Sensor 1 alone: the live field starts climbing; hold Sensor 1 and nothing restarts.
  • Sensor 2 then Sensor 1: no score, no screen change.
  • Sensor 1 then Sensor 2: the value freezes, the win bit sets, the winning screen opens with the frozen result.
  • Sensor 2 held down: one result only; the next run needs a fresh Sensor 1 edge.
  • Reset: accumulator cleared, result zero, panel back on the play screen.
  • Drop the panel's link mid-round and restore it: the CPU kept timing and the frozen result still matches a stopwatch. If a field reads stale after reconnect, work through Is It the Driver, the Tag or the Screen? before touching the logic.

One accumulator, one result copy, one screen-change tag: the CPU owns the time and the win, and the KTP600 shows what the CPU tells it to show.

Questions asked

How often does the KTP600 Basic refresh the timer value?

The panel refreshes a tag at the cycle set in that tag's acquisition cycle setting in the HMI tag table. The default reads the PLC about once a second, which is slow for a scoreboard. Set the tag's cycle to 100 ms and the play screen tracks tenths of a second. The number in the CPU is exact either way; the cycle only controls how fresh the display looks.

Does the elapsed value survive a CPU power cycle?

Only if the memory holding it is retentive. The accumulator's working data and your result tag live in data blocks; mark the specific variables as retentive in the block and they keep their values through a power cycle, while anything unmarked comes back zero. A game that resets every round does not need it. Pulse the reset in your start sequence instead.

What if the player never reaches Sensor 2?

The accumulator climbs for as long as the run-active bit is high; the TIME type runs to roughly 24 days before it wraps. Add a maximum round time in the CPU: when the elapsed value passes your limit, say 60,000 ms, clear run-active and set a timeout bit instead of the win bit, so the panel shows a fail result and the next reset clears it like a loss.

What tag type carries the screen number to the panel?

A plain DInt HMI tag mapped to a DInt in the CPU is enough for a handful of screens. Keep one number for one screen and never reuse a number, because the panel simply shows whichever screen carries that number. If a screen change is ignored, first check that both projects agree on the tag's address and data type before touching the game logic.

Keep reading

  • How-to

    How to Display a Time-Until-Closed Countdown on an HMI

    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.

    HMI and touchscreens

  • Troubleshooting

    Why WinCC Start and Stop buttons do not control an S7-300 output

    The Start and Stop buttons do nothing because E0.0 and E0.1 are S7-300 input image addresses: the CPU refreshes them from the input modules every scan, so an HMI write cannot survive. Step 7 simulation changes the simulated input state itself, which is why the LED follows it. Move the two commands to memory bits such as M0.0 and M0.1, latch them in the PLC, and let the program drive A4.0.

    HMI and touchscreens

  • Explainer

    Can an HMI Script Count PLC Bit Changes Reliably

    Yes, but only as an approximate, non-critical count. A runtime script sees the tag at discrete reads, so a bit that turns on and off between reads is missed; reported field experience treats signals held 2 s per state as reliable and anything below 500 ms as unusable. Any count that matters belongs in the PLC, displayed on the HMI.

    HMI and touchscreens

KTP700 Basic Runtime Startup Wait and the Start Center