2022-05-02 10:25 AM
To build a metronome, I plan on using on using a freeRTOS task running a while(1) with RTC timestamps to trigger clock ticks.
The freeRTOS task will run high priority but yield to other tasks which will do other work like toggle leds or other pins. Using the timestamps, I can track and compensate for 'drift' between beats. Do I need the RTC clock for this approach? I don't want the metronome beats to lag/drift over long duration.
Should I use a hardware timer with interrupt instead? I'm trying to determine the best approach before I proceed.
Update: I'm now thinking of using a hardware timer to interrupt every 2ms and increment global variable ms_elapased and checking that variable in my freeRTOS Task's while(1) to play each 'beat'.
Thanks for any ideas!
2022-05-06 07:14 AM
"Timer drift" is just not happening if you autoreload. So it all comes down to the oscillator you use to feed the timer, be it crystal, rc or whatever.
2022-05-09 01:30 PM
The accuracy depends on a crystal, capacitors and PCB routes. Additionally the clocks can be individually calibrated and the frequency offset compensated.