2019-01-23 02:11 AM
Hello,
I'm working with an STM32F401RE (on a Nucleo), and I have some problem with the TIMER frequency.
a) The frequency APBx is 84Mhz, and I want a 500Hz PWM frequency on TIM3.
I set prescaler to 167 (168-1) and period to 999 (1000-1), is it correct ?
b) I also want a 500uS interrupt from TIM1 and i set prescaler to 0 and period to 41999 (42000-1), is it correct ?
In both case the frequency isn't the expected value (checked with oscilloscope), so I was wondering if it's my fault of that is due to the accuracy of the internal oscillator.
Thanks
Riccardo
2019-01-23 10:09 AM
> In both case the frequency is the expected value
Then what's the problem?
JW
2019-01-23 10:19 AM
Sorry,
I mean the frequency ISN'T correct. I have have edited my post .
2019-01-23 02:14 PM
And what is that incorrect frequency exactly?
What's the system frequency? Did you verify it by outputting onto MCO pin and measuring?
What's the APB divider? Note, that if it's >1, TIM input frequency is 2x the respective APB frequency.
Isn't APB1 maximum frequency 42MHz? You said that APBx for TIM3 is 84MHz, but TIM3 is on APB1.... so how is it?
Is the PWM generated using one of the PWM modes or using Toggle mode?
JW
2019-01-24 01:16 AM
I have activate the MCO and the oscillator is 16.25 Mhz, for that reason my values have an error of about 1.5% .
Thanks for your advice
2019-01-24 01:33 AM
You mean HSI?
That's slightly more than the datasheet value for factory-calibrated HSI at 25deg. which is +-1%, but the mcu might have heated up during measurement and also oscilloscopes are usually not a precision timing measurement instrument.
I wouldn't expect much more precision from HSI; if you need better precision, use a crystal or XCO (i.e. use HSE).
JW
2019-01-24 03:30 AM
Yes, HSI.
I agree that the error on the HSI is slightly too high.
I'll try a new nucleo when I'll get it, because currently I work on a old board used by other developer.
Thanks