how can you use time/clock in pac machine edition/rx3i?

In the example I sent you, rung 14 shows you how to mask off the minute from the high byte of %R1704 leaving the hour in the low byte of %R1706.
Rung 16 shows how to mask off the hour from the low byte of %R1704 and then shift the result (minute) to the low byte of %R1707.

Use the AND function with the appropriate mask to isolate the hour and minute data. Then, if you need to shift from low byte to high byte, multiply by 256. If you need to shift fro high byte to low byte, divide by 256. Once you have the data you want in the high and low bytes of two separate words. with zero in the opposite byte of each word, use the OR function to combine them into a single word.

Thank you. I'm testing. am I doing something wrong? the in1 and in2 are good but the Q is not? any idea

9D1EBEE2-8069-4693-B01C-3E942334F35F.jpeg
 
Your screen shots are displaying decimal numbers. Do the ANDing and ORing on the BCD data returned by the SVC_REQ and don't convert from BCD to decimal.
In order to combine hour and minute into a single word for display on the HMI, the HMI must be able to interpret that word's data as BCD. If it can't you'll need to use separate words for hour and minute.
 
Last edited:
Your screen shots are displaying decimal numbers. Do the ANDing and ORing on the BCD data returned by the SVC_REQ and don't convert from BCD to decimal.
In order to combine hour and minute into a single word for display on the HMI, the HMI must be able to interpret that word's data as BCD. If it can't you'll need to use separate words for hour and minute.


thanks it works. Does this differ much from the rx3i? 2 digit and 4 digit?

7B28A324-7247-4F3D-A08B-D06AED68B7FA.jpeg 68F6D888-BF0C-4D6E-8A83-0A7B554312DA.jpeg
 
In the example I sent you, rung 14 shows you how to mask off the minute from the high byte of %R1704 leaving the hour in the low byte of %R1706.
Rung 16 shows how to mask off the hour from the low byte of %R1704 and then shift the result (minute) to the low byte of %R1707.

Use the AND function with the appropriate mask to isolate the hour and minute data. Then, if you need to shift from low byte to high byte, multiply by 256. If you need to shift fro high byte to low byte, divide by 256. Once you have the data you want in the high and low bytes of two separate words. with zero in the opposite byte of each word, use the OR function to combine them into a single word.

I managed the time but OR FUNCTION doesn't work. am I doing something wrong? hours and minutes are fine, but when merging things go wrong. see picture.

B2C8C315-C478-40A7-92CE-D103ACFD0EF9.jpeg
 
It looks like you didn't shift the data in PLC_minut left by 8 places (multiply by 256) before performing the OR.


Ah ok so I have to shift the minutes and hours first or just the minutes? and then bcd4 to int? or just the OR function?

because I had already done that div with 256. see picture

AB719B50-1E4B-4DA9-A105-42FBD7E7D6A4.jpeg
 
Last edited:
Keep the data in BCD format while multiplying or dividing by 256 and while ORing. Converting from BCD to INT is the last thing you do.
You multiply by 256 if you start with data in the lower 8 bits of a word and want to move it to the upper 8 bits. You divide by 256 if you start with data in the upper 8 bits and want to move it to the lower 8 bits.
For some reason, probably related to cloudflare, I can't see the attachments in your last two posts. When I posted #21, I could see the attachment in post #20, but no longer.
Edit: Cloudflare made me log in again and now I can see the attachments.
 
Keep the data in BCD format while multiplying or dividing by 256 and while ORing. Converting from BCD to INT is the last thing you do.
You multiply by 256 if you start with data in the lower 8 bits of a word and want to move it to the upper 8 bits. You divide by 256 if you start with data in the upper 8 bits and want to move it to the lower 8 bits.
For some reason, probably related to cloudflare, I can't see the attachments in your last two posts. When I posted #21, I could see the attachment in post #20, but no longer.
Edit: Cloudflare made me log in again and now I can see the attachments.

this way, right? I'm going to test it in 10 minutes.

E145B73E-E235-4126-B4CB-A8434B31DC38.jpeg
 
