cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to obtain precise Hz increments using a Timer to set BeatsPerMinute?

LMorr.3
Senior II

I need to trigger a timer updateEvent at a rate ranging from 2 BeatsPerMinute to 1000 BeatsPerMinute. I can get the correct range by setting the timer's prescale value from 1 to 30,000 but I need to land on precise BeatsPerMinute integers. If I set the prescale to 1000, I get 76.9054 BeatsPerMinute but would like updateEvent interrupts exactly 76BPM.

Do I hook into the RTC so that I am using a 32.768KHz clock source to make the timing work as I require?

7 REPLIES 7

What part are we talking about, and what frequency are you clocking it at?

The TIM can have awkward factors, and the prescale/period are coded as N-1

Divide by 1000 would be 999, as this is a comparator for a 0 .. 999 range, to match the last count prior to the update

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TDK
Guru

Integer values of 2-1000Hz should be possible to hit exactly with typical clock frequencies.

> If I set the prescale to 1000, I get 76.9054 BeatsPerMinute

How exactly are you calculating this? What is your timer tick frequency?

If you feel a post has answered your question, please click "Accept as Solution".
LMorr.3
Senior II

Thank you for pointing this out. I now see that I can get integer values using the 84MHz osc by changing the prescale value.

> Integer values of 2-1000Hz should be possible to hit exactly with typical clock frequencies.

Show.

Btw., 2-1000BPM is 33.333mHz-16.667Hz... ;)

JW

LMorr.3
Senior II

My clock is 84MHz. What prescale value can I use to get 9kHz? Also, what prescale would get me to 11kHz? I'm able to get precise integers on the other.

S.Ma
Principal

How about RTC with 32868 Hz precise LSE crystal?

LMorr.3
Senior II

I'm currently looking into using a freeRTOS Task with timestamps between 'beats' instead of a hardware timer. Not sure if this is a good approach but will test it.