In the M580 CPU, why does the system word %SW51 (RTC Hour) show a different value?
How do I extract the value of the current local time hour from an M580 PLC's Runtime Clock (RTC) in a program?
EcoStruxure Control Expert
There is a new behaviour of %SW51 in M580 platform compared to the previous M340 generation of PLC. The local time Hour is not represented in %SW51 in the M580.
The local time can be read using the RRTC_DT function.
The RRTC_DT function returns the date and time in DateTime Type format.
This value can then be converted to an Array of 4 INTs (in BCD Format) containing:
DateAndTime_ARRAY = 16#SS00 (Seconds)
DateAndTime_ARRAY = 16#HHMM (Hour and Minute)
DateAndTime_ARRAY = 16#MMDD (Month and Day)
DateAndTime_ARRAY = 16#YYYY (Year)
These 4 INTs are structured in the same way as %SW50 to %SW53 in the M340.
Furthermore, to extract the Local time hour using the RRTC_DT function, see the screenshot below as an example:
The value from the DT_TO_ARINT array of INT variables is originally in BCD format and must be converted from BCD to INT. Then the left-most two digits represents the local time hour, which can be extracted by dividing the BCD value by 100 (with no remainder using the DIV function).
To see more information about the System Words, please see:
EcoStruxure™ Control Expert - System Bits and Words, Reference Manual
To see more information about the RRTC_DT function block, please see:
EcoStruxure™ Control Expert - System Block Library
To see more information about the DT_TO_ARINT and BCD_TO_INT function blocks, please see this guide:
EcoStruxure™ Control Expert - Standard Block Library