cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate ARR value for Timer TIM2, TIM3 in STM32F407

Ash1
Associate III

Hi

Can you tell me how I can calculate a value for ARR for timer 2(32bit timer) and timer3(16bit timer)

I am using STM32F407 APB1 timer clock is 12MHz prescaler is 6

17 REPLIES 17

Timer settings seems to be right. Have you done clock configuration in CubeMX? Please check if time clock (APB1 Timer clocks) is really 72 MHz.

Set CKD in (TIMx_CR1) as 00 should be correct

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


@Hl_st wrote:

 check if time clock (APB1 Timer clocks) is really 72 MHz.


+1

@Ash1 If in doubt, route the clock to one of the MCO pins, and measure it; eg, on an oscilloscope.

AndrewNeil_0-1738752872103.png

 

Sounds like you're clocking at 100 or 108 MHz, not 72

Check your PLL and HSE relationships 

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

 

hi

Can you suggest me a code in which there is generated interrupt using any timer

 


@Ash1 wrote:

 

hi

Can you suggest me a code in which there is generated interrupt using any timer

 


Time base with interrupt:

https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Projects/STM324xG_EVAL/Examples/TIM/TIM_TimeBase

PS: No ioc file available for this example.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

@Ash1 wrote:

Can you suggest me a code in which there is generated interrupt using any timer


The code posted by @SofLit in the very first reply !

Ash1
Associate III

Hi

I have recheked my configuration and found it was 84mhz timer clock instead of 72Mhz

so for 10 second I am loading 0x98967F in ARR and 83 i have loaded in PSC register but still timer is generating UIF flag sometimes in 7 seconds 4 seconds 2 seconds .can you help me Why I am facing this irregular intervals of setting UIF flag

Note :Do i have to set URS bit also in CR1 will it effec

You should be able to set it up once, and it will keep knocking at the right period.

Do you change anything in the interrupt handler or callback?

If you have SysTick running you could record HAL_GetTick() on the update interrupt, perhaps print there, or in your main() loop, or toggle a GPIO.

At long periodicity it will be a challenge to scope

 

I tend to code directly in HAL, without the code generators, it's not hard to set up the TIM in timebase mode. Soflit's code should suffice.

For long term you need 32-bit like TIM2 / TIM5, or you can use 16-bit or SysTick to count off smaller periods, or count-down a queue/list of software timers, say millisecond counts.

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