Timer display on HMI

I’m trying to display a 30 second stop watch/timer on the HMI. The trigger/or reset to zero would be the complete inspection button. This way production will know how fast they need to process each tube.

-Carlos

You can use a memory tag of type “Date” to store the target time (from what time the counter should start, or to what time it should count down). You can set this via a script on a button click, or a different trigger.

Then you can create any text field and set a binding on it like below

dateFormat(addSeconds(getDate(1900,1,1), secondsBetween(now(), {myTagPath/targetTime})), "HH:mm:ss")

What the expression does is first calculating the number of seconds between the current time now() and the target time. You can reverse the order depending on whether you want to count up or down.

Then the numer of seconds is added to a certain date (to create a new Date datatype), which in turn is formatted as "HH:m:ss".

Every second, the now() is refreshed, so you see the counter updating every second.

If you just want to display the number of seconds, you can get rid of the date formatting, and the expression will be a lot simpler:

secondsBetween(now(), {myTagPath/targetTime})
4 Likes