Page 1 of 1

STM32F1 - calibrating LSI

Posted: Sun Oct 16, 2022 3:45 pm
by dannyf
I was quite impressed with W801's feature to automatically calibrate its 32,768Hz RC oscillator - see here: https://dannyelectronics.wordpress.com/ ... libration/

This reminds me of the LSI on STM32F1 chips: a nominal frequency of 40Khz but a range of 30Khz - 60Khz. Thanks, ST :)

Here is my attempt at calibrating it: https://dannyelectronics.wordpress.com/ ... g-the-lsi/

in the end, I measured the LSI to be around 37Khz and brought down the error rate to < 100ppm.

the basic code isn't directly portable to STM32duino but the basic concept is. Hope it helps.

Re: STM32F1 - calibrating LSI

Posted: Sun Oct 16, 2022 5:49 pm
by ag123
one of those things which i may have misunderstood is that VBAT is mainly for LSE and to retain the few backup registers.
And if I'm right that VBAT works in conjunction with LSE + registers rather than LSI?
Hence, sometimes if VBAT, LSE, RTC + backup registers break, it kind of spoil the soup for me. Apparently, this bundle works as a subsystem.

Then there are lousy 32k crystals which drifts.
So I've this little 'RTC adjustment' piece (in roger's core)
https://github.com/rogerclarkmelbourne/ ... /RTCAdjust
that kind of allows one to compensate drifts in the 32k crystals

while i'd not claim ppm accuracy, after all that 'compensation', i've seen errors of less than a minute in a month (not terribly accurate, but decent).
i used to have a 5c 32k crystal that drifts so much that it is off by minutes the next day. All that 'adjustments' brought that 'less than a minute a month' performance.

Re: STM32F1 - calibrating LSI

Posted: Sun Oct 16, 2022 9:36 pm
by dannyf
if I'm right that VBAT works in conjunction with LSE + registers rather than LSI?
not sure. need to check against the datasheet.
less than a minute in a month
that's quite good: 1 minute / month =~20ppm. Most of those crystals are spec'd within that. But in reality they are often much better than that, typically in the 5-10ppm range.

there are watches that are good for 1 second / year = 30ppb. That's impressive.

When I get some time, I will build a TCXO of my own: using the mcu to measure temperature and then adjust pwm output to drive a varicap, in order to compensate for the crystal's tempco. that + running the crystla in a hot bubble (controlled by the mcu) could reach high stability.