Sign in to follow this  
Followers 0
Michael Walsh

Timer Countdown in Minutes and Seconds

4 posts in this topic

From a DM:

Hello Michael ,

I'm new here , i have doubt with the display of a timer , my boss request a count down display in the HMI but how we can display the real value?

I mean i need to put  Countdown display of 5min but the TIM is in miliseconds 6000 = 5min and in the display only put 6000.

i hope you can help me.

 Regards.

Ivan 

@Ivan Fajardo

Share this post


Link to post
Share on other sites

The TIM instruction is not in milliseconds, it is in 0.1s increments.  So, 6000 (BCD) = 600.0 s = 10 minutes.

I cannot save the picture on here, so I will have to type it.  You can use any addresses that you want, but I chose these.  My timer is T0.

P_On contact to do all of this:

BIN T0 D0               Convert the present value of the timer to an integer

/ D0 &600 D2          Divide the integer by 600.  This gives you minutes remaining as a whole number.

FLT D02 D4             Convert the integer to real. D4 has the value of minutes remaining as a real number.  Display it on the screen with no decimal places.

FLT D0 D10             Convert the current value of the timer (0.1s value) into a real number.

/F D10 +600.0 D12   Divide the value by 600 to convert to number of minutes as a real number, so 900 (integer) would convert to 1.5 minutes.

-F D12 D4 D14        Subtract the whole number of minutes remaining from the real number of time remaining.  Given the 900 example, this would be 1.5 minus 1 = 0.5.  D14 has the fractional minute value remaining.

*F D14 +60.0 D16    This converts the fractional minute value in D14 to seconds.  So, 0.5 * 60.0 = 30 s. 

In this example, T0 would have a BCD 900 in it, D4 would be 1.0 (whole minutes) and D16 would be 30.0 (30 seconds).  Be sure to display the D4 value on the screen with 0 decimal places.  You could display D16 with one decimal place or 0, that is up to what you want to see on the screen.  

There are other ways to do this, but this is one suggestion.

1 person likes this

Share this post


Link to post
Share on other sites

in case you get trouble with seconds value (due to rounding in real numbers), or if you would like to avoid floating points all together, you can obtain the seconds value slightly differently.

divide D0 by 600 to get minutes (in D2)

multiply D2 by 600 again and store in elsewhere (D20 for example), this is intermediate result showing minutes expressed in 0.1 seconds

then you can subtract D20 from D0 to get the seconds value (still expressed in 0.1sec which is easy to format on HMI). 

just an idea...

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0