Keep the data in BCD format while multiplying or dividing by 256 and while ORing. Converting from BCD to INT is the last thing you do.
You multiply by 256 if you start with data in the lower 8 bits of a word and want to move it to the upper 8 bits. You divide by 256 if you start with data in the upper 8 bits and want to move it to the lower 8 bits.
For some reason, probably related to cloudflare, I can't see the attachments in your last two posts. When I posted #21, I could see the attachment in post #20, but no longer.
Edit: Cloudflare made me log in again and now I can see the attachments.


this doesn't work either? am I doing it wrong? it is an rx3i by the way.

Edit: picture 2

25CE401E-C066-414B-9128-68C2EC83D7F8.jpeg 2F2EAB80-B2E8-47EE-8150-8BAF7BC56AD8.jpeg
 
Last edited:
I'm going to assume you set up the SVC_REQ for 4-digit year, so the data in Time_reader(4) is minutes in the upper 8 bits, hours in the lower 8 bits. The decimal value of 16917 in BCD is 4215, meaning the data was collected at 3:42 PM.
I further assume you want to reverse the bytes to put the hours in the upper 8 bits and the minutes in the lower 8 bits.
The easiest way to do that is with a ROR_WORD or ROL_WORD instruction with a length of 8 bits. and convert the result from BCD to INT
A harder way is to Divide Time_reader(4) by 256, storing the result in a spare register. That puts the minutes in the lower 8 bits of the storage register. Then AND Time(reader(4) with FF which strips the minutes and leaves the hour in the lower 8 bits of the result. Now multiply the result of the AND by 256 to to move the lower 8 bits left by 8 places. Finally, OR the two storage registers together and convert the result from BCD to INT
 
Last edited:
I'm going to assume you set up the SVC_REQ for 4-digit year, so the data in Time_reader(4) is minutes in the upper 8 bits, hours in the lower 8 bits. The decimal value of 16917 in BCD is 4215, meaning the data was collected at 3:42 PM.
I further assume you want to reverse the bytes to put the hours in the upper 8 bits and the minutes in the lower 8 bits.
The easiest way to do that is with a ROR_WORD or ROL_WORD instruction with a length of 8 bits. and convert the result from BCD to INT
A harder way is to Divide Time_reader(4) by 256, storing the result in a spare register. That puts the minutes in the lower 8 bits of the storage register. Then AND Time(reader(4) with FF which strips the minutes and leaves the hour in the lower 8 bits of the result. Now multiply the result of the AND by 256 to to move the lower 8 bits left by 8 places. Finally, OR the two storage registers together and convert the result from BCD to INT

his is how I have it now. it's just not right. I also notice that the minutes after 10 minutes no longer run the same, they seem to increase with a difference of 6 minutes with the real time and that of the CPU. So I checked that too. Do you perhaps see something I'm doing wrong here? I just can't figure it out. If I convert everything for the OR function from bcd4 to int, everything still runs fine. But as soon as the OR function combines the minutes and hours, it will either show 0 or, for example, 10.
 
Delete the BCD to INT conversion in rung 5. With it in place, PLC_hour is converted to INT too soon. Both elements at the IN1 and IN2 nodes of the OR instruction in rung 7 need to be in BCD format.

I did that, but it appears to give a strange value. see the photo and see pdf.

Time is 18:04

48256AD9-C64E-4429-A724-B1ACADA6EE8F.jpeg A73F4596-B337-48D5-BF2B-4CFFF267EAB8.jpeg B5D391F3-772B-402A-9154-89FCCE548162.jpeg
 

Attachments

  • TEST_LIVE_TIME.pdf
    190.5 KB · Views: 2
Last edited:

Similar Topics

We recently purchased a IC693CPU352 module and it appears the internal time clock is static. I can set the time and date but once set it does not...
Replies
5
Views
174
Hello. I cannot change the SendClock settings for a PROFINET IO device. I need to slow down the CODESYS PROFINET IO controller. What am I doing...
Replies
0
Views
202
Hello, I am trying to create an AOI that will retrive the clock datetime bits from a master plc through a generic message read instruction and...
Replies
2
Views
499
I was online a SLC5/04 yesterday and one thing I did was go to processor properties and set the date and time to get the PLC clock current. It...
Replies
4
Views
722
At the moment on my application (S7-1212C), the PLC/HMI are showing the correct time, i.e. the displayed time matches the time of the clock on the...
Replies
10
Views
918
Back
Top Bottom