Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4919

MicroPython • Re: Aligning actions to a specific time-gap before a second

$
0
0
You can use the on-chip elapsed microseconds counter or the 'time.ticks_*' functions to determine when a second has elapsed, or it's time to update your progress bar. That should give minimal latency and you should be able to get things synchronised so you are waiting for those synchronisations rather than doing anything else.
OK. it's back to reading the documentation for me, to understand how to do this.
Perhaps the display update is doing more than it should be doing and sometimes taking a long time to do that ?

You can add a 'print(time.time())' at the start and end of the update code to see how long it takes. Or note start and end times and show 'end minus start' as elapsed.
I'm updating only a small portion of the display's buffer for the timer update, but then the whole buffer is written to the display to be updated. I've had someone update the code to write only a portion of the buffer, which is an optimization I can use for sure. I'll also augment the code with time printing to give me a better idea where I 'm going wrong :(
For maximally accurate synchronisation with NTP, don't use the RTC which is only second accurate at best. By noting the elapsed microsecond count and using the fractional NTP seconds, you can get far better synchronisation even without determining what the delivery latency of the NTP packet was.
Second accuracy is all that is required for the TOPT calculation itself. Sub-second accuracy isn't required, just stable periodicity by a constant delta from the second. I'll try and figure out the second elapse boundary as you suggested at the beginning, (or some ticks value before the second itself).

Statistics: Posted by samveen — Wed Apr 10, 2024 3:19 pm



Viewing all articles
Browse latest Browse all 4919

Trending Articles