2019-05-21 04:56 PM
On the Nucleo-H743ZI board, I'm trying to configure TIM3 with a 10 us period. With the internal clock source at 200MHz, I would expect these parameters to create a 10 us TIM3 interrupt:
htim3.Instance = TIM3;
htim3.Init.Prescaler = 200;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 10;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL
But my TIM3 interrupt is occurring every 11us instead. Can anyone see what I'm doing wrong? Thanks for any help.
Solved! Go to Solution.
2019-05-22 10:52 AM
Don't guess... know. AN4013, STM32 cross-series timer overview, section 2,2 gives you an equation to figure out the prescaler and ARR (aka period) values. I don't have a H7 reference manual handy. but I am presuming the H7 timers are the same as the F4 and L4 (and every other line).
Just like the period being zero based, so is the prescaler. So in your original example, prescaler=199 and period=9 would have worked, as do the prescaler=1 and period=999 as you've found. At this point you are at the mercy of the stability/accuracy of your crystal (where errors are measured in parts per million).
I also noticed you changed the ClockDivision field. Just want to make sure you realize that has nothing to do with the output compare signal, but instead sets the clock divisor used in the digital filters on the timer's input signals.
2019-05-21 05:33 PM
0 ( Zero ) is a number too. Well, its a clocked valid state in context.
try period = 9;
2019-05-22 08:52 AM
Thank @Community member , changing period to 9 helps. Looking at an output compare that toggles on match, I saw the period was still a little off, 10.05 us.
Playing around with the prescaler and clock division, I get more accurate period (10.002us) with these settings:
htim3.Init.Prescaler = 1;
htim3.Init.Period = 999;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4;
Can it get even more accurate than that?
EDIT: I just realize, at this point, my scope probably can't measure with much more accuracy, so it's probably good.
2019-05-22 10:52 AM
Don't guess... know. AN4013, STM32 cross-series timer overview, section 2,2 gives you an equation to figure out the prescaler and ARR (aka period) values. I don't have a H7 reference manual handy. but I am presuming the H7 timers are the same as the F4 and L4 (and every other line).
Just like the period being zero based, so is the prescaler. So in your original example, prescaler=199 and period=9 would have worked, as do the prescaler=1 and period=999 as you've found. At this point you are at the mercy of the stability/accuracy of your crystal (where errors are measured in parts per million).
I also noticed you changed the ClockDivision field. Just want to make sure you realize that has nothing to do with the output compare signal, but instead sets the clock divisor used in the digital filters on the timer's input signals.
2019-05-22 12:33 PM
Thanks @Bob S, for the comment about the ClockDivision field not having anything to do with what I was doing. I did not realize that. And thanks for pointing me to the app note.