RTC Calibration program

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: https://technical.swissmicros.com/decoders/dm42/

You can then copy/paste the listing and post it in "code" tags.
Required
Posts: 33
Joined: Thu Jun 02, 2022 6:09 am

Re: RTC Calibration program

Post by Required »

Thank you guys for the clarifications.
I’m the Required one.

42S: 3117S03858 | DM42: 08455 | DM32: 00166 | 15C CE: 00085
Yonatan
Posts: 6
Joined: Tue Dec 27, 2022 9:23 pm

Re: RTC Calibration program

Post by Yonatan »

I just received my new DM41X, and I’m trying to understand Section 3.8 (RTC correction) in the online manual. I’m wrestling with the sign ambiguity in the definition of “drift” and in the definition of the correction term C. I agree with your post here:
ijabbott wrote:
Sat Jul 27, 2019 2:50 pm
I think the rtccalib.cfg value shown by the program possibly needs to be negated, or possibly the drift needs to be negated. I'm not sure which!

On 2019-03-31 (beginning of EU summer time), I set the calculator to the correct time.

On 2019-07-17 (108 days later), I noted my calculator had gained about 223 seconds, which is about +2.0648 seconds per day or +23.8983 ppm. The RTC calibration program produced a value of 25. I saved the rtccalib.cfg file with value 25 to the calculator and set the calculator to the correct time.

On 2019-07-27 (10 days since calibration), I noted my calculator had gained an additional 43 seconds, which is about +4.3 seconds per day or +49.7685. I.e. the rate of drift has slightly more than doubled since the initial calibration.

I know there has been some temperature variation between 2019-03-31 and 2019-07-27, but I can't imagine it having that much effect!

Today (2019-07-27) I shall set rtccalib.cfg to -25 and set the correct time on the calculator and monitor it in a week or so.
If I understand your post, if the clock is fast, the drift is positive, and the correction term C should be negative; and if the clock is slow, the drift is negative, and the correction term C should be positive.

As a side note I find the use of “ppm” to measure drift to be slightly confusing and slightly pointless. Clock drift might better be termed “drift rate” to make clear that it is the dimensionless ratio of measured seconds lost or gained over a period of time itself measured in seconds. Swap out seconds for fortnights and the ratio remains the same. Call this drift rate r, and substitute P for r using r=P/10^6 in the formula for C, and explicitly include the somehow implicit minus sign, and we get:

C = Round[-2^20 r/(1+r)]

which makes clear the quantization and the role the 2^20 plays in the quantization.
User avatar
ijabbott
Posts: 253
Joined: Fri Dec 15, 2017 2:34 pm
Location: GB-MAN

Re: RTC Calibration program

Post by ijabbott »

Yonatan wrote:
Sat Jan 14, 2023 6:36 pm
I just received my new DM41X, and I’m trying to understand Section 3.8 (RTC correction) in the online manual. I’m wrestling with the sign ambiguity in the definition of “drift” and in the definition of the correction term C. I agree with your post here:
ijabbott wrote:
Sat Jul 27, 2019 2:50 pm
I think the rtccalib.cfg value shown by the program possibly needs to be negated, or possibly the drift needs to be negated. I'm not sure which!

On 2019-03-31 (beginning of EU summer time), I set the calculator to the correct time.

On 2019-07-17 (108 days later), I noted my calculator had gained about 223 seconds, which is about +2.0648 seconds per day or +23.8983 ppm. The RTC calibration program produced a value of 25. I saved the rtccalib.cfg file with value 25 to the calculator and set the calculator to the correct time.

On 2019-07-27 (10 days since calibration), I noted my calculator had gained an additional 43 seconds, which is about +4.3 seconds per day or +49.7685. I.e. the rate of drift has slightly more than doubled since the initial calibration.

I know there has been some temperature variation between 2019-03-31 and 2019-07-27, but I can't imagine it having that much effect!

Today (2019-07-27) I shall set rtccalib.cfg to -25 and set the correct time on the calculator and monitor it in a week or so.
If I understand your post, if the clock is fast, the drift is positive, and the correction term C should be negative; and if the clock is slow, the drift is negative, and the correction term C should be positive.
The DM42 CALIB program has been updated since I wrote that. The updated version negates the result produced by the original version. I haven't used it for a while so I can't remember its parameters. Ideally it should take the current calibration value and the amount of time since it was changed into account.

If the clock is running fast the calibration value ought to be reduced (towards minus infinity), and if the clock is running slow the calibration value ought to be increased (towards positive infinity). Be careful with small adjustments for very small amounts of drift because that might flip the direction of the drift but with a larger absolute amount of drift.
As a side note I find the use of “ppm” to measure drift to be slightly confusing and slightly pointless.
It's just the same as people using a percentage instead of a per-unit fraction to describe a probability. But "parts per million" is the same as "per mille mille" (if such a term existed).
Clock drift might better be termed “drift rate” to make clear that it is the dimensionless ratio of measured seconds lost or gained over a period of time itself measured in seconds. Swap out seconds for fortnights and the ratio remains the same. Call this drift rate r, and substitute P for r using r=P/10^6 in the formula for C, and explicitly include the somehow implicit minus sign, and we get:

C = Round[-2^20 r/(1+r)]

which makes clear the quantization and the role the 2^20 plays in the quantization.
Indeed, but I think it would be even simpler for us humans if the drift was expressed as seconds per day. Using S for the number of seconds gained per day (negative if running slow), Your 'r' would then be S/86400. Or the calculation could be:

C = Round[-2^20 S/(86400+S)]
Yonatan
Posts: 6
Joined: Tue Dec 27, 2022 9:23 pm

Re: RTC Calibration program

Post by Yonatan »

Thanks for your reply! And I like your seconds/day version of the correction formula.
Post Reply