cancel
Showing results for 
Search instead for 
Did you mean: 

Is it better to use a hardware timer, or a freeRTOS Task with RTC for building a Metronome?

LMorr.3
Senior II

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!

11 REPLIES 11

"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.

The accuracy depends on a crystal, capacitors and PCB routes. Additionally the clocks can be individually calibrated and the frequency offset compensated.