• No results found

Intelligent Stepper Motor Driver With DRV8824

N/A
N/A
Protected

Academic year: 2021

Share "Intelligent Stepper Motor Driver With DRV8824"

Copied!
22
0
0

Loading.... (view fulltext now)

Full text

(1)

SLVA488 

SLVA488  – –October 2011October 2011

Intelligent Stepper Motor Driver with DRV8811/18/24/25 

Intelligent Stepper Motor Driver with DRV8811/18/24/25 

Jose Qui 

Jose Qui ññones ones 

...

...

...

...

...

...

...

...

...

...

...

...

...

...

  Analog Motor Drives   Analog Motor Drives 

ABSTRACT ABSTRACT Th

This is dodocucumement nt is is prprovovideided d as as a a susupppplelemement nt to to ththe e DRDRV8V881811/1/1818/2/21/1/2424/2/25 5 dadata ta shsheeeetsts. . It It dedetatails ils aa technique to improve real time control of an internal indexer bipolar stepper motor driver such as the technique to improve real time control of an internal indexer bipolar stepper motor driver such as the DRV8811, DRV8818, DRV8821, DRV8824 or DRV8825 while obtaining programmable acceleration and DRV8811, DRV8818, DRV8821, DRV8824 or DRV8825 while obtaining programmable acceleration and dec

decelereleratiation on proprofilfiles, es, spespeed ed concontrotrol l and and pospositiition on concontrotrol l by by the the utiutilizlizatiation on of of a a conconvenventiotional nal MSPMSP430430 microcontroller and any of the aforementioned power stages.

microcontroller and any of the aforementioned power stages.

Contents Contents 1

1 InIntrtrododucuctition on anand d PrProboblelem m StStatatememenentt

...

...

...

...

...

...

...

22 2

2 StStepeppeper r MoMototor r CoContntrorol l HiHigh gh LeLevevel l FuFuncnctitiononss

...

...

...

...

...

...

....

33 2.1

2.1 STEP STEP ActuatActuation: ion: AcceleAcceleratioration, n, Speed Speed ContrControl ol and and DeceleDeceleratioration Pn Profilrofileses

...

...

...

...

33 2.

2.2 2 AcAcceceleleraratiting ng ththe e MoMototorr

...

...

...

...

...

...

...

...

44 2.

2.3 3 StStepeppeper r SpSpeeeedd

...

...

...

...

...

...

...

...

..

88 2.

2.4 4 DeDececeleleraratiting ng ththe e MoMototorr

...

...

...

...

...

...

...

...

1010 2

2.5 .5 SpSpeeeed d ChChanangege

...

...

...

...

...

...

...

...

1010 2.6

2.6 PosPositiition on ConControtrol: l: NumNumber ber Of Of SteStepsps

...

...

...

...

...

...

....

1111 2.

2.7 7 HoHomiming ng ththe e StStepeppeperr

...

...

...

...

...

...

...

...

1212 3

3 II22C Protocol and Communications EngineC Protocol and Communications Engine

...

...

...

...

...

...

....

1313 3

3.1 .1 GPGPIIO O COCONFNFIIGG

...

...

...

...

...

...

...

...

1414 3.

3.2 2 STSTEPEPPEPER R COCONFNFIGIG

...

...

...

...

...

...

...

...

1414 3

3..3 3 GGPPIIO O OOUUTT

...

...

...

...

...

...

...

...

...

1515 3.

3.4 4 CuCurrrrenent t DuDuty ty CyCyclclee

...

...

...

...

...

...

...

...

1515 3.

3.5 5 STSTARART T STSTEPEPPEPERR

...

...

...

...

...

...

...

...

1515 4

(2)

Digital Signal Digital Signal Processor or  Processor or  Microcontroller 

Microcontroller  Dual H Bridge Power StageDual H Bridge Power Stage

ENABLE_A ENABLE_A PHASE_A PHASE_A VREF_A VREF_A ENABLE_B ENABLE_B PHASE_B PHASE_B VREF_B VREF_B GPIO GPIO GPIO GPIO DAC DAC GPIO GPIO GPIO GPIO DAC DAC L L O O G G II C C G G L L O O G G II C C G G OUTA OUTA OUTA OUTA OUTB OUTB OUTB OUTB STEP STEP DIR DIR ENABLE ENABLE DRV8811 DRV8811 DRV8818 DRV8818 DRV8821 DRV8821 DRV8824 DRV8824 DRV8825 DRV8825 OUTA OUTA OUTB OUTB ((AA)) ((BB)) USMx USMx STEP STEP DIR DIR ENABLE ENABLE USMx USMx

1

1

Int

Introd

roduc

uctio

tion

n and

and Pr

Probl

oblem

em Sta

Statem

tement

ent

Driving a stepper motor can be a daunting task. Whereas, providing a voltage at the terminals of a DC Driving a stepper motor can be a daunting task. Whereas, providing a voltage at the terminals of a DC motor causes immediate rotation, on a stepper motor, careful magnetic field commutation must be applied motor causes immediate rotation, on a stepper motor, careful magnetic field commutation must be applied in order to obtain the same behavior. In the not so distant past, said electromagnetic commutation was in order to obtain the same behavior. In the not so distant past, said electromagnetic commutation was achieved by coding powerful microprocessors to coordinate the phase and current information

achieved by coding powerful microprocessors to coordinate the phase and current information administered into the power stage.

administered into the power stage. With the

With the advenadvent t of high of high integrintegration on ation on monolimonolithic integratthic integrated circuits, it ed circuits, it becambecame e simplesimpler to r to take intotake into

hardware all the blocks once generated through code. A stand alone IC could now control even the most hardware all the blocks once generated through code. A stand alone IC could now control even the most intricate subjects such as phase commutation and microstepping without the need of precious

