Dynamic calibration of MCP79410 RTC

Hello

In order to calibrate the RTC (MCP79410) one method Microchip mentions is to test the difference between the original calibration time and the current real time and account for the difference in seconds during that period with the given PPM calculation (Equation 5-3).

The problem here is that these could already be field deployed devices and this means that the TRIMVAL register could already be set and any new setting would mean taking the current TRIMVAL setting into account.

To calculate this new TRIMVAL based on the current TRIMVAL setting would this be the correct way to adjust the TRIMVAL settings :

TRIMVAL = newTRIMVAL - currentTRIMVAL

where TRIMVAL is calculated as per EQUATION 5-4 and 5-3 on Pg 31 of MCP79410 manual.

TRIMVAL = PPM x 32768 x 60 / (1000000 x 2)

My thinking is when date time is set save this date and time in the RTC ram and when a new date and time is set down the line calculate the difference between saved date and time and new date and time to calculate the new TRIMVAL.

thanks in advance
cb

I only glanced at the datasheet but it looks like TIRMVAL is a signed quantity.

So without fear I suggest that the new recommended value be added to the current value:

TRIMVAL += newTRIMVAL;

I'll stay tuned, for the same issue coming up for me with the DS3231 - def want to make it happen automatically when the clock is given a minor adjustment after a prolonged running period.

a7

1 Like

I did a project using a GPS module to set the initial value of the Aging register of the DS3231, but never got around to doing the dynamic adjustment. But I concluded that if you can use Alarm2 as your only alarm, then you could store the previous adjustment time in the Alarm1 registers, which go down to the second. As long as you never enable Alarm1, there would be no effect on the RTC functions.

Also, it may not be obvious which way to adjust the Aging register if the RTC is running slow or fast. As I recall now, I ended up thinking that increasing the register value adds units of capacitance to the crystal oscillator, which would slow it down. So that would mean you would increase the value if it's running fast, and decrease it if it's running slow. That logic may work, or it may be just the opposite. :slight_smile:

Anyway, I hope you post your DS3231 solution when it's ready.

Other possibly useful information. For a Nano running at 16MHz, at room temperature, a single increment or decrement of the Aging register is equivalent to 264 Nano clock cycles over a five-minute period. That's for the DS3231SN. It's 576 clock cycles for the DS3231M.

Further clarification on using the Alarm1 registers to save the most recent adjustment time. I was just thinking that there are four registers, which is 32 bits of information. That could just be the number of seconds since 12:00:01 January 1, 2025 UTC.

Thanks Alto777 - will try it and post results here.

Unix time should work and each AR bit is 0.1ppm (+ or - dep on sign bit).

I know the datasheet says that, but I actually got .055ppm for an SN part at room temperature. It may vary with temperature. And yes, Unix time would also work, at least for a while.

On closer inspection of the calculation its not as simple as adding two values as the sign bit is a direction bit and nothing to do with representing a -ve number,

if RTC has gained time (fast) after PPM calculation then clear sign bit and if RTC has lost time (slow) then set sign bit.

For any calculation compensating for the value already in TRIM register this means if the newTRIM value has the same sign bit as the TRIM value then add the TRIM and newTRIM values and keep the sign bit whether 1 or 0 depending on slow or fast RTC..

If the sign bits of the newTRIM and the TRIM already in the register are different then subtract the smaller TRIM value from the larger TRIM value and keep the sign of the larger value.

Let me know if you are in agreement. Would hate to deploy a few 100 only to discover an oversight !!

Thanks.

cam

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.