I am programming the RAK4631 via Arduino IDE.
I need a fairly accurate 1-second clock. When measuring the NRF_RTC1->COUNTER value, I can see that it runs slightly faster than 1 second: in 60 seconds, it is almost 2 seconds fast. This equates to a gain of > 40 minutes per day!
How can I correct this, or use another counter that is more accurate?
I don’t think millis() would work as I have some delay() functions in the code, which would pause the CPU, thus rendering millis() inaccurate, correct?
Please disregard my question above. I had not realized that the NRF_RTC1->COUNTER value is NOT milliseconds! It is instead the 32768hz clock divided by the NRF_RTC1->PRESCALER + 1, which by default is set to 31. So 32768/(31 + 1) = 1024. Therefore, if we divide NRF_RTC1->COUNTER by 1024, we get accurate seconds.