2019-09-29 10:31 PM
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
Solved! Go to Solution.
2019-09-29 11:06 PM
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
2019-09-29 11:06 PM
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
2019-09-30 02:29 AM
@JW - Thanks for your guidance.... It works.