Introduction
Your CPU has a real-time clock that:
provides the current date and time
displays the date and time of the last application shut-down
Clock Accuracy
The resolution of the real-time clock is 1 ms. The clock accuracy is affected by the operating temperature of the application:
Operating Temperature |
Maximum Daily Drift (Seconds/Day) |
Maximum Yearly Drift (Minutes/Year) |
---|---|---|
25 °C (77 °F) stabilized |
+/- 2.6 |
+/- 17.4 |
0...60 °C (32...140 °F) |
+/- 5.2 |
+/-33.1 |
Clock Back-Up
The accuracy of the real-time clock is maintained for 4 weeks when the CPU power is turned off if the temperature is below 45 °C (113 °F). If the temperature is higher, the back-up time is shorter. The real-time clock back-up does not need any maintenance.
If the back-up power is too low, system bit %S51 is set to 1. This value indicates a loss of time when the power supply was OFF.
Current Date and Time
The CPU updates the current date and time in the system words %SW49–%SW53 and %SW70. This data is in BCD.
RRTC_DT
function.Accessing the Date and Time
You can access the date and time:
on the CPU debug screen
in the program
from the DTM diagnostics screen
To read the current date and time, read system words %SW49 through %SW53. This operation sets system bit %S50 to 0.
To write the current date and time, write system words %SW50 through %SW53. This operation sets system bit %S50 to 1.
When system bit %S59 is set to 1, you can increment or decrement the current date and time values with system word %SW59.
The function performed by each bit in word %SW59 is:
Bit |
Function |
---|---|
0 |
increments the day of the week |
1 |
increments the seconds |
2 |
increments the minutes |
3 |
increments the hours |
4 |
increments the days |
5 |
increments the months |
6 |
increments the years |
7 |
increments the centuries |
8 |
decrements the day of the week |
9 |
decrements the seconds |
10 |
decrements the minutes |
11 |
decrements the hours |
12 |
decrements the days |
13 |
decrements the months |
14 |
decrements the years |
15 |
decrements the centuries |
Determining the Date and Time of the Last Application Shutdown
The local date and time of the last application shutdown are displayed in system words %SW54 through %SW58. They are displayed in BCD.
System Word |
Most Significant Byte |
Least Significant Byte |
---|---|---|
%SW54 |
seconds (0 to 59) |
00 |
%SW55 |
hours (0 to 23) |
minutes (0 to 59) |
%SW56 |
month (1 to 12) |
day in the month (1 to 31) |
%SW57 |
century (0 to 99) |
year (0 to 99) |
%SW58 |
day of the week (1 to 7) |
reason for the last application shutdown |
The reason for the last application shutdown can be displayed by reading the least significant byte of system word %SW58, which can have these values (in BCD):
Word%SW58 Value |
Definition |
---|---|
1 |
application switched to STOP mode |
2 |
application stopped by watchdog |
4 |
power loss |
5 |
stop on detected hardware error |
6 |
stop when errors such as these are detected:
Details on the software detected fault type are stored in %SW125. |