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?
Product Line
Modicon M580
Enviroment
EcoStruxure Control Expert
Unity Pro
Cause
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.
Resolution
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[1] = 16#SS00 (Seconds)
DateAndTime_ARRAY[2] = 16#HHMM (Hour and Minute)
DateAndTime_ARRAY[3] = 16#MMDD (Month and Day)
DateAndTime_ARRAY[4] = 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).
How do I extract the value of the current local time hour from an M580 PLC's Runtime Clock (RTC) in a program?
Product Line
Modicon M580
Enviroment
EcoStruxure Control Expert
Unity Pro
Cause
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.
Resolution
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[1] = 16#SS00 (Seconds)
DateAndTime_ARRAY[2] = 16#HHMM (Hour and Minute)
DateAndTime_ARRAY[3] = 16#MMDD (Month and Day)
DateAndTime_ARRAY[4] = 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).