intricate subjects such as phase commutation and microstepping without the need of precious microcontroller resources.

microcontroller resources.

Figure 1. Stepper Control Logic and Power Stage Figure 1. Stepper Control Logic and Power Stage Figure 1

Figure 1 shows the level of integration which can be obtained when the code inside of a microcontroller, shows the level of integration which can be obtained when the code inside of a microcontroller, and in charge of causing stepper commutation, is concatenated along with the power stage into a single and in charge of causing stepper commutation, is concatenated along with the power stage into a single chip solution. Notice that in both scenarios a series of simple control signals exist. A STEP pulse is used chip solution. Notice that in both scenarios a series of simple control signals exist. A STEP pulse is used to generate steps or microsteps; a DIR signal defines the direction of rotation; the ENABLE line

to generate steps or microsteps; a DIR signal defines the direction of rotation; the ENABLE line determines whether the power stage is enabled or not; and the User Mode bits are used to select a determines whether the power stage is enabled or not; and the User Mode bits are used to select a degree of microstepping.

degree of microstepping. Contr

Controlling a olling a steppstepper, however, can still er, however, can still benefbenefit from it from the usage of the usage of a a micromicrocontrcontroller. Tasks such as oller. Tasks such as speedspeed and position control, acceleration and deceleration, homing, etc. still require accuracy and precision which and position control, acceleration and deceleration, homing, etc. still require accuracy and precision which a microcontroller can easily supply. The question we must ask is: Will the application processing unit be a microcontroller can easily supply. The question we must ask is: Will the application processing unit be asked to compute all the parameters related to stepper motion, or will a smaller and more cost economical asked to compute all the parameters related to stepper motion, or will a smaller and more cost economical microcontroller be used to tackle the tasks at hand?

microcontroller be used to tackle the tasks at hand?

Using a smaller microcontroller to perform the aforementioned tasks is advantageous if numerous Using a smaller microcontroller to perform the aforementioned tasks is advantageous if numerous stepp

steppers are ers are to be to be contrcontrolled. In olled. In this fashion, the application procesthis fashion, the application processor can sor can utilize its real utilize its real time resourctime resources toes to properly coordinate application intensive aspects, while the small microcontrollers deal with the intricacies properly coordinate application intensive aspects, while the small microcontrollers deal with the intricacies of controlling the stepper motors.

of controlling the stepper motors. This applicatio

This application n note details an note details an implemimplementatentation ion using an using an MSP430MSP430F2132 microconF2132 microcontrolletroller r and aand a

DRV8824/25 device which has an internal indexer bipolar stepper microstepping power stage. Combined, DRV8824/25 device which has an internal indexer bipolar stepper microstepping power stage. Combined, they form a module capable of receiving commands from a master controller through an I

they form a module capable of receiving commands from a master controller through an I22C bus, andC bus, and

which will then undertake all the actions to control the stepper motor both in speed and position. In order which will then undertake all the actions to control the stepper motor both in speed and position. In order to best utilize the available resources, a series of GPIO terminals were added, which will provide extra to best utilize the available resources, a series of GPIO terminals were added, which will provide extra functionality to the main processor.

(3)

MSP430F2132 DRV8811 DRV8818 DRV8821 DRV8824 DRV8828 STEP DIR nENABLE DA CL HOME       G        P       I       O  ADDR0 ADDR1       I       2       C  nSLEEP OUTA OUTB  VREF

Figure 2. Intelligent Stepper Controller Block Diagram

2

Stepper Motor Control High Level Functions

2.1

STEP Actuation: Acceleration, Speed Control and Deceleration Profiles 

Stepper motors offer a means to achieve speed control without the usage of closed loop mechanisms such as shaft encoders or resolvers. On a microstepping internal indexer driver, this open loop control is obtained by modulating the frequency at the STEP input. Each pulse at the STEP input, becomes a mechanical step motion at the stepper motor. Hence, it is safe to say that since we know what frequency we are applying at the STEP input, we then know the actual step rate the stepper motor is moving at. This will hold true as long as the right parametric values, such as current, voltage and torque, are maintained within reasonable levels throughout the application’s operation.

Unfortunately, we cannot just apply any frequency or step rate to any given stepper motor. Due to the mechanisms behind the revolving magnetic field at the stator and the permanent magnet at the rotor, a stepper motor can only start moving if the requested speed is smaller than a parameter given by the motor’s manufacturer and referred to as the starting frequency (denominated FS). For example, if the FS for a particular stepper motor is 300 steps per second (SPS), it will most likely not be possible to start the motor at a frequency of 400 SPS.

(4)

Time (s)      M    o       t     o     r      S     p       e      e       d       (        S       P      S       )   Desired Speed (SPS) Starting Speed (SPS) Stopping Speed (SPS)  Acceleration Rate (SPSPS) Deceleration Rate (SPSPS)

Since the application may require speed rates larger than the FS, it is then very important to subject the motor commutation through an acceleration profile which starts at a speed rate lower than its maximum FS and increases speed accordingly until reaching the desired speed.

Figure 3. Typical Stepper Acceleration and Deceleration Profile Figure 3 shows a typical acceleration and deceleration profile where:

Starting Speed is a STEP frequency lower than the motor’s rated FS at which the motor will start moving. Measured in steps per second (SPS), where STEPS refers to full steps.

Acceleration Rate is a factor of how much the STEP frequency will be increased on a per second basis. Measured in steps per second per second (SPSPS).

Desired Speed is the STEP frequency the application requires the motor to move at. It marks the STEP frequency at which the acceleration profile concludes. Measured in steps per second.

Deceleration Speed is a factor of how much the STEP frequency will be decreased on a per second basis. Measured in steps per second per second (SPSPS).

