-->
1. Kinematic basicsThe linear acceleration (ramping) formulas are:where S - acceleration distance, in stepper motor case - number of steps, v0 - initial velocity, base speed (steps per second), v - target velocity, slew speed (steps per second), a - acceleration (steps per second per second), t - acceleration time, ramping period (seconds). By rearranging [2] and putting it in [1] we have and that can be represented as a recursive form of speed calculation for one step: where i - step number (1 < i < S). 2. Control basicsTo produce the speed profile for stepper motor we need to provide the real time delays between step pulses:where pi - delay period for the i-th step (timer ticks), F - timer frequency (count of timer ticks per second), so according to [6] the exact delay value will be: or 3. ApproximationUsing Taylor serieswhen -1 < n < 1 we can approximate [9] to Let's check the -1 < n < 1 condition. Our n was or, by velocity, The maximum n value will be at minimum speed, on the first calculated step, where i = 2 Because the minimal v0 is 0, from [6] we have So n will be always less than or equal to 1. Because our calculations are forward-only we have no limitation in case of deceleration (negative acceleration) too. 4. ImplementationThe given parameters are:v0 - base speed, v - slew speed, a - acceleration, F - timer frequency and the calculated parameters are: S - acceleration/deceleration distance p1 - delay period for the initial step pS - delay period for the slew speed steps R - constant multiplier The variable delay period p (initially p = p1) that will be recalculated for each next step is: where m - variable multiplier that depends on the movement phase: m = -R during acceleration phase, m = 0 between acceleration and deceleration phases, m = R during deceleration phase. For accuracy purpose let's set p = pS if p < pS or between acceleration and deceleration phases, p = p1 if p > p1 . 5. Optional enhancementUsing the higher order approximation of Taylor serieswe can get more accurate results replacing [20] with where q = m . p . p . By [22] we have excellent precision but with two extra multiplications and one extra addition vs [20]'s good precision way. Finally let's construct a very good compromise with just one extra multiplication and one extra addition: However I think that the good way ([20]) is not merely good but even good enough for most of stepper motor applications. The enhancement is important for servo drivers with the step/direction control that ramping up from and down to zero speed. 6. Programming noteThis algorithm was designed for floating point mathematics and in this form it works faster than in the integer form that requires division. |
* This algorithm was developed by the author in
1994 for L.I.D. Ltd as a part of POEM Stepper Organizer
software to control up to 4 axes through IBM PC's
parallel port (LPT) and was ported to microcontroller
platform in 2004. The main field of usage since 1994 - laser diamond cutting. ** Special thanks to David Austin <dave@slotech.fsnet.co.uk> who helped me with the enhancement part. |