Skip to main content
Suraj Vanjeeswaran
Associate II
April 12, 2017
Question

Could somebody guide me as to how to compute Precaler,Duration,dutycycle and period for STM32f469NI-eval board Timer

  • April 12, 2017
  • 6 replies
  • 1782 views
Posted on April 12, 2017 at 09:28

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.

    This topic has been closed for replies.

    6 replies

    Nesrine M_O
    Associate
    April 12, 2017
    Posted on April 12, 2017 at 13:20

    Hi

    Vanjeeswaran.Suraj

    ,

    Please try to start from ready examples under te STM32cubeF4 firmware package:

    • STM32Cube_FW_F4_V1.0\Projects\STM32469I_EVAL\Examples\TIM\TIM_PWMOutput
    • STM32Cube_FW_F4_V1.0\Projects\STM32469I_EVAL\Examples\TIM\TIM_7PWMOutput

    Refer also to

    http://www.st.com/content/ccc/resource/technical/document/application_note/group0/91/01/84/3f/7c/67/41/3f/DM00236305/files/DM00236pdf/jcr:content/translations/en.DM00236pdf

    application note it may help you.

    -Nesrine-

    Suraj Vanjeeswaran
    Associate II
    April 13, 2017
    Posted on April 13, 2017 at 12:16

    Thanks for your reply Nesrine. I'll post back after trying  out the example projects mentioned by you.

    Suraj Vanjeeswaran
    Associate II
    April 14, 2017
    Posted on April 14, 2017 at 13:01

    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

    Tesla DeLorean
    Guru
    April 13, 2017
    Posted on April 13, 2017 at 21:59

    >>

    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

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Suraj Vanjeeswaran
    Associate II
    April 14, 2017
    Posted on April 14, 2017 at 11:38

    Thanks for providing me the values Clive One I shall try them out and post back here

    Suraj Vanjeeswaran
    Associate II
    April 14, 2017
    Posted on April 14, 2017 at 12:36

    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