cancel
Showing results for 
Search instead for 
Did you mean: 

Help configuring STM32H7 timer

edwin8
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Bob S
Principal

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.

View solution in original post

4 REPLIES 4
T J
Lead

0 ( Zero ) is a number too. Well, its a clocked valid state in context.

try period = 9;

edwin8
Associate II

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.

Bob S
Principal

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.

edwin8
Associate II

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.