cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 and PWM (12bits)

jlecl.1
Associate III

Dear everyone,

I'm trying to manage a DC motor with IC controller in PWM.

My frequency have been calculated for have 12bits resolutions (Fclk :72Mhz > Fpwm17.5Khz).

 

TIM2->CCR1 = 30;
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
HAL_GPIO_WritePin(GPIOB, MA_SENS_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, MA_SLEEP_Pin, GPIO_PIN_SET);

 

The desired frequency is good, but i'm not able to have the resolution.
I thinks, my DutyCycle command is not right but no idea to do different.

Do you have an idea ?

Capture.PNG

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
AScha.3
Chief III

You set the prescaler to 72, so you get 1us ticks. Then 54 ticks in timer...17 khz with 5 bit resolution - as you set it.

For 12bits set prescaler to 0 and timer to 4095, then get 12 bits

And CCR 2048 is mid/half period.

But why so high frequency? Do you drive the motor direct with this pwm (MOSFET and freewheeling diode )? Then from my tests a much lower frequency is better, because of the high inductivity of the motor.

I used 200 Hz or so...

 

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
AScha.3
Chief III

You set the prescaler to 72, so you get 1us ticks. Then 54 ticks in timer...17 khz with 5 bit resolution - as you set it.

For 12bits set prescaler to 0 and timer to 4095, then get 12 bits

And CCR 2048 is mid/half period.

But why so high frequency? Do you drive the motor direct with this pwm (MOSFET and freewheeling diode )? Then from my tests a much lower frequency is better, because of the high inductivity of the motor.

I used 200 Hz or so...

 

 

If you feel a post has answered your question, please click "Accept as Solution".

Thanks for you reply.

The 17,5Khz have been choosed for three raison:

> Current pulse smaller

> Sound not audible

> 12bits resolution as calcul with the formula.

I will test it now!