This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

stepper motor control using drv8811

Other Parts Discussed in Thread: MSP430FG4618, DRV8811

i am using msp430fg4618 and drv811 to run a 7.5 degree, 12V stepper motor in microstep mode....assume rpm=120

i have a written a program to give PWM signal of 50% duty cycle to the STEP pin of 8811. is it right?

#include <msp430fg4618.h>

#include <in430.h>

 

 

void main(void)

{

  volatile unsigned int i;

 

  WDTCTL = WDTPW +WDTHOLD;                  // Stop WDT

 

SCFQCTL = 0x82;                             //f= 2*32768*(4+1) approx 

 

equals 320kHz

SCFI0 = 0x40; 

FLL_CTL0 = 0x30;                           //DCO outputis divided, 

 

Xcap=10pf

FLL_CTL1 = 0x20;                           //XT2 is OFF, MCLK=SMCLK=DCO

 

 

 

  // Wait for xtal to stabilize

  do

  {

  IFG1 &= ~OFIFG;                           // Clear OSCFault flag

  for (i = 0x47FF; i > 0; i--);             // Time for flag to set

  }

  while ((IFG1 & OFIFG));                   // OSCFault flag still set?

 

  P1DIR |= 0x04;                            // P1.2 output

  P1SEL |= 0x04;                            // P1.2 TA1 option

 

  TACCR0 = 3277-1;                           // PWM Period

  TACCTL1 = OUTMOD_7;                       // TACCR1 reset/set

  TACCR1 = 1639;                             // TACCR1 PWM duty cycle

 

  TACTL = TASSEL_2 + MC_1;                  // SMCLK, up mode

 

 

}

if the above program is right, i just need to configure the rest of the pins as follows?

ENABLE- low

SLEEP- high

USM0,USM1- high (8th microstep)

RESET- high

SRn- high

HOMEn-high

DIR- low

 

  • Hi AMJ,

    A quick glance at this code looks like it could work. Do note that to change the speed of the stepper, you will need to change the STEP frequency. Hence, when you change your TACCR0 register, you may need to change TACCR1 register as well. Of course, only as TACCR0 approaches TACCR1. So you may prefer an instruction like:

    TACCR1 = TACCR0 > 1;

    The technique I use is different, in case you want to consider it. I do not set the timer to PWM, but to generate a frequency. I set the output compare output to toggle (OUTMOD4 if I recall. Then all I have to update is the TACCRx register with a value. The frequency is of course half of this as I need to toggles to generate 1 STEP, but this is perfectly fine. Actually, it works better as it is already easy for the timer to go fast, with the great majority of speeds pretty much useless as the motor can not STEP that fast anyway. You can always scale the timer down too, of course.

    Everything else in your code looks like it should work.

    Best regards,

    JIQ

  • hi

    thank u so much...i made a few additions to my code...

    #include <msp430fg4618.h>

    #include <in430.h>

     

     

    void main(void)

    {

      volatile unsigned int i;

     

      WDTCTL = WDTPW +WDTHOLD;                  // Stop WDT

     

    SCFQCTL = 0x82;                             //f= 2*32768*(4+1) approx equals 320kHz

    SCFI0 = 0x40; 

    FLL_CTL0 = 0x30;                           //DCO outputis divided, Xcap=10pf

    FLL_CTL1 = 0x20;                           //XT2 is OFF, MCLK=SMCLK=DCO

     

     

     

      // Wait for xtal to stabilize

      do

      {

      IFG1 &= ~OFIFG;                           // Clear OSCFault flag

      for (i = 0x47FF; i > 0; i--);             // Time for flag to set

      }

      while ((IFG1 & OFIFG));                   // OSCFault flag still set?

     

      P2DIR |= 0xFF;                              // P2.7--> HOME, P2.6-->SRn, P2.5- ->RESET,P2.4-->USM1,P2.3 --> USM0, P2.2 --> DIR, P2.1--> SLEEP, P2.0 --> ENABLE

      P2OUT |= 0xFD;                           // all are high except DIR-->LOW and ENABLE-->HIGH

      P2OUT &= ~0x01;                       // ENABLE--> LOW

      P1DIR |= 0x04;                            // P1.2 output for STEP

      P1SEL |= 0x04;                            // P1.2 TA1 option

     

      TACCR0 = 3277-1;                           // PWM Period= 10msec

      TACCTL1 = OUTMOD_7;                       // TACCR1 reset/set

      TACCR1 = 1639;                             // TACCR1 PWM duty cycle =50 %

     

      TACTL = TASSEL_2 + MC_1;                  // SMCLK, up mode

    }

     i calculated pps =(no. of steps per rev *rpm)/60

    if n= 48 and rpm=120, pps= 96.

    hence Twait = 10msec

    hence i chose my PWM period as 10msec

    Now Is the above code fine?

  • please help me...is the above code fine?

     

    also, i'm giving PWM sognals to STEP pin of DRV8811....can i give it directly or do i need a circuit interfacing the two?

  • Hi AMJ,

    I think the best way for you to validate this code is to actually run it and see what output you get. When I write code, I am always under the impression that the code is pretty much 100% correct, but it is only a matter of downloading it into my micro, with the superbly accessible and economical debugging tools, to realize where the bugs may lie.

    If I read your code, I will not be able to determine what nuisances lurke in its lines. My brain is not an MSP430 microcontroller, you know. Let the MCU have the last word. And since this is a 16 bit micro, that should be extremely feasible ;-)

    I do want to point out the STEP input will not respond correctly to a PWM signal. It has to be a frequency signal. If you use a PWM, the motor will always move at the same speed. As you change the duty cycle, nothing will happen, other than possibly going to the point in which the pulse is so short in time (low duty cycle values), the device completely ignores it.

    Best regards,

    Jose Quinones