2023-02-16 02:54 AM
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
2023-02-16 02:56 AM
note an answer.. but from an4776, seems my intuition was not so bad (or at least I hope so..)
2023-02-16 03:29 AM
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
2023-02-16 03:29 AM
>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.
2023-02-16 04:52 AM
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:
which one should I prefer ? if counter also HW, then it should not have any impact...
BR
V
2023-02-16 10:03 AM
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.
2023-02-16 10:07 AM
for both, you have to subtract 1, i.e. prescaler == "divide by 100" = 100-1 = 99 and so on.
hth
KnarfB
2023-02-16 11:13 AM
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...