cancel
Showing results for 
Search instead for 
Did you mean: 

RTC calibration on sTM32f3 discovery

abelletoile9
Associate II
Posted on February 21, 2013 at 15:46

I meet difficulties to understand the RTC calibration protocoles presented in the UM1581, the RM0316 or the AN3371.Two distincts calibration procedures are discussed there in :

- a coarse one,

- a smooth one.

For what I understand so far from AN3371, the coarse calibration seems to be relevant to correct the offset due the 32KHz cristal inaccuracy once and for all whereas the smooth calibration allows an on the fly recalibration that could result from temperature drift for instance. Is this correct? If yes then should both calibrations be performed for a greater accuracy? I don't see any reference to the coarse calibration neither in RM0316 nor in UM1581... It seems, still from AN3381, that the coarse calib is available on f3 series (table 15) whereas no firmware driver API is available for it (Table 16)...

On an even more basic aspect, I don't understand the information given by AFO_CALIB (which seems to be refered to as RTC_CALIB in the reference manual)... How does this smooth calibration work... Do I need an external calibration source ? Do you have some illustration code to provide ?

And Finally, does the smooth calibration implies that the RTC is not available to other threads during the 32s calibration operation ?

Thanks in advance for any piece of information!

Arno
7 REPLIES 7
hatem_ch
Associate II
Posted on February 22, 2013 at 12:36

Hi,

If we take an oversight of the STM32 MCUs documentation, u will see that the coarse calibration was first introduced by STM32F1 MCUs family. STM32F2 MCUs’ RTC is also built-in with coarse calibration. But for recent products wave (STM32F3 and STM32F4), it is noticed that a new calibration technic is introduced : the Smooth Calibration.

Just, if we follow the chronological evolution of the RTC peripheral for STM32 MCUs, it is clear that the smooth calibration is the replacement of the Coarse technic. I think, that the Coarse calibration is kept only for compatibility reasons.

The Smooth Calibration can be used to:

- Either adjust the offset drift on LSE oscillation due to Crystal loading mismatch (static correction; it is done normally one time for each PCB)

- Or to dynamically compensate the temperature effect on the oscillation drift (Crystal oscillation frequency depends on temperature)

To measure the RTC drift, dedicated equipment are needed. But, basically, the principle of calibration is simple: just we need to calculate the time difference between two RTC updates.

Now, if you refer to the reference Manual, you find that ST people said: in order to get the right RTC deviation you need to measure the time between much more than one RTC updated : much more than one second:

They specify 8 seconds, 16 seconds and 32 seconds windows. For me of course I will adjust my RTC using the 32 seconds because it gives that better resolution as they said. But for someone how is producing millions of units, each second means money.

Now, how to measure the RTC one seconds updates? Because if you remember we need to count 32 RTC second updates and measure the time interval needed for that. The deviation will be simply the time elapsed divided by 32. And if you multiply by 10Exp6 you will get the drift expressed in PPM.

Hopefully, on STM32F3 RTC we have an 1-Hz output which can be directed externally to the MCU through the AFO_CALIB also called RTC_Calib.

Calibration seems to be transparent to the RTC operation. In other words calibration is done on the fly. If not, I think dynamic calibration has no sense. Isn’t ?

For calibration demonstration soft, as far as I know ST doesn’t provide a one (I checked on ST web site). From my side, personally, I didn’t need to develop such soft. So, sorry man I think you need to try to do it by yourself.

May be you can share with us later on your experience with RTC calibration.

That’s all !!

abelletoile9
Associate II
Posted on February 22, 2013 at 15:19

Hello einSTein (Albert? Franck?)

Well this is a nice and detailled answer!

Thank you very much for those informations.

So, if I understood it correctly, I can forget about the (almost deprecated) coarse calibration and focus on the smooth one! And I need an external calibrated 1Hz source to which I should compare each  PCB at least once to get the ad'hoc accuracy!

Unfortunately, the external source is a problem for me as it implies time and handlings which represent, indeed, an undesirable overcost...I guess I'll try to go without this nice <1ppm calibration :'( . If I can't, you can be sure I'll keep the forum posted with my struggle with calibration!

Thanks again for your post.

M0NKA
Senior
Posted on February 23, 2013 at 15:27

Hi,

My project is running on F4 part. I have TCXO main clock with 2.5 ppm precision, so

i thought it is a good idea to implement some type of calibration. With lots of reading

of the docs and some examples on the net i put something together(check attached file),

which in theory should work, somehow it didn't compensate 8-10 sec slow down per

24 hours. So i simply gave up and coded NTP protocol and just calibrate via time server

as i really need 1s precision.

Maybe there is a mistake in my code, and you can find it and make it work for you.

BR, Chris

________________

Attachments :

calib.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtVy&d=%2Fa%2F0X0000000aR7%2F6NHxslS8y6sqYYNs1w4MU3JOVVYZoexUnpR8nuNj4hc&asPdf=false
abelletoile9
Associate II
Posted on February 25, 2013 at 16:00

Hi Chris,

thanks a lot for sharing this.

I just had a look to your code and if I understood it right, you're using the TIM5 to calibrate your LSE. I don't not which clock you're using with that TIM5 but I'm afraid that it might have a lower accuracy than the LSE.

Am I wrong?

Best regards,

Arno

M0NKA
Senior
Posted on February 26, 2013 at 10:57

Hi,

I use the main clock for the TIM5. The part I use for it

http://uk.farnell.com/fox-electronics/fox924b-25-000/tcxo-25-0mhz-3-3v-smd/dp/2063962

. The 2.5ppm is not great,

but at least is temperature compensated. But still, i couldn't meet the 1s precision i

need, so i am calibrating via NTP now.

Regards

abelletoile9
Associate II
Posted on February 27, 2013 at 10:05

Hi M0NKA,

Ok, I get it now! I didn't understand it properly...

Well, your part seems interesting and not very expensive, it might be worth trying...

Thanks.

blacksu6
Associate II
Posted on October 24, 2014 at 11:43

I can set DCE bit of  register RTC_CR to enable RTC coarse calibration. But how can I do to enable RTC smooth calibration?  If I reset DCE bit of register RTC_CR and set proper value to register RTC_CALR, whether  RTC smooth calibration is enabled or not?