Skip to content

RTC 'calibration' #469

@Rutherther

Description

@Rutherther

It's possible that if LSE crystal is used, the crystal won't have the exact frequency of 32.768 kHz. It looks to me that Rtc::select_frequency is not enough, as it allows only to set whole number frequencies. If I want to have RTC with 1 Hz, and the clock gets ahead by a second or two per day, the prescaler for RTC should be different than 1 Hz based precisely on 32.768 kHz. (should not be 32.768 / 1 - 1)

This HAL currently does not support adding or subtracting from the prescaler. This may be solved by writing to prlh and prll directly, but I would say that implementing support for some kind of a calibration like this is not out of scope of this HAL and could be implemented in Rtc.

What do you think about this? And what do you think the implementation should be? The best I came up with is making something like Rtc::select_precise_frequency(&mut self, frequency: Hertz, adjustment: u32), where adjustment would just be added to the prescaler.

I am up to PR this, but I am unsure 1. if this is in the scope of this HAL, 2. if the implementation I proposed makes sense, maybe it could be done better

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions