Sign in to follow this  
Followers 0
Jeremiah

Minutes to Hour Conversion Help?

21 posts in this topic

Hello there might be a very simple solution to my problem but I am having trouble coming up with it. Anyways I have a SLC505 processor and I am using RSview32. I would like to display a number(minutes) from the processor into an actual hour/minute format in the HMI. For example: I would like to have 400 minutes from the plc displayed as 6h:40min on the HMI. I would also need to the backward conversion from the HMI to the PLC as the operator could enter 6h:40min and have that converted to 400 minutes in the processor. Any help would be greatly appreciated. Thanks for your time. Jeremiah

Share this post


Link to post
Share on other sites
See PDF CONVERTMINUTES.pdf

Share this post


Link to post
Share on other sites
Man that was easy! Thanks a lot Mickey. I was really over thinking this one.

Share this post


Link to post
Share on other sites
Your welcome. Only one small problem with the above code. You could run into a spot where you round to 60 mins. I have done this with feet and inches and had to clamp the inches to 11" ( your case 59 mins. ) It doesn't look good on screen to have 6Hr 60mins. Easy enough to take care of if this becomes a problem. Edited by Mickey

Share this post


Link to post
Share on other sites
use this very simple

Share this post


Link to post
Share on other sites
rpraveenkum, he uses SCL505 which doesn't have MOD instruction...

Share this post


Link to post
Share on other sites
I don't have RSL500 CPT has mod function then try it Edited by rpraveenkum

Share this post


Link to post
Share on other sites
The CPT instruction doesn't support the MOD function:

Share this post


Link to post
Share on other sites
When using a DIV instruction, if there is a problem with rounding, then don't use the 'destination' at all. Just have some dummy location. Instead, do the DIV, then use the contents of the Math Register (S:13, S:14) one is the UNROUNDED quotient and the other is the REMAINDER (as in a MOD instruction). Edited by b_carlton

Share this post


Link to post
Share on other sites
I think this will do Edited by rpraveenkum

Share this post


Link to post
Share on other sites
I aint got one handy to test this on but does that mean if I did a DIV on say 17 by 3 ( ie the answer is 5.666) and put the result straigt into a register would i get 5 or 6 if the location is an integer. ? I understand the S13 & S14 way (that should at least give me 5 & 2).

Share this post


Link to post
Share on other sites
Yes - the AB DIV command rounds (not truncates) the answer if sent to an integer..

Share this post


Link to post
Share on other sites
Thanks for the heads up Bernie... So this means that if you wanted only the interger part then you pretty much should use the S:13 S14 registers then copy the S13: to your integer word. One to remember....

Share this post


Link to post
Share on other sites
While checking I noted that for the MicroLogix 1100 to get the Quotient/Remainder the destination must be explicitly set to the math register (S:13). Just check the documentation closely for your particular processor.

Share this post


Link to post
Share on other sites
Save yourself a ton of work. Send only the minutes tag to RSView and let it do the hour minute conversion for display purposes and save yourself the extra tag and the ladder programming, You're going to create the display fields anyways, so a properly crafted expression using RSView's MOD and DIVIDE (it truncates for you) instructions for the display field will be by far the simplest solution. On your display screen create two adjacent numeric displays each with a field length of two with a colon in between: ##:##. If you need more than 99 hours then make the left field (hours) longer. For my example, let ProcessMinutes be the name of the tag from the PLC that contains the minutes the process has run. In the expression for the left numeric display enter ProcessMinutes / 60 - this will display hours. In the expression for the right numeric display enter ProcessMinutes % 60 - this will display minutes. Configure the right hand numeric displays to display leading zeros. Five minutes will display as 0:05 and 75 minutes will display as 1:15. Edited by Alaric

Share this post


Link to post
Share on other sites
Alaric: This is exactly what I was looking for however I can not get it to work. The left numeric display works fine but the right does not display anything. I just tried it out with a memory tag, not a tag from the plc. I don't think that should matter. Have you tested this out and got it to work? Thanks a lot Jeremiah

Share this post


Link to post
Share on other sites
I tested it by putting a numeric entry field on the same screen that I took the screen captures from. It worked just fine. Make sure you have your tag names all correct and are using the correct operators for the MOD function. Also check to make sure there is no other animation on the numeric display such as visibility or position. Unfortunately I didn't save the graphic file, otherwise I could zip it and attach it to the post.

Share this post


Link to post
Share on other sites
I keep getting an expression error. I did the same thing with the numeric entry field. My tag is called "test" I tried test%60 and test % 60. In the status bar at the bottom of the screen I get Expression: "test%60" Error evaluating expression. Very strange. Not sure why its not working. Anyhelp? Jeremiah

Share this post


Link to post
Share on other sites
The MOD function will work with two constant numbers (22%4) but not with a tag. I found a couple of tech notes in AB's knowledge base. One mentions that the tag is converted to a floating point before the mod function and that the mod function only accepts integers. To get around this it says to use direct references instead of tags but rsview32 will not allow me to do this. The other tech note says that the hmi tag can not be part of a folder and to use a root tag. How do you create a root tag. I haven't created any folders are far as I know. Any help would be greatly appreciated. Jeremiah

Share this post


Link to post
Share on other sites
Jeremiah, How is your tag configured? Make sure that it is of type analog and that its data type is either a signed integer or an unsigned integer, do not leave it at the default setting, force it to be a an integer. If minutes is a float in your PLC I suggest you first MOV it to an integer word and then read the integer with RSView.

Share this post


Link to post
Share on other sites
Thanks a lot Alaric. I was just leaving the data type as default. I changed it to unsigned integer and we are golden. Thanks again for your help. Jeremiah

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