I am having troubles with the calibration function of the RTC_A module of an MSP430f530x.
I measure the XT1 (32768 Hz, +/- 20 ppm) inaccuracy compared to a reference clock (1 Hz, +/- 1 ppm). Let's call that value "error_measured".
With no compensation in the RTCCTL2 register (that is RTCCALS and RTCCAL to 0), I set the clock time to match a reference (for example a national clock service on phone or internet, or a GPS clock). Two weeks later, the clock under test has drifted. I check the deviation with the reference clock, and call that "error_crystal".
"error_crystal" and "error_measured" are equal (+/- 1 or 2), which validates the measurement method for "error_measured".
From the value "error_measured", I calculate the register values to put in RTCCALS and RTCCAL. I think I understood the specification about the calibration, here are two examples of the register values:
"error_measured" == +14 ppm (fast crystal) -> RTCCALS = 0, RTCCAL = 7
"error_measured" == -12 ppm (slow_crystal) -> RTCCALS = 1, RTCCAL = 3
With the settings in the RTC registers, another two weeks run is started. Two weeks later, instead of having a compensated error ("error_compensated") within +/- 5 ppm, I find that the time has been compensated approximately twice as much as expected, in the expected direction.
In the first of the example cases above:
- "error_measured" == +14 ppm
- "error_crystal" == +14 ppm
- RTCCALS = 0, RTCCAL = 7
- "error_compensated" == -13 ppm
and another example:
- "error_measured" == -19 ppm
- "error_crystal" == -17 ppm
- RTCCALS = 1, RTCCAL = 4
- "error_compensated" == +20 ppm
Here are my questions:
1. is my calculation of the RTC registers correct, from the given "error_measured"?
2. has anyone actually used the RTC calibration and seen it working as described above? Or seen it working as I expect?
3. is there any errata that I missed, about his problem?
4. is there any example code available for RTC calibration?
Notes:
- the two weeks run give approximate ppm errors. The longer the test run, the more reliable the result.
- up calibration may give more than double the expected calibration. I have fewer samples with slow crystals, so there is not much data there.
- the units under test are indoors at all times, faily constant temperature.
- the MSP430 goes to sleep regularly (LPM4), but ACLKREQEN is set to 1. I expect the RTC module to keep ACLK alive by requesting it all the time.