ST AN2044 Application note

AN2044
APPLICATION NOTE
OPERATING PRINCIPALS FOR PRACTISPIN
STEPPER MOTOR MOTION CONTROL
1 REQUIREMENTS
In operating a stepper motor system one of the most common requirements will be to execute a relative move. The move will usually be specified as a fixed number of basic motor steps in the clockwise or counter-clockwise direction. It is common practice to execute this move along a trapezoidal shaped velocity vs. time profile.
Given the move distance, accel, decel, and peak speed requirement, a profile can be deter­mined. Since the control structure of the practispin software is designed such that the velocity and accel/decel rate can be changed at will, the task of pre-calculating the velocity profile boils down to determining the position values where operation switches from accel to constant speed and then from constant speed to decel. Since this is a relative move, we can assume that motion starts at position = 0, ti me = 0, and v elocity = 0. Figure 1 shows a ty pical trapezoi ­dal velocity vs. time profile
Figure 1. Trapezoidal Velocity vs. Time Profile
Let: P = total move distance in steps
P1 = steps required to accel from 0 to V P2 = steps required to decel from V to 0 V = peak velocity in steps per second (steps/sec) V1 = average velocity during accel or decel
AN2044/0904
Rev. 1
1/9
AN2044 APPLICATION NO TE
A = required accel rate in steps per second per second (steps/sec2) D = required decel rate in steps per second per second (steps/s ec2) T1 = acceleration time in seconds T2 = deceleration time in seconds
2 TRAPEZOIDAL POSITION FORMULAS
If we assume that the velocity will rise from 0 to V at a constant rate of acceleration:
1) T1 = V / A
2) V1 = V / 2
3) P1 = V1 T1
Substituting 1 and 2 into 3 yields:
4) P1 = V2 / 2A
In the same manner we have:
5) P2 = V2 / 2D
Once P1 and P2 have been calculated a check can be made to determine whether a trapezoi­dal profile is possible or whether a triangular move must be made instead. If the total number of steps required to accel and decel ( P1 + P2 ) is less than the total m ove distance, P , then there will be some "room" left for a constant velocity portion of the profile. If, on the other hand, P1 + P2 is greater than P, then the move profile cannot be allowed to get up to the requested speed since just getting up to speed and back down (at the requested accel and decel) would cause a move that would overshoot the target position.
If P1 + P2 is greater than P then a triangular rather than trapezoidal profile must be projected. With a triangular velocity profile there is no constant velocity portion of the move. The motor will accelerate at A and then abruptly switch to decelerating at D in order to "land" at the desired position at zero speed. In the case of a triangular profile we have only one im-
portant parameter to calculate, that being the motor position at which the system must switch from accel to decel mode.
The calculation is, however, somewhat more complicated than the trapezoidal case. Figure 2 shows a typical triangular velocity vs. time profile.
Figure 2. Triangular Velocity vs. Time Profile
2/9
AN2044 APPLICATION NOTE
3 TRIANGULAR POSITION FORMULAS
In a triangular move, the total distance is the distance to accel plus the distance to decel:
6) P = P1 + P
Substituting 4 and 5 into 6 yields:
7) P = V2 / 2A + V2 / 2D
Multiplying both sides of 7 by 2AD to clear fractions yields:
8) 2ADP = DV2 + AV2
2
Extracting the common factor V2 on the RHS of 8 yields:
2
9)2ADP = V
( D + A )
Dividing both sides of 9 by 2A( A + D) yields:
2
10)DP / ( A + D ) = V
/ 2A
Substituting 4 into 10 and re-arranging yields:
11)P1 = PD / ( D + A )
Equation 11 is our final result and is the most convenient form o f the formula for calculating the position at which the mode must be switched from accel to dec el for a triangular move. Please note also that this formula passes a fundamental "sanity" test.
If the accel and decel rates are equal, then P1 = P / 2. This is intuitively obvious. The system would have to spend half the total distance accelerating
and the other half decelerating. As the decel rate is increased, we can spend more time accelerating before we have to "put
on the brakes" to come to a stop at the required position.
The Practispin stores P, D, and A as unsigned 16 bit variables. A 16 by 16 multiply subroutine is used to get the product PD, which is 32 bit.
A 32 by 16 divide subroutine is used to get the quotient of PD and ( D + A ). Note: If ( D + A ) overflows 16 bits then both terms are pre-divided by 2 before the main divide is executed.
The same subroutines are used to calculate formulas 4 and 5 in the trapezoidal case. Please note that execution time for these calculations is not critical since they are done only once per move and are completed before the move begins.
4 PRACTISPIN STEPPER MOTOR CONTROL SCHEME
4.1 20 KHZ INTERRUPT
The heart of the stepper motor c ontrol mechanism is the 20KHZ interrupt. This interrupt in­vokes an Interrupt Service Routine (ISR) which executes repeatedly on a fixed time interval of 50 microseconds. In the subsequent discussion we will call this 50 microsecond interval a TICK and this will serve as our basic time unit.
In order to maintain a consistent system of units we w ill meas ure position in steps, v e locity in steps/tick, and acceleration/deceleration in steps/tick amount to a real time simulation of the motion system. The ISR calculates real time values for
2
. The calculation performed by the ISR
3/9
Loading...
+ 6 hidden pages