{}

Our Brands

Impact-Company-Logo-English Black-01-177x54

Welcome to the Schneider Electric Website

Welcome to our website.
Search FAQs
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.
In the M580 CPU, why does the system word %SW51 (RTC Hour) show a different value?
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).

Simple Ladder Example to get only the Local Hour

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: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.
LD Code Part 1
LD Code Part 2

When run in the Simulator, the Runtime Clock is the Windows Clock:
LD Simulation 1
LD Simulation 2


[FBD Language Example]
Implemented in FBD, there is no longer a requirement for these highlighted Variables:Highlighted Variables not required for FBD
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:FBD Required Variables

Using the identical logic as in the LD language example translated to FBD, the code would appear as follows:
FBD Code

When run in the Simulator:
FBD Simulation

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:
Import 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/


Schneider Electric Vietnam

Attachment(s)
RRTC_DT_Example_SRs.zip [4.22 KB]
Explore more
Range:
Articles that might be helpful Users group

Discuss this topic with experts

Visit our Community for first-hand insights from experts and peers on this topic and more.
Explore more
Range: