cancel
Showing results for 
Search instead for 
Did you mean: 

Best prescaler/period tradeoff to generate a clock

VDaanen
Associate II

Hello,

I need to generate a clock to trigger some sensors acquisition at a given frequency..

I'm doing this using a timer

I do have several choice to configure the timer prescaler & period fields.

My question is : what is the best choice to limit MCU core use ? should I prefer high prescaler and low period, or low prescaler, or there is no reason to choose one versus the other...

I could not find any clues, my feeling is that I should prefer high prescaler (because most of the timer, prescalers are HW) and reduce period (because SW) but that's just an intuition...

Thanks

Vincent

7 REPLIES 7
VDaanen
Associate II

note an answer.. but from an4776, seems my intuition was not so bad (or at least I hope so..)

KnarfB
Principal III

If it is a fixed frequency, it doesn't matter, everthing is hardware if you use dedicated PWM / toggle output and the core is involved only for setup. For some frequencies and chips, you might be able to use the MCO pin too.

hth

KnarfB

AScha.3
Chief III

>I need to generate a clock to trigger some sensors acquisition at a given frequency.

generate clock with timer = hardware, set prescale and period as you want

at given frequency -> so anyway is fixed and you have no choice - or i dont understand, what is your question then.

If you feel a post has answered your question, please click "Accept as Solution".
VDaanen
Associate II

Hi

thx for your answers guys..

just some additional info: the clock is used by the fw to trigger an acquisition. The code polls on a global variable which is set to true in the interrupt routine associated to the timer

@AScha.3​ say i want to generate a clock at 100Hz (STM32L476 with HSE 80MHz), the following configs are correct:

  • prescaler = 2, preload=400000
  • prescaler = 4, preload= 200000
  • prescaler = 100, preload=8000

which one should I prefer ? if counter also HW, then it should not have any impact...

BR

V

AScha.3
Chief III

i would take /100, preload 8000 . just because this is < 16bits , so every counter 16 or 32 bit is working fine.

100 Hz come out anyway.

If you feel a post has answered your question, please click "Accept as Solution".
KnarfB
Principal III

for both, you have to subtract 1, i.e. prescaler == "divide by 100" = 100-1 = 99 and so on.

hth

KnarfB

S.Ma
Principal

If you use a low power STM32 (L4, L5, U5), most peripherals have individual clock source mux, so the core clock can be changed (power) or even stopped (halt): Brain in the Coma and Organs still functioning...