Jump to content

Jazz indirect clock function

Recommended Posts

In U90Ladder I've tried to use the indirect clock function time. It allows you to specify a start and an end time and between these two times the output will be active. The problem I have is with the format in which it appears I have to specify these times. The time AB:CD is equal to the value A*4096 + B*256 + C*16 + D. In other words: the value is equal to that value which in hexadecimal representation reads like the time it is representing.

Suppose I read the RTC using SI31. Suppose it is 12:34 and I want to know the time in hours and minutes. I will use SI31 and read the integer 1234. I divide by 100 to get the hours and in the remainder (SI4) I can find the minutes.

Now I want to do the reverse. I start with 12 and 34. I have to divide 12 by 10, multiply the result by 6 and it this to 12. I then multiply this by 256. I then divide the minutes by 10, multiply by 6 and add the results to the minutes. I finally add the transformed minutes and hours to get the value I need for the indirect clock function:

12/10 = 1

1*6 = 6

12 + 6 = 18

18*256 = 4608

34/10 = 3

3*6 = 18

34+18 = 52

4608 + 52 = 4660 (which is 1234h)

Can this be done simpler? (and as a bonus question: why on earth does this function not use the same format as SI31?)

Link to comment
Share on other sites

You can use next algorithm:

Use SI 4 and DIV function.

Divide 0x1234 for 0x10 (16 decimal). You have last digit 4 (decimal or hex is the same) in SI 4, and result 0x123 in other MI.

4 is a last digit of decimal time. Add it to an empty result.

Divide 0x123 for 16. Multiply SI 4 for 10 and add to result MI.

Continue more times to finish.

You have decimal result for next use.

For conversion from decimal to hex use similar algorithm.

Is this what you need?


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...