cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030R8T6 Timer 3 Initialization Problem

Nimit Vachhani
Associate III

Greetings Everybody,

I am initializing STM32F030R8 Timer 3 with 48MHz clock and pre scaller 480 - 1 -> 479 and counter period 1. Technically this timer 3 interrupt should be generated at 48MHz / 480 -> 100KHz. On every interrupt i am toggling PA4 GPIO which i am viewing in Oscilloscope and it shows the frequency of 25KHz .. Shouldn't i be getting 100KHz output ? I cant figure out where i am going wrong ?

Any help would be of great help.

I am using STMCube and HAL libraries..

Below is snapshot of timer 3 init

0690X000009joQ5QAI.jpg

1 ACCEPTED SOLUTION

Accepted Solutions

The frequency of Update events (to which you probably interrupt - I don't use Cube) is ftimer/(TIMx_PSC+1)/(TIMx_ARR+1), i.e. if you set ARR ("Period") to 1, the frequency is half of the output of prescaler. You can't set ARR to 0 as that stops the timer; if you want higher frequency, lower the prescaler.

Now if you toggle output at every timer period, your output frequency is half of the toggle frequency - a full period of output waveform is two periods of timer, as in one period you set 0 and in second you set 1.

These two things make your output frequency quarter of what you expect.

JW

View solution in original post

2 REPLIES 2

The frequency of Update events (to which you probably interrupt - I don't use Cube) is ftimer/(TIMx_PSC+1)/(TIMx_ARR+1), i.e. if you set ARR ("Period") to 1, the frequency is half of the output of prescaler. You can't set ARR to 0 as that stops the timer; if you want higher frequency, lower the prescaler.

Now if you toggle output at every timer period, your output frequency is half of the toggle frequency - a full period of output waveform is two periods of timer, as in one period you set 0 and in second you set 1.

These two things make your output frequency quarter of what you expect.

JW

Nimit Vachhani
Associate III

@JW - Thanks for your guidance.... It works.