2017-04-12 12:28 AM
I am trying to setup PWM to control Stepper Motor using stm32cubemx code initialiser with keil IDE, I need a max duty cycle of 50% at a frequency 12MHz. I am trying to obtain proper values for prescaler, autoreload(duration) and period for configuring my timer for the above configuration.
2017-04-12 04:20 AM
Hi
Vanjeeswaran.Suraj
,Please try to start from ready examples under te STM32cubeF4 firmware package:
Refer also to
application note it may help you.-Nesrine-
2017-04-13 05:16 AM
Thanks for your reply Nesrine. I'll post back after trying out the example projects mentioned by you.
2017-04-13 12:59 PM
>>
I am trying to setup PWM to control Stepper Motor using stm32cubemx code initialiser with keil IDE, I need a max duty cycle of 50% at a frequency 12MHz. I am trying to obtain proper values for prescaler, autoreload(duration) and period for configuring my timer for the above configuration.
180 / 12 = 15
168 / 12 = 14
Prescaler wants to be 0 ie 1 -1, Period wants to be 14 ie 15-1 for a 180 MHz clock source (TIMCLK, so APB2)
The Pulse = 15 / 2, but has to be an integer, so that won't be exactly 50/50. If that's an absolute must you'll need to run at 168 MHz
You are also not going to have a lot of choices of pulse width at this frequency
2017-04-14 04:38 AM
Thanks for providing me the values Clive One I shall try them out and post back here
2017-04-14 05:36 AM
Hello Clive One,
I tried to control my stepper motor using the values for prescaler,Counter Period and duty cycle provided by you,But unfortunately my stepper motor does not rotate,it just generates a humming noise.I even tried reducing the Timer Out Clock frequency to 2KHz by using these values
Prescaler=0
Counter Period =[(90MHz/2KHz)-1]=45000-1=44999 (my timer Timer 3 is connected to APB1 )
Duty Cycle=4499*(50/100)=22,499.5 I took 22,499 for 50% duty cycle
My motor currently works with PWM for the following Timer Parameters
Prescaler=1
Counter Period=65535
duty cycle= 65535*(50/100)=32767.5 or 32767 integer value for 50% duty cycle
I am trying to rotate my motors at a desired speed of 540RPM, With the above parameters I am only getting a speed of 180RPM.I would be very grateful if you could guide me as to how to achieve the desired speed for stepper motor using PWM.
-Suraj Vanjeeswaran
2017-04-14 06:01 AM
Hello Nesrine,
I tried out the example project TIM_PWMOutput located in STM32Cube_FW_F4_V1.15.0\Projects\STM32469I_EVAL\Examples\TIM\TIM_PWMOutput
wherein the PWM output(Step Pin) is taken from PC6. I modified the example to add a new Pin PA2 as GPIO_Output for setting DIR for the stepper motor. But I am not able to get the motor to rotate with this,kindly advise if I am missing something here.Also I would be grateful if you could provide me some example program based on stm32cubemx to control a stepper motor using STM32F469NI-eval board interfaced with A4988A Pololu stepper drivers.
-Suraj Vanjeeswaran