Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function that uses the register "FREQCORR" for clock correction #89

Open
Abravius opened this issue Jun 28, 2022 · 3 comments · May be fixed by #98
Open

Add function that uses the register "FREQCORR" for clock correction #89

Abravius opened this issue Jun 28, 2022 · 3 comments · May be fixed by #98
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@Abravius
Copy link

Abravius commented Jun 28, 2022

The RTC in my chip isn't really accurate. I think I'm not the only one

I looked in the library source code, but didn't find any existing function that allows correcting the clock.

I think it would be very important to add a function to correct the clock. This can be done using the FREQCORR" register.

Datasheet:

https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Atmel-42181-SAM-D21_Datasheet.pdf

Register in the page 262.

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Jun 28, 2022
@Abravius Abravius reopened this Jun 29, 2022
@Abravius
Copy link
Author

Abravius commented Jun 29, 2022

I've this solution :

//Function used to correct the RTC clock

//<_Sign> :   If the correction must be positive (false) or negative (true)
//<_Value> :  Value to put in the register from 1 to 127.
void SetClockCorrection(bool _Sign, byte _Value)
{
         RTC->MODE2.FREQCORR.reg = (byte)_Sign << 8 || _Value;
}

I'm testing it right now.

@Abravius
Copy link
Author

After 24 hours, same problem. I don't know why...

@pe-jot
Copy link

pe-jot commented Oct 30, 2023

After 24 hours, same problem. I don't know why...

Your code shifts _Sign one bit too far.
Furthermore, as far as I read the datasheet, there's need for write synchronization, thus you'll have to place something like
while(RTC->MODE2.STATUS.bit.SYNCBUSY); before writing the register.

@per1234 per1234 changed the title Feature request: Adding a function using the register "FREQCORR" for clock correction Add function that uses the register "FREQCORR" for clock correction Oct 31, 2023
@pe-jot pe-jot linked a pull request Oct 31, 2023 that will close this issue
@per1234 per1234 linked a pull request Oct 31, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants