481
Technical support / Re:Time based events
« on: July 20, 2009, 08:35:46 PM »
The early suggestion on how to avoid mis-reading the TIME[] was not tested. This code has been tested:
'Read RTC - code to access time of day registers and return CORRECT values
' in the following variables:
' DM[301] TIME[1], RTC Hours
' DM[302] TIME[2], RTC Minutes
' DM[303] TIME[3], RTC Seconds
while 1
' read all TIME[] registers, one time
'
DM[301] = TIME[1]
DM[302] = TIME[2]
DM[303] = TIME[3]
' re-read the TIME[] register and verify that they did not change
' from the previous set. The whole point of this exercise is to
' detect and discard erronous readings that can occur becuase the PLC
' firmware is constanly updating these register. It is possible to
' observe the following transisitons:
'
' 23:59:59 -> 23:59:00 -> 23:00:00 -> 00:00:00
'
if ((DM[301]=TIME[1]) AND (DM[302]=TIME[2]) AND (DM[303]=TIME[3]))
return ' time is correct, no invalid transisitons
endif
' If we are here then there was a roll over between the reads of the
' TIME[] registers...so try it again
'
endwhile
'Read RTC - code to access time of day registers and return CORRECT values
' in the following variables:
' DM[301] TIME[1], RTC Hours
' DM[302] TIME[2], RTC Minutes
' DM[303] TIME[3], RTC Seconds
while 1
' read all TIME[] registers, one time
'
DM[301] = TIME[1]
DM[302] = TIME[2]
DM[303] = TIME[3]
' re-read the TIME[] register and verify that they did not change
' from the previous set. The whole point of this exercise is to
' detect and discard erronous readings that can occur becuase the PLC
' firmware is constanly updating these register. It is possible to
' observe the following transisitons:
'
' 23:59:59 -> 23:59:00 -> 23:00:00 -> 00:00:00
'
if ((DM[301]=TIME[1]) AND (DM[302]=TIME[2]) AND (DM[303]=TIME[3]))
return ' time is correct, no invalid transisitons
endif
' If we are here then there was a roll over between the reads of the
' TIME[] registers...so try it again
'
endwhile