cancel
Showing results for 
Search instead for 
Did you mean: 

PWM configuration with CubeMx

RStra
Associate III

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

6 REPLIES 6

> In both case the frequency is the expected value

Then what's the problem?

JW

Sorry,

I mean the frequency ISN'T correct. I have have edited my post .

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

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

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

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