Leap Year compensation is based upon the era of the specific chip design, and applicability is normally annotated on the cover page of that data sheet. For most chip designs that do not include a Century register, the Leap Year compensation functions properly through 2099 and is assumed to be the result of this expression:
Due to the era of existing chip designs, many of today‘s RTC components containing a Century register apply the same algorithm solely upon on content of the Year register, and therefore will incorrectly designate 2100 as a leap year.
The
DS1347 RTC utilizes the full Gregorian algorithm to determine Leap Year adjustments for February:
Leap_Year = 0 ; default to No
If MODULO (CALENDAR_YEAR/4) == 0 ; divisible by 4?
If MODULO (CALENDAR_YEAR/100) == 0 ; divisible by 100?
If MODULO (CALENDAR_YEAR/400) == 0 ; divisible by 400?
Leap_Year = 1
end ; if
else
Leap_Year = 1
end ; if
end ; if
The Century register (if applicable) counts from 00h to 99h. All 8 bits in this register are read/write capable.
Results When Illegal Data Is Written
Up to this point, we have discussed the proper counting methods used by the RTC, given the legal range of values for the register in question. Occasionally a question may arise concerning expected counter behavior when improper values were initially installed. The answer is deterministic, and only requires a copy of the component‘s register map to arrive at a conclusion.
To access the result of loading an improper value, perform a Logic AND of the written value with the write-enabled bits in the register in question.
If the resulting content is less than the register‘s maximum counter value, the register should subsequently increment from that AND-ed value. Rollover will occur when the bit states in the register eventually coincide with the expected maximum value for that counter (12h or 00010010b as shown in Example 1).
Example 1: Write 2Ah into the Month register of a
DS1337 serial RTC
From the product specification, the Month register content was verified to match the register description above.
BCD |
Binary |
2Ah |
00101010 |
Write to Month |
9Fh |
10011111 |
Enabled bits in Month register (with Century bit) |
0Ah |
00001010 |
Resulting content of "0Ah" after writing the Month |
12h |
00010010 |
Logic match for "maximum value" |
If the resulting content is greater than the register‘s maximum counter value, the register should subsequently increment from that AND-ed value to some unpredictable rollover condition. In this case, not only was the hour value illogical, but setting bit6 also changed the functionality of the Hours counter to 12-hour Mode. Prediction of the roll-over point is illogical and results may vary, based upon that specific chip design.
Example 2: Write FFh into the Hours register of a
DS1390 low-voltage RTC
From the product specification, the Hours register content was verified to match the register description above.
BCD |
Binary |
FFh |
11111111 |
Write to Hours |
7Fh |
01111111 |
Enabled bits in Hours register |
7Fh |
01111111 |
Resulting content of "7Fh" when reading the Hours |
Example 3: Write 38h into the Hours register of a DS1341 low-current RTC
From the product specification, the Hours register content was verified to match the register description above.
Since bit6 (12/%-overbar_pre%24%-overbar_post%) was not set, the component would be running in 24-hour mode, and 38h is obviously past the normal 24-hour mode register maximum of 23h. The resulting time error is difficult to estimate, given an unstated period of operation between when the value was corrupted and when it was detected.
BCD |
Binary |
38h |
00111000 |
Write to Hours |
7Fh |
01111111 |
Enabled bits in Hours register |
38h |
00111000 |
Resulting content of "38h" when reading the Hours |
Example 4: Write AAh into the Seconds register of a DS1302 trickle-charge timekeeping chip
From the product specification, the Seconds register content deviates from the register description above; the inclusion of the CH bit (bit7) requires some further understanding of that bit‘s functionality.
Since only 7 bits are used for the Seconds value, the counter was actually written to 2Ah. "CH" stands for Clock Halt.
With CH = 1, the oscillator is stopped and the counters do not increment, so it will never increment or roll over with CH set. The resulting time loss is difficult to estimate, given an unstated period of this idle (noncounting) condition before detection/correction.
BCD |
Binary |
AAh |
10101010 |
Write to Seconds |
FFh |
11111111 |
Enabled bits in Seconds register |
AAh |
10101010 |
Resulting content of "AAh" when reading the Seconds |
Example 5: Write 2Dh into the Date register of a
DS1338 serial RTC
From the product specification, the Date register content was verified to match the register description above.
BCD |
Binary |
2Dh |
00101101 |
Write to Date |
3Fh |
00111111 |
Enabled bits in Hours register |
2Dh |
00101101 |
Resulting content of "2Dh" when reading the Hours |
Summary
In conclusion, we have discussed the counter chain structure utilized in Maxim‘s BCD-formatted RTCs, the derivation of unique calendar events, and Leap Year/Century handling. Additionally, using published register information and the deterministic nature of the state machine logic, some behavioral traits resulting from errant programming can be recognized during the system debugging phase. This symptom recognition can reduce a product‘s time to market.