Stopping Speed is the STEP frequency at which the deceleration profile and the motor will be stopped. In this application note, stopping speed is taken to be the same as the starting speed. Measured in steps per second.

2.2

Accelerating the Motor 

The start stepper command starts by issuing steps at a starting frequency denoted by the StartingSpeed variable. A timer must be used to generate STEP pulses at such frequency. On this application note, Timer A0.2 was used to set the STEP signal and Timer A0.0 was used to clear the same signal. The pulse width is 32 clock pulses wide which translates to 2 µs. Since the DRV8825 requires STEP pulses at least 1-µs wide, this implementation results in a legal pulse generation.

(5)

ep requency s er o Pulse Width

Must be larger than 1 us

      T       A       0        C        C        R       2       S     e       t     s        T       A       0        C        C        R       0        C        l    e      a      r     s        T       A       0        C        C        R       2       S     e       t     s        T       A       0        C        C        R       0        C        l    e      a      r     s 

void AccelTimeCompute(unsigned int AccelDecelRate) {  if (AccelDecelRate <= 4000) {   AccelerationTime = 4000/AccelDecelRate;  AccelerationIncrease = 1;  } else {   AccelerationTime = 1;  AccelerationIncrease = AccelDecelRate/4000;  } tmpAccelerationTime = AccelerationTime;  }

Figure 4. Timer A0 Used to Generate STEP Pulses

The interrupt subroutine for Timer A0.2 is in charge of programming the Timer A0.0 hardware reset, as well as programming itself in order to schedule the next step generation.

A second timer function is needed to generate the acceleration portion of the speed control profile. The microcontroller selected for this application only had two available timers so as will be explained shortly, a trade off had to be made.

Timer A1.1 was used along with timer A1.0 to generate the PWM output which would be used to generate an analog to digital converter, by adding an RC filter, to drive the DRV8825’s VREF analog input pin. With this technique, it is then possible to control stepper current in real time.

Although all timer resources seem to be depleted, there is still an aspect of timer A1 we can utilize. If we code the PWM generator to count from decimal 0 to decimal 249, we will have 250 time units. At 16 MHz, each timer unit is equal to 62.5 ns with 250 of them accounting for 15.625  µs. By further dividing this result by 8, we can get a fairly useful time base of 125  µs, or 4000 timer ticks per second.

What this means is we can increase the stepper speed rate up to 4000 times per second. A simple mathematical equation can then be used to compute both the acceleration time interval and the

acceleration increment parameter. The code snippet below shows the equations used to compute both aspects of the acceleration parameter:

Figure 5. Function Computing Time Interval and Acceleration Increase Parameters for Acceleration or Deceleration Rate

(6)

Init H Bridges and Variables Timer A0.1 = Start Speed

Start Stepper? YES NO  Accel Time Complete? YES Timer A0.1

Count Accel Time Interval

NO

Compute Acceleration Rate and Acceleration Time

Start Acceleration Engine

Stepper Speed+= Accel Rate

START

Stepper Speed >= Desired Speed?

NO

Stepper Speed= Desired Speed Disable Acceleration Engine

END

Figure 6 shows the flowchart of the state machine in charge of coordinating the acceleration. As can be seen, the command to start the motor will configure all the parameters required for motion, including the call to the AccelTimeCompute function.

Figure 6. Stepper Speed Acceleration Flowchart

The actual speed modification takes place inside the AccelDecel function which gets called from within the main execution which is in turn enabled within the timer A1.0 interrupt service routine (ISR). It is important for the AccelDecel function not to be called from within inside the ISR as this impacts real time operation. Instead, inside the ISR the microcontroller sleep mode is disabled, which allows execution to resume from the main loop.

(7)

