You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Is your Espruino 1v4 not keeping good time either? That should have a proper 32kHz crystal on it?

    Thanks! That's basically what I was doing in the branch I have that doesn't work very well, but there are some issues:

    • In his example it's only accurate to 1 part in 128, so he'll never be more accurate than 7800 ppm - it's better, but not great. Pretty sure that could be improved to 1 part in 16384 though.
    • LSI will still drift as the chip gets warm - if you auto-calibrate when the chip starts up it'll almost certainly drift off quickly if you're running full-tilt for any period of time.
    • Every time you set the prescaler, it seems to set the subsecond counter to 0 (as far as I could tell from the datasheet) - so you if you keep doing it all the time to keep track of drift you'll lose accuracy as well!
    • The code I use to maintain sub-32kHz accuracy via the RTC depends heavily on the subsecond counter - I've had trouble getting it working reliably right after the timer period changes.

    So I could actually expose that functionality as a function, E.calibrateRTC() - but I think realistically this is something users would have to call themselves. E.calibrateRTC() could save the new prescaler value into flash though - that could be a good compromise.

    ... or if I'm using the HSE for timekeeping, I could keep track what the LSI speed was all the time - and when I go into Deep Sleep I could adjust the amount of ticks I sleep for with that in mind... So not trying to 'fix' the LSI speed, but actually just being aware of it and working around it.

About

Avatar for Gordon @Gordon started