RTC drift due to temperature variations on Kinetis K device

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RTC drift due to temperature variations on Kinetis K device

Jump to solution
3,755 Views
anujtanksali
Contributor II

Hello,

I am using MK22FN512 device and observed that the RTC deviates over a period of time so temperature compensation is required to correct the RTC.

Taking reference from application note AN4149 (attached) which is for Kinetis M device and datasheet of MK22FN512  have listed out the steps required below,

Please let me know if the steps are correct.

 

1. Read the temperature every 15 minutes using formula below

temp = 25 - (Vtemp - Vtemp25) / m))

Vtemp is current voltage measured 

Vtemp25 is the voltage at 25DegC (this value is taken from datasheet)

m is the temperature sensor slope (this value is taken from datasheet)

temp is the measured temperature.

2. Calculate the frequency deviation using formula below

f = f0 [1 - 0.04ppm(T-T0) (T-T0)]

-0.04ppm is temperature coefficient as per crystal datasheet

T is measure ambient temperature 

T0 is 25DegC

using above we get the temperature f and comparing to f0  which is 32768 we get the PPM error at temperature T i.e. (f0-f) will give the ppm error.

 

3. Using above PPM error in formula below,

 

PPM error = Tcr / (CIR + 1)

using this we get values of Tcr and CIR and we can set the values of the registers Tcr and CIR.

 

4. Wait for next 15 min cycle and repeat the above steps.

 

Thanks and Regards,

Anuj

 

0 Kudos
Reply
1 Solution
3,686 Views
_Leo_
NXP TechSupport
NXP TechSupport

Hi,

Indeed, you can use that range of values for your implementation, since the specification for Temp sensor slope (1.55 to 1.69mV/°C) covers the entire range of VDD voltage values and 3.3V is within the range. Note that it won't be exactly 1.62mV/°C, but it won't go out of range.

On the other hand, I share with you the Application Note AN3031 , which is a bit old, but it will serve as a guide on how to calibrate the temperature sensor.

Regards,
Leonardo

View solution in original post

0 Kudos
Reply
11 Replies
3,748 Views
mjbcswitzerland
Specialist V

Hi

I think the first thing that needs to be done is ensure that the RTC crystal is accurately matched to the circuit since the most important thing is that you have minimum drift at 25°C.
A crystal based RTC will typically be accurate to around 5 minutes a year when the basic circuit is correct.
The RTC compensation has a resolution of about 5 minutes/year steps and can be used to compensate big errors but won't make it more accurate since it can't 'tune' better than a good crystal circuit.
Although temperature compensation can be performed it is likely to be only effective if the circuit is intended for a wide operating range and, due to its limited resolution, may require periods of over compensation followed by periods of under-compensation to emulate a more accurate long-term adjustment.
Also don't forget that temperature compensation is only possible when the processor is running and will have no effect when the circuit is powered down (battery backed up RTC). Long periods of such a circuit powered off at temperature extremes could result in high drift if the basic HW is not stable - which can't be compensated.
Basically it usually makes more sense to invest in ensuring that the HW is accurate (chosen crystal correctly matched to the circuit and its loading capacitors); that the crystal (or oscillator) is inherently accurate (tight tolerance and low temperature deviation) and its loading capacitors are of precision than to try to compensate.
For high precision applications a temperature compensated oscillator can be considered as well as a means of synchronising the time to an external reference (eg. when there is access to a time server via a network connection).

Regards

Mark

0 Kudos
Reply
3,746 Views
anujtanksali
Contributor II

Hello,

Thanks for the quick reply.

I understand your point and we do have devices which connect to the internet and can sync RTC with internet time. But we also have devices where the internet is not available.Our devices once turned on keep on running continuously so there is no issue of powering the device off. The user will set the RTC again if it is powered down for a long time and then powered up.

But If the only way is to compensate through software then are the steps mentioned above correct?

Regards

Anuj

 

 

 

0 Kudos
Reply
3,743 Views
mjbcswitzerland
Specialist V

Hi

The steps are correct apart from the detail that you have to consider the fact that the compensation is still fairly course.

