Topic: DMD0221 Date and Time Overview |
|
All of the Do-more CPUs are equipped with a Real Time Clock that is accurate to within +/- 1.53 minutes per month.
The current date and time in the Do-more PLC is internally stored as a UTC (Coordinated Universal Time) UTC (Coordinated Universal Time) is the primary time standard by which the world regulates clocks and time. Time zones around the world are expressed as positive or negative offsets from UTC, as in the list of time zones by UTC offset. UTC is used in many Internet and World Wide Web standards. The Network Time Protocol, designed to synchronise the clocks of computers over the Internet, encodes times using the UTC system. value. The UTC value is a 32-bit integer value that represents the number of seconds that have elapsed since a particular point in time. Do-more PLCs use the 1970 Epoch - which began at 00:00:00, 1 January 1970 - as that reference point in time. The current UTC value is stored in the PLC in the system-defined location $UTC (DST21).
The current time of a Do-more PLC can be automatically adjusted for the Time Zone by entering the number of minutes of adjustment for the current time zone in the system-defined location $TimeZone (DST384).
The current time of a Do-more PLC can be further adjusted for Daylight Saving Time by setting the system-defined location $SummerTime (ST768). If this bit location is ON then 1 hour of time is added to the current time calculation; if OFF then no additional time is added.
The current date and time is automatically rendered from the UTC time value by applying adjustments for the Time Zone, and for Daylight Saving Time stored in the system-defined location $LocalTime (DST22).
Viewing a UTC value is not useful for humans. The Data View has a display format called '1970 Epoch' which will display a UTC value in human-readable form (DD-MMM-YYYY Day Hour:Minute:Second). In the Data View below, the first entry is $UTC in native format, the second is $UTC displayed in the 1970 Epoch format. At the end are similar entries for $LocalTime.
In review, there are four system-defined locations in the CPU that contain
UTC-centric time values, they are:
The rendering of the local date and time in the CPU follows this pattern:
|
|
Date/Time StructuresAs stated earlier, storing native UTC values is very economical (they only consume a single DWord location), but using the Date and Time values in a ladder logic program, or referencing the Date and Time from an HMI while the values are in UTC form is not very convenient. To alleviate this, the Do-more CPU uses Date/Time structures to make the Date and Time values more user friendly.
The individual pieces of the Date and the Time are stored in separate members of a Date/Time structure. The individual structure members can then be used as parameters in instructions or read / written from an HMI just like any other memory location in the CPU's memory. All Date/Time structures have the following member fields:
.Year is a 4-digit number representing the year.
.Month is a 2-digit 1 to 12 representing the month. .Day
is a 2-digit value from 1 to 31 representing the day of the month. .DayOfWeek is a 2-digit value from 0 to 6 representing the day of the week
. .Hour is a 2-digit value from 0 to 23 representing the hours. .Minute
is a 2-digit value from 0 to 59 representing the hours. .Second is a 2-digit value from 0 to 59 representing the hours.
.Date is a 32-bit hexadecimal value that contains the .Year, .Month, and .Day field values packed into a DWord as follows: YYYYMMDD (use the Date Field display format in Data View to view the value in a human readable form)
.Time - a 32-bit hexadecimal value that contains the .DayOfWeek, .Hour, .Minute, and .Second field values packed into a DWord as follows: DDHHMMSS (use the Time Field display format in Data View to view the value in a human readable form)
The default configuration of a Do-more CPU has two predefined memory blocks of Date/Time structures: SDT0 - SDT7 (System Date/Time) which contain date/time values generated the PLC, and UDT0 - UDT31 (User Date/Time) which the programmer can use in the ladder logic project. The first three system-defined Date/Time structures have the following values:
$Now (SDT0)
contains the system-generated current date and time value, including
adjustments for Time Zone and Daylight Saving Time. $SysShutdown
(SDT1) contains the date and time when the CPU was last
powered OFF. $SysStartup (SDT2) - contains the date and time when the CPU was last powered ON.
|
|
Using the Date and Time ProgrammaticallyThere will be instances when you want to use the PLCs current date and / or time in the project's ladder logic, for example, when storing a time-stamp that an event occurred, or triggering an event at a certain time. And while UTC values are not very human-friendly, they are very efficient when used by computers for doing these types of operations. The Do-more instruction set contains the following instructions that use the date and/or time information. Refer to the specific Help on each instruction for detailed information on using them in your ladder logic: Use Date/Time StructuresDTCMP
- Compare Date/Time compares some or all of the fields of two Date/Time
structures. The calculation is always performed as First Date/Time - Second
Date/Time. DTDIFF
- Difference between two Date/Times calculates the number of seconds
of time between the contents of two Date/Time structures. The calculation
is always performed as Date/Time A - Date/Time B. DTOFFSET - Add Offset to Date/Time adds a specified amount of time to the contents of a Date/Time structure.
Convert UTC Values to Date/Time Structures and Vice VersaDT2EPOCH
- Convert Date/Time to 1970 Epoch calculates the number of seconds
between the contents of the designated Date/Time structure in the CPU
and midnight on January 1, 1970. EPOCH2DT - Convert 1970 Epoch Time to Date/Time converts a value that represents the number of seconds since midnight on January 1, 1970 to a Date/Time structure.
|
|
See Also:Date and Time Overview
Synchronizing the Clocks on Multiple Do-more PLCs
|
|