int main() { 

 //ALL INITIALIZATION OCCURS HERE 

 __bis_SR_register(GIE); // Enable all Interrupts while (1) {   _BIS_SR(CPUOFF); // Enter LPM0   AccelDecel();  }  } #pragma vector=TIMER1_A0_VECTOR   __interrupt void Timer1_A0(void)

{  TimerA0Count += 1; if (TimerA0Count == ATBCount) {  TimerA0Count = 0; if (tmpAccelerationTime == 0) {  tmpAccelerationTime = AccelerationTime;

 _BIC_SR_IRQ(CPUOFF); // Clear LPM0 - jumps to AccelDecel();  }

tmpAccelerationTime -= 1;  }

 }

Figure 7. Main Function Calls the AccelDecel Code Whenever Code Inside of an ISR Removes the Micro from Sleep Mode

(8)

void AccelDecel(void) {  switch (AccelerationState) {  case (NOACC): break; case (ACCEL):  ActualStepperSpeed += AccelerationIncrease; if (ActualStepperSpeed >= DesiredStepperSpeed) {   ActualStepperSpeed = DesiredStepperSpeed;  AccelerationState = NOACC;

TA1CCTL0 &= ~CCIE; //DISABLE 250 us coordinator interrupt on TA1.0   } SpeedCompute(ActualStepperSpeed); break; case (DECEL):  ActualStepperSpeed -= AccelerationIncrease; if (ActualStepperSpeed <= DesiredStepperSpeed) {   ActualStepperSpeed = DesiredStepperSpeed;  AccelerationState = NOACC;

TA1CCTL0 &= ~CCIE; //DISABLE 250 us coordinator interrupt on TA1.0   } SpeedCompute(ActualStepperSpeed); break; case (STOP):  ActualStepperSpeed -= AccelerationIncrease; if (ActualStepperSpeed <= StartStepperSpeed) {   ActualStepperSpeed = StartStepperSpeed;  AccelerationState = NOACC;

TA1CCTL0 &= ~CCIE; //DISABLE 250 us coordinator interrupt on TA1.0  ExecutedSteps = NumberOfSteps - 1;  } SpeedCompute(ActualStepperSpeed); break;  }  }

Figure 9. AccelDecel Function is State Machine Code in Charge of Modifying Stepper Speed According to Programmed Acceleration or Deceleration Profile

2.3

Stepper Speed 

Stepper speed is carefully controlled by using Timer A1.0 and A1.2 as detailed previously. How the timer is being clocked is important to understand, as the 16- bit timer by itself is not capable of reproducing all the possible speeds applications around this topology may try to run at. For example, while the Timer A1 is being clocked at 16 MHz, fast stepping rates are easily obtained, while slow speeds cannot be

(9)

bool SpeedCompute(unsigned int MotorSpeedInHz) {  if (MotorSpeedInHz < 31 ) {  return false;  } else if (MotorSpeedInHz < 61 ) {  ClockConfigure(8); StepperSpeedTMR = 2000000 / MotorSpeedInHz; return true;  } else if (MotorSpeedInHz < 123) {  ClockConfigure(4); StepperSpeedTMR = 4000000 / MotorSpeedInHz; return true;  } else if (MotorSpeedInHz < 245) {  ClockConfigure(2); StepperSpeedTMR = 8000000 / MotorSpeedInHz; return true;  } else {  ClockConfigure(1); StepperSpeedTMR = 16000000 / MotorSpeedInHz; return true;  }  }

As a result, it is imperative to modulate the clock speed by subdividing it. Luckily Timer A has a series of dividing factors which allow the timer clocking speed to be subdivided from 16 MHz down to as slow as 2 MHz.

The equation to compute how many clock cycles are needed to reproduce a particular stepping rate is:

# Clock Cycles = TIMER CLOCK FREQUENCY / STEP_RATE in Hz (1)

A quick analysis on the results provided by the previous equation showed the stepping rate segregations on a per clock cycle count basis. If for a given timer clock frequency the resulting number of clock cycles was larger than 65535 then a further subdivision factor would be needed to reduce the clock count from saturating the timer register.

The function SpeedCompute is in charge of transforming a stepping rate in Hz into clock count.

Depending on the speed, the timing source for Timer A1 is sub divided to slow down its incremental rate. If the requested stepping rate is less than 31, the function returns false in which case no rate is generated. Although it may be desirable to obtain stepping rates lower than 31 full steps, this can still be achieved by utilizing a faster speed and configuring the DRV8824/25 device to operate in 32 degrees of microstepping. For example, if the programmed DesiredSpeed is 32 SPS, and the DRV8824/25 is configured to operate in 32 degrees of microstepping, the stepper will move 1 full step per second.

Figure 10. SpeedCompute Transform the Stepping Rate in Hz into a Clock Count Timer A1.1 - Can Use to Generate Accurate Timing Information

(10)

void ClockConfigure(char Divider) {  int tempTA0CTL; tempTA0CTL = TA0CTL; switch (Divider) {  case 1:

tempTA0CTL &= ~( BIT7 + BIT6); break;

case 2:

tempTA0CTL &= ~( BIT7 + BIT6); tempTA0CTL |= TA0_ID_DIV2; break;

case 4:

tempTA0CTL &= ~( BIT7 + BIT6); tempTA0CTL |= TA0_ID_DIV4; break;

case 8:

tempTA0CTL &= ~( BIT7 + BIT6); tempTA0CTL |= TA0_ID_DIV8; break;

 }

TA0CTL = tempTA0CTL;  }

Figure 11. Function ClockConfigure is Called Within the SpeedCompute Function to Modify the Divider Affecting Timer A1 Clock Speed

The functions SpeedCompute and ClockConfigure are called to set the StartSpeed, to set the new stepper speed on a per acceleration click occurrence and then when the DesiredSpeed is met. Once the

programmed DesiredSpeed target is reached the stepper motor maintains said speed until a deceleration profile is commanded.

2.4

Decelerating the Motor 

The concept of a deceleration profile the motor is virtually identical to the acceleration profile implementation except that instead of increasing stepper speed, speed is decreased.

There are two instances in which a deceleration profile may be employed: during SpeedUpdate or during StepperStop commands. In this implementation, the stepper deceleration profile is finished either when the start speed is reached or when the programmed number of steps is executed.

Also, it was chosen for the deceleration rate to hold a different memory location such that a non symmetric acceleration/deceleration profile, such as the one portrayed in  Figure 3, could be employed.

The SpeedCompute and ClockConfigure are used in the same fashion as they were used during the acceleration portion of the motion control profile. However, the state machine, or the AccelDecel function, is configured to execute the DECEL portion of code.

2.5

Speed Change 

During run time, it is possible to change the speed and incur in further acceleration or deceleration as deemed by the application. When the command SpeedUpdate is issued, the firmware checks to see whether the new DesiredSpeed is larger or smaller than the ActualStepperSpeed. The result of this operation configures the Acceleration Deceleration engine accordingly.

(11)

2.6

Position Control: Number Of Steps 

The closed loop capabilities of a stepper are not limited to accurately controlling the speed. Since in essence the controller is counting the very same steps which are being generated, knowledge of step position is continuously being updated. Every time a step is executed, the variable StepPosition is updated according to step rotation direction. For example, if the motor is rotating clockwise (DIR = HI), the

StepPosition variable is incremented, whereas if the motor is rotating counterclockwise (DIR = LO), then the StepPosition variable is decremented.

NOTE: The notions of motor rotation as clockwise or counterclockwise are directly dependent to how the motor was wired and the motor itself.

The variable StepPosition can be read in real time to obtain information as to where the motor is at any given point in time.

On this application note, however, the controller is always operating in Position Control mode. The

variable NumberOfSteps is programmed to hold the entire number of steps which will be executed. Since this is a 32-bit variable, the total number of steps could be a significantly large number, in which case the motor would in essence be operating in free running mode. However, if the NumberOfSteps count is small, then the motor will stop once the total NumbeOfSteps have been executed.

The previous mechanism is achieved by counting how many steps have been executed and comparing this number to the NumberOfSteps command. This is taken care of on the Timer A0.2 ISR as shown in Figure 12.

Notice this ISR is in charge of a few tasks we have described earlier and which are of crucial importance to generating accurate stepping information. These tasks are:

1. Generation of the STEP pulse by configuring when the STEP clear takes place. Timer A0.0 is in charge of returning the STEP signal to LO.

2. Configuring the TIMERA0.2 to generate the next step according to the current step rate, or StepperSpeedTMR, which is the timer equivalent of the current rate in Hz.

3. Determining whether the current generated step is the last step to execute. This happens when ExecutedSteps is equal to NumberOfSteps.

4. If the current generated step is equal to StepsToStop value, then the engine is commanded to start a deceleration profile.

(12)

#pragma vector=TIMER0_A1_VECTOR   __interrupt void Timer0_A1(void)

{  switch (TA0IV) {  case TA0CCR1_CCIFG_SET: break; case TA0CCR2_CCIFG_SET:

TA0CCR0 = TA0CCR2 + StepPulseWidth; //2 us at 16 MHz 

TA0CCR2 += StepperSpeedTMR; ExecutedSteps += 1;

if (ExecutedSteps == NumberOfSteps) { 

TA0CCTL2 &= ~(CCIE + BIT5 + BIT6 + BIT7); //Disable Pulse Generation  }

else if (ExecutedSteps == StepsToStop) { 

 AccelTimeCompute(DecelerationRate);  AccelerationState = STOP;

TA1CCTL0 |= CCIE; //ENABLE 250 us coordinator interrupt on TA1.0 

 }

if (P3IN && DIR) {  StepPosition += 1;  } else {  StepPosition -=1;  }

ReadTable[0] = (StepPosition & 0xFF00) >> 8; ReadTable[1] = StepPosition & 0xFF;

break;

case TA0IFG_SET: break;

 }  }

Figure 12. Timer A0.2 ISR

2.7

Homing the Stepper 

The concept of preserving stepper position is in essence flawed if we do not know the system’s start position. This is true for any motor system in which the closed loop feedback is relative, versus absolute. As a result, it is important we start counting our steps from a known position. Said position is often

referred to as HOME.

The application note incorporates a HOME sensor input which is flexible enough to accommodate both sensor polarities (e.g. asserted HI or asserted LO). A typical HOME sensor implementation is to have an optical sensor and a flag at the stepper motor shaft. When the flag meets the optical sensor slit, then the stepper motor stops and this position is from now on referred to as HOME. Internally, the controller clears the StepPosition variable.

(13)

#pragma vector=PORT1_VECTOR   __interrupt void PORT1_Change(void)

if (P1IFG && HOMEIN) { 

P1IE = 0; P1IFG = 0;

TA0CCTL2 &= ~(CCIE + BIT5 + BIT6 + BIT7); StepPosition = 0;

 }  }

Since the motor can be started at any given position, the HOME sensor could be found to be at either state. Hence, initially, the state is to be considered unknown. The typical homing implementation calls for a transition from HI to LO or a transition from LO to HI as chosen by the application.

In order to easily capture the chosen transition, the HOME sensor was allocated to a GPIO pin with a Pin On Change Interrupt. Since the pin can be configured to raise the ISR flag either with a rising or a falling edge, we can capture on either edge. Whereas the typical polling function would require some sort of a state machine to filter out the wrong transition, this hardware interrupt works exceptionally well, rendering the amount of code to be considerably tiny.Figure 13 shows the ISR for the PORT1 Pin On Change Interrupt vector. The reader will notice this code is in charge of clearing the StepPosition variable, as well as stopping the motor.

Figure 13. Port 1 Pin On Change Interrupt Service Routine

3

I

2

C Protocol and Communications Engine

In order to program the device parameters and the stepper motion engine profiles, an I2C protocol was

chosen. The way it was designed, up to four controllers can be cascaded with only two communication lines and two address selector lines.

The I2C protocol is the typical three byte packet where the first byte is the slave address, the second byte

is the register address and the third byte is the data. There are 21 possible address register which can be accessed.

(14)

Number Of Steps

Number Of Steps

Number Of Steps1

Number Of Steps0

StepsToStop

StepsToStop

StepsToStop1

StepsToStop0

StartSpeed1

StartSpeed0

 Accel1

 Accel0

DesiredSpeed1

DesiredSpeed0

Decel1

Decel0

GPIO CONFIG

Stepper Config

GPIO OUT

Current Duty Cycle

Start Stepper 

0x00

0x01

0x02

0x03

0x04

0x05

0x06

0x07

0x08

0x09

0x0A

0x0B

0x0C

0x0D

0x0E

0x0F

0x10

0x11

0x12

0x13

0x14

ndex

PARAMETER TABLE

GPIO DIR 7

Bit 7 Bit 0

GPIO DIR 6 GPIO DIR 5 GPIO DIR 4 GPIO DIR 3 GPIO DIR 2 GPIO DIR 1 GPIO DIR 0

N/A

Bit 7 Bit 0

ENABLE MODE2 MODE1 MODE0 N/A N/A DIR

Figure 14. Parameters Table

The variables residing on addresses 0x00 to 0x0F have been discussed on previous sections. The other addresses are a combination of parameters as well as actions.

3.1

GPIO CONFIG 

Defines the GPIO direction, for the 8 GPIO pins 0 to 7, where a configuration of 0 denotes an input and a configuration of 1 denotes an output.

3.2

STEPPER CONFIG 

Configures control signals for the stepper power stage. These register bits are directly mapped to the Power Stage hardware pins, so changing the state of any of these bits immediately changes the respective pin at the power stage input.

(15)

GPIO 7

Bit 7 Bit0

GPIO 6 GPIO 5 GPIO 4 GPIO 3 GPIO 2 GPIO 1 GPIO 0

START ACCEL START STEPPER STOP STEPPER CHANGE SPEED HOME HI HOME LO 0x00 0x01 0x02 0x03 0x04 0x05

OPCODE

START STEPPER

3.3

GPIO OUT 

Those GPIO bits which were configured as outputs are configured when writing to this address. Note that writing to this address is equivalent to writing to the MSP430 PxOUT register so only bits which are

configured to be outputs on their respective PxDIR register, will react accordingly. Those pins which are configured as inputs will still behave as inputs.

3.4

Current Duty Cycle 

A register accepting a number from 0 to 249 which then becomes PWM output duty cycle. The current code does not check whether the written is equal or less than 249. Any number larger than 249 will yield a 100% duty cycle PWM.

3.5

START STEPPER 

This address is more a command than an actual register. A switch case statement decodes the data byte and an action is executed. Possible actions are:

Where:

START ACCEL starts the stepper motor through at the StartSpeed and ramps up until reaching DesiredSpeed. If no other command is received, motor stops once the NumberOfSteps have been executed.

START STEPPER starts the stepper at the StartSpeed. No acceleration occurs. If no other command is received, motor stops once the NumberOfSteps have been executed.

STOP STEPPER stops the stepper while ramping down through the deceleration profile. Motor stops as soon as the StartSpeed is reached or the NumberOfSteps have been executed.

CHANGE SPEED accelerates or decelerates the stepper depending on whether the actual speed is larger or lesser than the new DesiredSpeed. For this command to work, a new DesiredSpeed must be written while the motor is running.

HOME HI starts the motor at the StartSpeed and runs until a transition to HI is observed on the HOME sensor input, or when the NumberOfSteps have been executed.

HOME LO starts the motor at the StartSpeed and runs until a transition to LO is observed on the HOME sensor input, or when the NumberOfSteps have been executed.

The Start Stepper command will configure the stepping engine parameters such as NumberOfSteps, StepsToStop, StartStepperSpeed, DesiredStepperSpeed, AccelerationRate and DecelerationRate. It will then decode the action parameter and start the stepper motor according to the received command. The I2C communications are handled by the USCI RX and TX vector interrupts.

(16)

#pragma vector=USCIAB0TX_VECTOR //UCA_TRANSMIT on UART/SPI;

UCB_RECEIVE, UCB_TRANSMIT on I2C

 __interrupt void USCI_AB0_Transmit(void)

{

if (UCB0CTL1 & UCTR)

{

UCB0CTL1 &= ~UCTR;

IFG2 &= ~UCB0TXIFG;

}

else

{

SerialBuffer[SerialPointer] = UCB0RXBUF;

SerialPointer += 1;

if (SerialPointer == SERIAL_BUFFER_LENGTH)

{

SerialPointer = 0;

ParametersTable[ADDRESS] = PARAMETER;

switch(ADDRESS)

{

case GPIO_CONFIG:

char tempOut;

P1DIR = PARAMETER & 0xC0;

//Use 2 MSB's to configure the

GPIO Direction on pins P1.7 and P1.6

P2DIR = PARAMETER & 0x3F;

//Use 6 LSB's to configure the

GPIO direction on pins P2.0 to P2.5

case STEPPER_CONFIG_ADDR:

tempOut = P3OUT;

tempOut &= ~(nENABLE + MODE0 + MODE1 + MODE2 + DIR);

tempOut |= PARAMETER;

P3OUT = tempOut;

break;

case GPIO_OUT_ADDR:

P2OUT = PARAMETER;

tempOut = P1OUT;

tempOut &= ~(BIT7 + BIT6);

tempOut |= (PARAMETER & 0xC0);

P1OUT = tempOut;

break;

case CURRENT_DC_ADDR:

TA1CCR1 = PARAMETER;

break;

(17)

case START_STEPPER_ADDR:

NumberOfSteps = (ParametersTable[NUMBER_OF_STEPS3_ADDR] << 8) +

(ParametersTable[NUMBER_OF_STEPS2_ADDR]);

NumberOfSteps *= 65536;

NumberOfSteps += (ParametersTable[NUMBER_OF_STEPS1_ADDR] << 8) +

ParametersTable[NUMBER_OF_STEPS0_ADDR];

ExecutedSteps = 0;

StepsToStop = (ParametersTable[STEPS_TO_STOP3_ADDR] << 8) +

(ParametersTable[STEPS_TO_STOP2_ADDR]);

StepsToStop *= 65536;

StepsToStop += (ParametersTable[STEPS_TO_STOP1_ADDR] << 8) +

ParametersTable[STEPS_TO_STOP0_ADDR];

StartStepperSpeed = (ParametersTable[START_SPEED1_ADDR] << 8) +

ParametersTable[START_SPEED0_ADDR];

DesiredStepperSpeed = (ParametersTable[DESIRED_SPEED1_ADDR] << 8) +

ParametersTable[DESIRED_SPEED0_ADDR];

 AccelerationRate = (ParametersTable[ACCEL1_ADDR] << 8) +

ParametersTable[ACCEL0_ADDR];

DecelerationRate = (ParametersTable[DECEL1_ADDR] << 8) +

ParametersTable[DECEL0_ADDR];

(18)

switch (PARAMETER)

{

case START_ACCEL:

// Start stepper motor at Start speed and until

reaching desired speed

 AccelerationState = ACCEL;

 ActualStepperSpeed = StartStepperSpeed;

 AccelTimeCompute(AccelerationRate);

TA1CCTL0 |= CCIE;

//ENABLE 250 us coordinator interrupt on TA1.0

//WDTCTL = 0x5A00 + WDTTMSEL + WDTSSEL + BIT1 + BIT0;

break;

case START_STEPPER:

// Start stepper motor at start speed. Run at this

rate.

 AccelerationState = NOACC;

 ActualStepperSpeed = StartStepperSpeed;

break;

case STOP_STEPPER:

// Stop motor from current speed, through a

deceleration profile and until reaching Start Speed. Then stop and disable stepping

engine

 AccelTimeCompute(DecelerationRate);

 AccelerationState = STOP;

TA1CCTL0 |= CCIE;

//ENABLE 250 us coordinator interrupt on TA1.0

break;

case CHANGE_SPEED:

// Modify current speed up or down to Desired

Speed.

if (DesiredStepperSpeed >= ActualStepperSpeed)

{

 AccelTimeCompute(AccelerationRate);

 AccelerationState = ACCEL;

TA1CCTL0 |= CCIE;

//ENABLE 250 us coordinator interrupt on TA1.0

}

else

{

 AccelTimeCompute(DecelerationRate);

 AccelerationState = DECEL;

TA1CCTL0 |= CCIE;

//ENABLE 250 us coordinator interrupt on TA1.0

//WDTCTL = 0x5A00 + WDTTMSEL + WDTSSEL + BIT1 + BIT0;

}

break;

(19)

case HOME_HI:

// Move Stepper at Start Speed until the Home

Sensor becomes HI. Go through LO if already at HI

 AccelerationState = NOACC;

 ActualStepperSpeed = StartStepperSpeed;

P1IFG &= ~HOMEIN;

P1IES |= HOMEIN;

P1IE |= HOMEIN;

break;

case HOME_LO:

// Move Stepper at Start Speed until the Home

Sensor becomes LO. Go through HI if already at LO

 AccelerationState = NOACC;

 ActualStepperSpeed = StartStepperSpeed;

P1IFG &= ~HOMEIN;

P1IES &= ~HOMEIN;

P1IE |= HOMEIN;

break;

}

if (SpeedCompute(ActualStepperSpeed))

{

P3OUT &= ~(nENABLE);

P1OUT |= NSLEEP;

TA0CCR2 += StepperSpeed TMR;

TA0CCR0 = TACCR2 + StepPulseWidth;

//2 us at 16 MHz

TA0CCTL2 &= ~CCIFG;

TA0CCTL2 |= (CCIE + TA0_OUTMOD2_CONF);

}

break;

}

}

}

}

(20)

4

Application Schematic

(21)

1 1 2 2 3 3 4 4 5 5 6 6 D D C C B B  A A 1 2 3 4 5 6 7 8 9 10 1 1 1 2 1 3 1 4 J 1 J TAG GND V3p3 SBWTCK V3p3 GND 0.1uF C1 nSLEEP S TEP       1 TP1 VM VM       1 TP2G ND GND       1 TP3V 3P3 0.1uF C5 1 2 3 4 J 5 S tepper   AOUT1  A OUT2 C3 0.01uF CP1 C P2 0 .1uF C6 VCP 0 .1uF C4 VM  AOUT1  A OUT2 I SENA D ECAY n FAULT n SLEEP V 3P3OUT B OUT1 B OUT2 I SENB DIR n ENABLE S TEP MD0 MD1 MD2 .47uF C7 1 2 J 2 V M 1 2 3 4 J 4 S tepper   A OUT1  A OUT2 3.3K R7 . 2 R6 . 2 R5 100uF C 2 3.3K R 1 D1 V M VM BOUT1B OUT2 B OUT1 B OUT2       G        N       D       0  OUT 1 FB 2 NC 3 GND 4 EN 5 NC 6 NC 7 IN 8 U 3 TPS79801 10 uF C9 VM 61.9K R 11 39K R 12 V3p3 TST/SBW 1 DVCC 2 P2.5 3 DVSS 4 P2.7/ XOUT 5 P2.6/ XIN 6 RST 7 P2.0 8 P2.1 9 P2.2 1 0 P3.0 1 1 P3.1 1 2 P3.2 1 3 P3.3 1 4 P3.4/TXP3.5/RX 1516 P3.6/TA1.0 17 P3.7/TA1.1 18 P2.391 P2.402 P1.0/TACLK 21 P1.1/TA0.0 22 P1.2/TA0.1 23 P1.3/TA0.2 24 P1.4/TCK 25 P1.5/TMS 26 P1.6TCLK 27 P1.7/TDI 28 U1 MSP430F2132 CP1 1 CP2 2 VCP 3 VMA 4  AOUT1 5 ISENA 6  AOUT2 7 BOUT2 8 ISENB 9 BOUT1 1 0 VMB 1 1 VREF 1 2 VREF 1 3 GND 1 4 V3P3OUTnRESET51 1 6 nSLEEP71 nFAULTDECAY81 1 9 DIR02 nENABLE12 STEPNC 22 2 3 MODE042 MODE152 MODE262 nHOME72 GND82       G        N       D       0  U2 D RV8825 M D0 D1 M M D2 G PIO0 G PIO1 G PIO2PIO3 G G PIO4 G PIO5 D IR S DA S CL V REF_PWM n ENABLE H OME S BW_  TDOI SBWTCK SBW_TDOI GPIO7 GPIO6 330 R2 V3p3 V3p3 1 2 J 6 I 2C SDA S CL 1 2 3 4 5 6 7 8 9 10 J 9 G PIO V3p3 GPIO0 G PIO1 G PIO2 G PIO3 G PIO4 G PIO5 G PIO6 G PIO7 VREF_PWM 0.01uF C8 5.1K R8 3 .3K R3 1 2 3 J 3 H OME V3p3 HOME  A DR0  A DR1 1 2Y1 1 2 J MP1  A DR0  A DR0DR1 A 3.3K R9 V3p3 1 2 J MP2  A DR0 3.3K R10 V3p3 3.3K R4 nFAULT TL1 DRV8825Combo 3.3K R13 21

SLVA488 – October 2011 Intelligent Stepper Motor Driver with DRV8811/18/24/25 

Submit Documentation Feedback 

Copyright ©  2011, Texas Instruments Incorporated

IMPORTANT NOTICE

Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements, and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should obtain the latest relevant information before placing orders and should verify that such information is current and complete. All products are sold subject to TI’s terms and conditions of sale supplied at the time of order acknowledgment.

TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TI’s standard

warranty. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where mandated by government requirements, testing of all parameters of each product is not necessarily performed.

TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products and

applications using TI components. To minimize the risks associated with customer products and applications, customers should provide adequate design and operating safeguards.

TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right, or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information published by TI regarding third-party products or services does not constitute a license from TI to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property of the third party, or a license from TI under the patents or other intellectual property of TI.

Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied by all associated warranties, conditions, limitations, and notices. Reproduction of this information with alteration is an unfair and deceptive business practice. TI is not responsible or liable for such altered documentation. Information of third parties may be subject to additional restrictions.

(22)

Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements, and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should obtain the latest relevant information before placing orders and should verify that such information is current and complete. All products are sold subject to TI’s terms and conditions of sale supplied at the time of order acknowledgment.

TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TI’s standard

warranty. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where mandated by government requirements, testing of all parameters of each product is not necessarily performed.

TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products and

applications using TI components. To minimize the risks associated with customer products and applications, customers should provide adequate design and operating safeguards.

TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right, or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information published by TI regarding third-party products or services does not constitute a license from TI to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property of the third party, or a license from TI under the patents or other intellectual property of TI.

Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied by all associated warranties, conditions, limitations, and notices. Reproduction of this information with alteration is an unfair and deceptive business practice. TI is not responsible or liable for such altered documentation. Information of third parties may be subject to additional restrictions.

Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice. TI is not responsible or liable for any such statements.

TI products are not authorized for use in safety-critical applications (such as life support) where a failure of the TI product would reasonably be expected to cause severe personal injury or death, unless officers of the parties have executed an agreement specifically governing such use. Buyers represent that they have all necessary expertise in the safety and regulatory ramifications of their applications, and acknowledge and agree that they are solely responsible for all legal, regulatory and safety-related requirements concerning their products and any use of TI products in such safety-critical applications, notwithstanding any applications-related information or support that may be provided by TI. Further, Buyers must fully indemnify TI and its representatives against any damages arising out of the use of TI products in such safety-critical applications.

TI products are neither designed nor intended for use in military/aerospace applications or environments unless the TI products are specifically designated by TI as military-grade or "enhanced plastic." Only products designated by TI as military-grade meet military

specifications. Buyers acknowledge and agree that any such use of TI products which TI has not designated as military-grade is solely at the Buyer's risk, and that they are solely responsible for compliance with all legal and regulatory requirements in connection with such use.

TI products are neither designed nor intended for use in automotive applications or environments unless the specific TI products are designated by TI as compliant with ISO/TS 16949 requirements. Buyers acknowledge and agree that, if they use any non-designated products in automotive applications, TI will not be responsible for any failure to meet such requirements.

Following are URLs where you can obtain information on other Texas Instruments products and application solutions:

Products Applications

Audio   www.ti.com/audio Communications and Telecom   www.ti.com/communications Amplifiers   amplifier.ti.com Computers and Peripherals   www.ti.com/computers Data Converters   dataconverter.ti.com Consumer Electronics   www.ti.com/consumer-apps DLP® Products   www.dlp.com Energy and Lighting   www.ti.com/energy

DSP   dsp.ti.com   Industrial   www.ti.com/industrial Clocks and Timers   www.ti.com/clocks   Medical   www.ti.com/medical Interface   interface.ti.com   Security   www.ti.com/security

Logic   logic.ti.com Space, Avionics and Defense   www.ti.com/space-avionics-defense Power Mgmt   power.ti.com Transportation and Automotive   www.ti.com/automotive

Microcontrollers   microcontroller.ti.com Video and Imaging   www.ti.com/video RFID   www.ti-rfid.com

OMAP Mobile Processors   www.ti.com/omap

Wireless Connectivity   www.ti.com/wirelessconnectivity

TI E2E Community Home Page   e2e.ti.com Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265

References

Related documents

At the end of '99, the standards for reservist training statewide jumped to 650 hours but Blanas could have grandfathered Jack Sellers and other major cronies the way Sheriff

Knot tensile strength retention 14 days post implantation 60-70%. 18 days post implantation 50% 21 days post

Configure Xfire for Non-Steam Stuttering of Duty Modern Publishing 2 New PCS Centennial Products Siemens SL55 Sauce Case High Quality Obtuse Design Beautiful Attractive by OEM

Echolocation: paired fm-echolocation clicks between 7-60 kHz (recordings from Sinai). Distribution in Egypt: The Egyptian fruit bat is widely distributed in the Nile valley,

My searches included using keywords: school based mental health, emotional disorder, behavioral disorder, emotional and behavioral disorder, elementary aged children,

e ff ects of FSH on early follicle populations in the absence of luteinizing hormone (LH) activity, we examined mature hypogonadal ( hpg ), gonadotrophin-deficient mice

Specifically, the risk is considered as the area of the distribution of the arrival time fell after the latest time of the time window, and the mean of the arrival time is

Key words: Ahtna Athabascans, Community Subsistence Harvest, subsistence hunting, GMU 13 moose, Alaska Board o f Game, Copper River Basin, natural resource management,