For example, if the formula says you need to compensate +3ppm due to the present temperature and the only compensation settings allow 0 or +11ppm or +22ppm there is no point in rounding the result and choosing the next compensation step since it may result in either no compensation or "over compensation" which results in worst drift in the opposite direction.

If you need to compensate +3ppm you would need to compensate +11ppm during one compensation period (usually 4.25 minutes) and then remove the compensation during 3 compensation periods.
The exact point in time of each compensation is not known apart from the fact that it will take place at some instance in a compensation period (the period being the value of CIR in seconds - whereby CIR will practically always be 255 so smallest adjustments).
If the temperature is changing quite rapidly each attempt to compensate may add more error than it is attempting to remove during such periods.
Essentially some averaging may be required to ensure best performance.

Regards

Mark

 

0 Kudos
Reply
3,722 Views
anujtanksali
Contributor II

Hello,

Thank you for your reply.

I had question about the formulas used. 

The formulas use the temperature coefficient value and temperature slope value which can be taken from the datahseet but values in the datasheet are specified at certain conditions highlighted below.

anujtanksali_1-1650900986833.png

 

as per my hardware VDDA is connected to 3.3V and the values specified are for VDDA = 3V

So can I use the above values directly in my implementation or I will have to calculate the values as per my hardware. If yes then how do I calculate the temperature coefficient value and temperature slope value?

Thanks in advance

Regards

Anuj

0 Kudos
Reply
3,687 Views
_Leo_
NXP TechSupport
NXP TechSupport

Hi,

Indeed, you can use that range of values for your implementation, since the specification for Temp sensor slope (1.55 to 1.69mV/°C) covers the entire range of VDD voltage values and 3.3V is within the range. Note that it won't be exactly 1.62mV/°C, but it won't go out of range.

On the other hand, I share with you the Application Note AN3031 , which is a bit old, but it will serve as a guide on how to calibrate the temperature sensor.

Regards,
Leonardo

0 Kudos
Reply
3,659 Views
anujtanksali
Contributor II

Hello,

Thank you for your reply. It is very helpfull in the code implementation. 

Can you please share a code sample if present for temperature compensation. Am using KDS IDE for code development and device is MK22FN512

Thanks and Regards,

Anuj

 

0 Kudos
Reply
3,640 Views
_Leo_
NXP TechSupport
NXP TechSupport

I regret to inform you that there is no SDK example for this part. On the other hand, we do not longer support the KDS, so we recommend our valuable clients to move to MCUXpresso IDE.

Please let me know if I can help you on anything else.

0 Kudos
Reply
3,635 Views
anujtanksali
Contributor II

Hello,

Can you please share SDK example used for a different part similar to above part or any other part as the logic will be similar. Similar part SDK example is prefered. We use MCUXpresso IDE too so no issues with the IDE.

Thanks and Regards

Anuj

 

 

0 Kudos
Reply
3,608 Views
_Leo_
NXP TechSupport
NXP TechSupport

I have consulted the documentation and the community, and for Kinetis MCUs officially only the application note AN3031 covers the temperature sensor, which includes some sample code. It was written for the S08, but the equations work for Kinetis as well, and the ADC is very similar.

0 Kudos
Reply
3,521 Views
anujtanksali
Contributor II

Hi

Thanks for the reply.

Is there a sample code available for RTC compensation? Can you please share it. It might be for a different kinetis controller then also its fine. I was not able to find any sample code.

Thanks

Anuj

 

 

 

0 Kudos
Reply
3,494 Views
anujtanksali
Contributor II

Hi

Am implementing RTC temperature compensation for a K22FN512 device

Am able to get the frequency using equation from the application note AN4949

Am assuming the equation is valid for a kinetics K22FN512 device

f = f0 * [1 - 0.04ppm ((T - T0) * (T - T0)]

and then calculate the frequency error by f - f0

f0 is crystal frequency 32768 KHz

Then using the equuation

f-f0  = Tcr / (CIR + 1)

calculate the Tcr using CIR = 24 i.e the compensation is applied every 25 sec

Set the Tcr  and CIR values in RTC TCR register 

Is this procedure correct?

Please let me know

 

Thanks and Regards

Anuj

 

 

 

 

 

 

 

 

0 Kudos
Reply