You are currently viewing the content available in Vietnam. If you are looking for information for another region, please select the correct country from the top-left dropdown in the page and 'Navigate to Browse FAQs' in the Support menu.
Issue
In the M580 CPU, why does the system word %SW51 (RTC Hour) show a different value than Local Time or UTC?
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
Environment
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 using the DT_TO_ARINT function block which will contain the following values in BCD format:
PLC_TIME_ARRAY[0] = 16#SS00
High Byte = Seconds
Low Byte = (not used) returns 0
PLC_TIME_ARRAY[1] = 16#HHmm
High Byte = Hour (24h format)
Low Byte = Minutes
PLC_TIME_ARRAY[2] = 16#MMDD
High Byte = Month of the year
Low Byte = Day of the month
PLC_TIME_ARRAY[3] = 16#YYYY
Whole INT = 4 digit Year
These 4 INTs are structured in the same way as %SW50 to %SW53 in the M340 where the High and Low Bytes contain separate information on the date and time data.
[Simple Example]
To extract just the Local time Hour value 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).
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 extract all 6 values of the Date and Time, see below for full implementation in both Ladder Logic (LD) and Function Block Diagram (FBD) languages:
[Ladder Logic Code]
Required Variables:
Note that in the first rung, we need to write the output of the RRTC_DT function block into an intermediary Variable (PLC_DateTime) of type DT before writing it to the IN Pin of DT_TO_ARINT. This is a requirement in the Ladder Logic programming of Control Expert for this data type.
When run in the Simulator, the Runtime Clock is the Windows Clock:
[FBD Language Example]
Implemented in FBD, there is no longer a requirement for these highlighted Variables:
The intermediary BYTE variables containing the BCD values are not required because we can just use lines across more Function blocks in FBD language.
And same with the PLC_DateTime (DT type) variable is not required in FBD.
Meaning a smaller subset of Variables is required:
Using the identical logic as in the LD language example translated to FBD, the code would appear as follows:
When run in the Simulator:
These sections can be downloaded from this FAQ's attached "RRTC_DT_Example_SRs.zip" file.
In the zipped file, there are two files:
RRTCDateTimeExtract_FBD.XBD - Function Block Implementation Example
RRTCDateTimeExtract_LD.XLD - Ladder Logic Implementation Example
They can be imported individually into your EcoStruxure Control Expert application by right clicking under Project Browser > Programs > Tasks > MAST > Logic:
To see more information about the System Words, please see:
EcoStruxure™ Control Expert - System Bits and Words, Reference Manual
https://www.se.com/ca/en/download/document/EIO0000002135/
To see more information about the RRTC_DT function block, please see:
EcoStruxure™ Control Expert - System Block Library
https://www.se.com/ca/en/download/document/33002539K01000/
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
https://www.se.com/ca/en/download/document/33002519K01000/
In the M580 CPU, why does the system word %SW51 (RTC Hour) show a different value than Local Time or UTC?
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
Environment
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 using the DT_TO_ARINT function block which will contain the following values in BCD format:
PLC_TIME_ARRAY[0] = 16#SS00
High Byte = Seconds
Low Byte = (not used) returns 0
PLC_TIME_ARRAY[1] = 16#HHmm
High Byte = Hour (24h format)
Low Byte = Minutes
PLC_TIME_ARRAY[2] = 16#MMDD
High Byte = Month of the year
Low Byte = Day of the month
PLC_TIME_ARRAY[3] = 16#YYYY
Whole INT = 4 digit Year
These 4 INTs are structured in the same way as %SW50 to %SW53 in the M340 where the High and Low Bytes contain separate information on the date and time data.
[Simple Example]
To extract just the Local time Hour value 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).
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 extract all 6 values of the Date and Time, see below for full implementation in both Ladder Logic (LD) and Function Block Diagram (FBD) languages:
[Ladder Logic Code]
Required Variables:
Note that in the first rung, we need to write the output of the RRTC_DT function block into an intermediary Variable (PLC_DateTime) of type DT before writing it to the IN Pin of DT_TO_ARINT. This is a requirement in the Ladder Logic programming of Control Expert for this data type.
When run in the Simulator, the Runtime Clock is the Windows Clock:
[FBD Language Example]
Implemented in FBD, there is no longer a requirement for these highlighted Variables:
The intermediary BYTE variables containing the BCD values are not required because we can just use lines across more Function blocks in FBD language.
And same with the PLC_DateTime (DT type) variable is not required in FBD.
Meaning a smaller subset of Variables is required:
Using the identical logic as in the LD language example translated to FBD, the code would appear as follows:
When run in the Simulator:
These sections can be downloaded from this FAQ's attached "RRTC_DT_Example_SRs.zip" file.
In the zipped file, there are two files:
RRTCDateTimeExtract_FBD.XBD - Function Block Implementation Example
RRTCDateTimeExtract_LD.XLD - Ladder Logic Implementation Example
They can be imported individually into your EcoStruxure Control Expert application by right clicking under Project Browser > Programs > Tasks > MAST > Logic:
To see more information about the System Words, please see:
EcoStruxure™ Control Expert - System Bits and Words, Reference Manual
https://www.se.com/ca/en/download/document/EIO0000002135/
To see more information about the RRTC_DT function block, please see:
EcoStruxure™ Control Expert - System Block Library
https://www.se.com/ca/en/download/document/33002539K01000/
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
https://www.se.com/ca/en/download/document/33002519K01000/