
bengineer08 (Customer) asked a question.
Hello, I'm looking to display a calibration maintenance message every 6 months. After the calibration is completed the PLC will take the current time from the RTC year, month and day SD addresses and copy them over to year, month and day DS addresses. I'm having a mental block on how to increment those new year, month and day values by 6 months to set the next target calibration maintenance date.
It seems simple, just add 6 to the month address, but then I have to check if it's over 12, and if so subtract 12, and add 1 to year.
I guess I have a two pronged question.
First, are there any built in functions or routines that can keep track of things like "today's date +6 months"?
Second, (this is less to do with RTC, and more general PLC operation, I suppose), if I'm doing this in a subroutine that's called with a one-shot trigger, how is my month address going to react?
I have two rungs:
The first says: (new month) = (month) + 6
The second rung compares: if (new month) > 13 then (new month) -12 and (new year) +1
the question is, since the values write at the end of the scan, will the second rung compare to the original (new month) or will it evaluate the (new month) +6 ?
The writes to DS addresses happen immediately, not at the end of the scan
The Click PLC does not have a way to access the RTC as an integer, such as epoch seconds that many other PLCs do. If that were the case, you could simply add 262,800 (1/2 year's worth of seconds) to the epoch time. Or use one of the PLC's built in time offset instructions it probably has. But the Click has none of these features, so you are stuck doing kludge math to accomplish this, such as NewMonth = IF(Month > 6, Month - 6, Month + 6). NewYear = IF(Month > 6, Year + 1, Year), or what you did in separate rungs will work too. Bernie is correct, the values will be written instantly, the second rung will evaluate as you intend. Only physical outputs, Y's, are written at the end of the scan.
Create a "did maintenance warning" C bit. Compare the current month with each of the maintenance months.
If equal to either and the bit is not set then set it and issue the warning. If it was already set then do nothing.
If the current month is not equal to either of the two maintenance months then reset the bit.
There is really no reason to involve the day or year at all.
Thanks for the help!