2023-07-11 07:04 AM - edited 2023-07-11 07:06 AM
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 ?
Solved! Go to Solution.
2023-07-11 08:19 AM - edited 2023-07-11 08:30 AM
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...
2023-07-11 08:19 AM - edited 2023-07-11 08:30 AM
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...
2023-07-11 08:38 AM
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!