Intelligent Stepper Motor Driver With DRV8824
Short Description
Descripción: design stepper motor driver...
Description
Application Report SLVA488 – – October 2011
Intelligent Stepper Motor Driver with DRV8811/18/24/25 Jose Qui ñones
............................. ............... ............................. ............................. ............................ ............................. ............................. .............. Analog Motor Drives ABSTRACT
This This docu docume ment nt is prov provide ided d as a supp supple leme ment nt to the the DR DRV8 V881 811/ 1/18 18/2 /21/ 1/24 24/2 /25 5 data data shee sheets ts.. It deta details ils a 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 deceler decelerati ation on profil profiles, es, speed speed contro controll and positi position on contro controll by the utiliz utilizati ation on of a conven conventio tional nal MSP430 MSP430 microcontroller and any of the aforementioned power stages.
1 2
3
4
Contents Intr Introd oduc ucti tion on and and Prob Proble lem m Stat Statem emen entt ............................. ........................................... ............................. ............................. ........................... ............. 2 Step Steppe perr Moto Motorr Cont Contro roll High High Leve Levell Func Functi tion ons s ............................ ........................................... ............................. ............................. ................... .... 3 2.1 STEP Actuation: Actuation: Acceleratio Acceleration, n, Speed Control Control and Deceleratio Deceleration n Profil Profiles es ........................... .................................. ....... 3 2.2 2.2 Acce Accele lera rati ting ng the the Moto Motorr ........................... .......................................... ............................. ............................. ............................. ..................... ....... 4 2.3 2.3 Step Steppe perr Spee Speed d ........................... .......................................... ............................. ............................ ............................. ............................. ................ .. 8 2.4 2.4 Dece Decele lera rati ting ng the the Moto Motorr ............................ ........................................... ............................. ............................. ............................. ................... ..... 10 2.5 Spee Speed d Chan Change ge ............................ ........................................... ............................. ............................. ............................. ............................ .............. 10 2.6 Positi Position on Con Contro trol: l: Num Number ber Of Steps Steps ............................. ........................................... ............................. ............................. .................. .... 11 2.7 2.7 Homi Homing ng the the Step Steppe perr ........................... ......................................... ............................. ............................. ............................. ........................ ......... 12 2 ............................................ ............................. ............................. ................... .... 13 I C Protocol and Communications Engine ............................. ........................................... ............................. ............................. ............................. ............................ .............. 14 3.1 GPI GPIO CONF CONFIIG ............................ ............................................ ............................. ............................ ............................. ...................... ....... 14 3.2 3.2 STEP STEPPE PER R CONF CONFIG IG ............................. .......................................... ............................. ............................. ............................. ............................. .................... ..... 15 3.3 GPIO OUT ........................... ........................................... ............................. ............................. ............................. ....................... ......... 15 3.4 3.4 Curr Curren entt Duty Duty Cycl Cycle e ............................ .......................................... ............................ ............................. ............................. ......................... ........... 15 3.5 3.5 STAR START T STEP STEPPE PER R ............................ ........................................... ............................. ............................. ............................. ............................ .............. 20 Appl Applic icat atio ion n Sche Schema mati tic c ............................
SLVA488 – October 2011 Submit Documentation Feedback
Intelligent Stepper Motor Driver with DRV8811/18/24/25 Copyright © 2011, Texas Instruments Incorporated
1
Introduction and Problem Statement
1
www.ti.com
Introd Introduc uctio tion n and Probl Problem em Statem Statement ent 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 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 administered into the power stage. With the advent advent of high integration integration on monolithic monolithic integrated integrated circuits, it became became simpler simpler to take into 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 microcontroller resources.
GPIO STEP
GPIO
DIR
DAC
ENABLE USMx
Digital Signal Processor or Microcontroller GPIO GPIO DAC
L O G I C
ENABLE_A PHASE_A
OUTA
G
VREF_A
STEP OUTA DIR
ENABLE_B
Dual H Bridge Power Stage L O G I C
PHASE_B VREF_B
ENABLE USMx
OUTB
DRV8811 DRV8818 DRV8821 DRV8824 DRV8825
OUTA
OUTB
OUTB
G
(A)
(B)
Figure 1. Stepper Control Logic and Power Stage Figure 1 shows 1 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 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 determines whether the power stage is enabled or not; and the User Mode bits are used to select a degree of microstepping. Controlling Controlling a stepper, stepper, however, can still benefit benefit from the usage of a microcontr microcontroller. oller. Tasks such as speed 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 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? Using a smaller microcontroller to perform the aforementioned tasks is advantageous if numerous steppers steppers are to be controlled. controlled. In this fashion, the application processor processor can utilize its real time resources resources to properly coordinate application intensive aspects, while the small microcontrollers deal with the intricacies of controlling the stepper motors. This application application note details an implementat implementation ion using an MSP430F2132 MSP430F2132 microcontrolle microcontrollerr and a 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 2C bus, and 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 functionality to the main processor. Figure processor. Figure 2 shows 2 shows a block diagram of the proposed implementatio implementation. n.
2
Intelligent Stepper Motor Driver with DRV8811/18/24/25
Copyright © 2011, Texas Instruments Incorporated
SLVA488 – October 2011 Submit Documentation Feedback
Stepper Motor Control High Level Functions
www.ti.com
DA
STEP
CL C 2 I
ADDR0
DIR
ADDR1 nENABLE
HOME
nSLEEP
VREF MSP430F2132
DRV8811
OUTA
DRV8818 DRV8821 DRV8824
O I P G
DRV8828
OUTB
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.
SLVA488 – October 2011 Submit Documentation Feedback
Intelligent Stepper Motor Driver with DRV8811/18/24/25 Copyright © 2011, Texas Instruments Incorporated
3
Stepper Motor Control High Level Functions
www.ti.com
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. ) S P S ( d e e p S r o t o M
Desired Speed (SPS) Stopping Speed (SPS)
Acceleration Rate (SPSPS) Starting Speed (SPS)
Deceleration Rate (SPSPS) Time (s)
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.
4
Intelligent Stepper Motor Driver with DRV8811/18/24/25
Copyright © 2011, Texas Instruments Incorporated
SLVA488 – October 2011 Submit Documentation Feedback
Stepper Motor Control High Level Functions
www.ti.com
ep requency s
er o
Pulse Width Must be larger than 1 us
s t e S 2 R C C 0 A T
s r a e l C 0 R C C 0 A T
s t e S 2 R C C 0 A T
s r a e l C 0 R C C 0 A T
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: void AccelTimeCompute(unsigned int AccelDecelRate) { if (AccelDecelRate = Desired Speed?
Stepper Speed= Desired Speed Disable Acceleration Engine
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.
6
Intelligent Stepper Motor Driver with DRV8811/18/24/25
Copyright © 2011, Texas Instruments Incorporated
SLVA488 – October 2011 Submit Documentation Feedback
Stepper Motor Control High Level Functions
www.ti.com
int main() { //ALL INITIALIZATION OCCURS HERE __bis_SR_register(GIE); while (1) { _BIS_SR(CPUOFF); AccelDecel(); } }
// Enable all Interrupts
// Enter LPM0
Figure 7. Main Function Calls the AccelDecel Code Whenever Code Inside of an ISR Removes the Micro from Sleep Mode
#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 8. Timer A1.0 ISR Disables Sleep Mode Once an Acceleration Tick is to be Executed
SLVA488 – October 2011 Submit Documentation Feedback
Intelligent Stepper Motor Driver with DRV8811/18/24/25 Copyright © 2011, Texas Instruments Incorporated
7
Stepper Motor Control High Level Functions
www.ti.com
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 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.
12
Intelligent Stepper Motor Driver with DRV8811/18/24/25
Copyright © 2011, Texas Instruments Incorporated
SLVA488 – October 2011 Submit Documentation Feedback
I 2 C Protocol and Communications Engine
www.ti.com
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. #pragma vector=PORT1_VECTOR __interrupt void PORT1_Change(void) { if (P1IFG && HOMEIN) { P1IE = 0; P1IFG = 0; TA0CCTL2 &= ~(CCIE + BIT5 + BIT6 + BIT7); StepPosition = 0; } }
Figure 13. Port 1 Pin On Change Interrupt Service Routine
3
I2C Protocol and Communications Engine In order to program the device parameters and the stepper motion engine profiles, an I 2C 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.
SLVA488 – October 2011 Submit Documentation Feedback
Intelligent Stepper Motor Driver with DRV8811/18/24/25 Copyright © 2011, Texas Instruments Incorporated
13
I 2 C Protocol and Communications Engine
www.ti.com
ndex
PARAMETER TABLE
0x00
Number Of Steps
0x01
Number Of Steps
0x02
Number Of Steps1
0x03
Number Of Steps0
0x04
StepsToStop
0x05
StepsToStop
0x06
StepsToStop1
0x07
StepsToStop0
0x08
StartSpeed1
0x09
StartSpeed0
0x0A
Accel1
0x0B
Accel0
0x0C
DesiredSpeed1
0x0D
DesiredSpeed0
0x0E
Decel1
0x0F
Decel0
0x10
GPIO CONFIG
0x11
Stepper Config
0x12
GPIO OUT
0x13
Current Duty Cycle
0x14
Start Stepper 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. Bit 7 GPIO DIR 7
3.2
Bit 0 GPIO DIR 6
GPIO DIR 5
GPIO DIR 4
GPIO DIR 3
GPIO DIR 2
GPIO DIR 1
GPIO DIR 0
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. Bit 7 N/A
14
Bit 0 ENABLE
MODE2
MODE1
Intelligent Stepper Motor Driver with DRV8811/18/24/25
MODE0
N/A
Copyright © 2011, Texas Instruments Incorporated
N/A
DIR
SLVA488 – October 2011 Submit Documentation Feedback
I 2 C Protocol and Communications Engine
www.ti.com
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. Bit 7 GPIO 7
3.4
Bit 0 GPIO 6
GPIO 5
GPIO 4
GPIO 3
GPIO 2
GPIO 1
GPIO 0
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:
OPCODE
START STEPPER
0x00
START ACCEL
0x01
START STEPPER
0x02
STOP STEPPER
0x03
CHANGE SPEED
0x04
HOME HI
0x05
HOME LO
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.
SLVA488 – October 2011 Submit Documentation Feedback
Intelligent Stepper Motor Driver with DRV8811/18/24/25 Copyright © 2011, Texas Instruments Incorporated
15
I 2 C Protocol and Communications Engine
www.ti.com
#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;
16
Intelligent Stepper Motor Driver with DRV8811/18/24/25
Copyright © 2011, Texas Instruments Incorporated
SLVA488 – October 2011 Submit Documentation Feedback
I 2 C Protocol and Communications Engine
www.ti.com
case START_STEPPER_ADDR: NumberOfSteps = (ParametersTable[NUMBER_OF_STEPS3_ADDR]
View more...
Comments