Linear acceleration of stepper motor  - Page 1
Forum section: electronics / projects

author: ricko_uk
author_rank: Super Contributor
timestamp: May 31, 2021, 05:34:07 pm
content: Hi,I need to accelerate a stepper motor as fast as possible and I am driving it in 1/4 microstepping mode. I do not need to generate the acceleration profile on the fly and I do not need to keep the calculation short because the micro used is a 32-bits and the calculations are done at boot generating the profile only once and then stored in an array.Questions:1) I hear contradicting views on the stepper motor pull-out torque decreasing (some say drastically/esponentially) with the level of microstepping. Even online doing some search I keep coming across contradicting views. Is there some definitive data on this? I assume it is a well tested fact, but not according to the people I spoke to or the various things I read online.2) in order to implement a constant acceleration I used this app note which, seems referenced to often:http://ww1.microchip.com/downloads/en/AppNotes/doc8017.pdfBut when I implement the formulas, whether in Excel or in my code, the time delays decrease exponentially and not linearly (see my attached Excel screenshot). Am I missing something? Shouldn't the time intervals driving the stepper be decreasing (i.e. speed increasing) linearly? Even the speed graph in that application note shows speed increasing linearly/constantly which is obvious given the acceleration is supposed to be constant...3) As a side question, are there other papers/methods/application notes?Thank you

author: Nominal Animal
author_rank: Super Contributor
timestamp: May 31, 2021, 05:51:50 pm
content: Quote from: ricko_uk on May 31, 2021, 05:34:07 pmStepper rotational velocityωis a linear function of pulse frequencyf,ω=kf(k being just a constant describing the number of pulses per one angular unit). The interval between pulsesλis literallyλ=1/f. Therefore, rotational velocity isinversely proportionalto pulse interval,ω=k/λ.The curve you see is not exponential, but 1/x, and is expected from this relationship.

author: ricko_uk
author_rank: Super Contributor
timestamp: May 31, 2021, 06:07:39 pm
content: Thank you Nominal Animal!Quote from: Nominal Animal on May 31, 2021, 05:51:50 pmI think it is time for me to take a break and go for a walk!

author: Nominal Animal
author_rank: Super Contributor
timestamp: May 31, 2021, 06:19:01 pm
content: One commonly used speed curve isω(t) = 3Wt2/T2- 2Wt3/T3.This starts with zero velocity at timet=0, reaching velocityω=Wat timet=T, and has zero acceleration at both times.The interval between pulses is thenλ(t) = k / (3Wt2/T2- 2Wt3/T3) = kT3/ (Wt2( 3T- 2t) ).While theω(t) curve is an intuitive-looking one (ramping smoothly from zero toWas time goes from zero toT, in a sort of soft very slanted s shape), the pulse interval one,λ(t), looks very much like just another 1/tcurve at a quick glance. Both, however, describe the exact same thing.The point is, do not look at the pulse interval curvesλ(t); the visual processing parts of our brain are not equipped to interpret these correctly. Instead, look at the rotational velocity curves,ω(t) = k /λ(t). Iftandλare in seconds, a 200 steps per turn quarter-microstepping motor has k = 1/(200×4×60×60) = 1/2880000 ≃ 0.000000347222; and yieldsωin RPM, rotations per minute.

author: ricko_uk
author_rank: Super Contributor
timestamp: May 31, 2021, 07:30:51 pm
content: Thank you Nominal Animal,Any advantages of using the one you suggested instead of the the one I originally came across in that app note?Either in ensuring more pullout torque (by having the time interval slightly different) or perhaps faster computation as it uses multiplication vs double square root? Or maybe other ones?Thank you

author: Nominal Animal
author_rank: Super Contributor
timestamp: May 31, 2021, 08:38:55 pm
content: Quote from: ricko_uk on May 31, 2021, 07:30:51 pmI think the appnote has better acceleration/torque properties.Note: I can do all the math involved, and have done a bit of experimentation (plus things like blade path compensation math for vinyl cutters), but I really don't have any real world experience yet. So my points are wholly theoretical and mathematical, with zero practical experience. Apologies, if I mislead you accidentally! I find this very interesting myself, and might have gotten a bit carried away here.The y(x)=3x2-2x3curve (forT=1,W=1) minimisesjerk, or change in acceleration. It is used in things like elevators, to make the acceleration/deceleration feel smooth. (There is also y(x)=10x3-15x4+6x5, which minimises the rate of change in jerk, giving almost unperceptible acceleration in elevators.)Because the force applied (assuming linear motion achieved by the motor, either via wheels, pulleys, or a leadscrew) isF=ma, or mass times acceleration, using constant acceleration yields constant force; and this force the motor needs to overcome with its torque. (There is a similar thing in the change of angular momentum, in case you only consider rotating a flywheel or something. As a first approximation (the roughest possible that makes sense), we could say torque needed is roughly linearly dependent on the acceleration. The torque a motor can provide is dependent on its rotational velocity, however.)For stepper motors, torque is maximum at or near zero speed, so at the low end, there is no need to start acceleration at zero. Newer digital stepper motor controllers do not appear to suffer from resonant speeds; or this is what I gathered from the recent not-very-accurate-but-quite-illustrative stepper/servo torque tests Clough42 did.There is one interesting rotational velocity curve, for accelerating from standstill to velocityWat timeT, with initial acceleration 2W/T, and final acceleration zero. This maximizes the force needed at low velocities, and minimizes it at the target velocity:$$\begin{aligned}\omega(t) &= \frac{2 W}{T} t - \frac{W}{T^2} t^2 \\\frac{d \omega(t)}{d t} &= \frac{2 W}{T} - \frac{2 W}{T^2} t = \frac{2 W}{T} \left( 1 - \frac{t}{T} \right) \\\frac{d^2 \omega(t)}{d t^2} &= - \frac{2 W}{T^2} \\\lambda(t) &= \frac{k}{\omega(t)} = \frac{T^2 k}{2 T W t - W t^2 } \\x(t) &= \int_{\tau=0}^{\tau=t} \omega(\tau) d \tau = \frac{W}{T} t^2 - \frac{W}{3 T^2} t^3 \\\end{aligned}$$where \$\lambda(t)\$ is the pulse interval at time \$t\$, and \$x(t)\$ is the approximate distance travelled. (Forexactdistance, we'd actually need to calculate the pulses, turning the integral into a sum where the velocity \$\omega(t)\$ issampledat specific times – this, pivoting from continuous time to discrete time, is a bit headache-inducing at times, so I left it out.)As a velocity-force (or velocity-torque) diagram, this gives a straight decreasing line, with zero torque at the target velocity \$W\$.Is this better or equivalent to what the appnote says? I don't know, but I'dloveto know! I don't have the equipment (nor the funds to buy expensive steppers) to find out. Especially the expensive servos seem to have VERY high peak torque capability, but have a relatively low steady-state maximum that applies to speeds up to 1000 RPM and over (based on Clough42's tests), so the ramp-steady-ramp profiles shown in the appnote make much more sense for those. For pure steppers, this might be better; I just don't know.

author: ricko_uk
author_rank: Super Contributor
timestamp: June 01, 2021, 12:30:21 am
content: Thank you Nominal Animal for the detailed infos! Very much appreciated!!And the fact that the one you suggested minimises jerk can come useful in another application I am working on.Thank you

author: jmelson
author_rank: Super Contributor
timestamp: June 01, 2021, 01:04:45 am
content: Well, all of the above is just theoretical, without including the effects of the motor and driver. But, those are REALLY important. As motor speed increases, the back EMF generated by the moving magnets increases linearly, while the available DC power supply is constant. So, the available overvoltage (power supply minus back EMF) decreases.Thus, it takes longer for the current to build in the windings at the same time as the time between current reversals decreases. So, available torque stays constant at very low speeds, then drops fairly linearly (and pretty steeply in most systems) up until some point at which torque goes to zero.Many manufacturers have torque vs. speed curves, at least for combinations of motors and drivers they sell. These are very instructive, and a bit shocking to see how quickly the torque falls off.Jon

author: jmelson
author_rank: Super Contributor
timestamp: June 01, 2021, 01:12:02 am
content: Quote from: ricko_uk on May 31, 2021, 05:34:07 pmIt depends a bit on the design of the stepper drive. Full step driver always deliver full current to both windings all the time. You won't get more holding torque than that. Half step drivers deliver full current to only one winding on half of the steps. That leads to less torque overall.But, all microstepping drives use some sort of scheme to deliver sine wave drive to both windings. The microstepping factor is just how many points the sine waves are divided into. So, above half step drives, microstepping factor should make no difference in torque, just a difference in speed vs. step puises input.Some advanced drives have schemes to detect and damp resonance, optimize linearity of the magnetic fields in the motors and adapt to torque load on the motor to counteract stalling. Those will change the sine wave current shaping and affect torque during acceleration/deceleration.Jon

author: ricko_uk
author_rank: Super Contributor
timestamp: June 01, 2021, 01:43:15 am
content: Thank you Jon!Quote from: jmelson on June 01, 2021, 01:12:02 amOn the board I am controlling there are only "simple" TB6600HG (https://eu.mouser.com/datasheet/2/408/TB6600HG_datasheet_en_20160610-1760530.pdf) and when I do notice quite a difference in the pullout torque between 1/2 and 1/8 step. Any idea what that might be caused by?Thank you

author: Doctorandus_P
author_rank: Super Contributor
timestamp: June 01, 2021, 08:59:31 am
content: A stepper motor is an electro-mechanical system, and inertia of the motor itself and of attached "stuff", and damping in couplings interact with the drive currents of the stepper motor. This was much more important 30 years ago compared to "modern times" because microstepping was not so common and full or half stepping can introduce resonances in the system which can lead to position loss.I have also seen those tables which state you can only use ridiculously small torque when high microstepping levels are used, but think about it this way:If you put a static current though one stepper motor winding, and then rotate the axle, the torque will be somewhat sinusoidal. If the motor is free, then output torque is zero. A 200 step/rev motor is a 50 pole motor, and after 4 full steps the motor is again in it's electrical "start position". Delivered torque is maximum if there is a 90 degree offset between the mechanical and the electrical position, and with 180 degree phase difference (two full steps) torque is zero again, but it's an unstable point.The tables with the very reduced torque for higher microstepping levels assume that you want a "correct" position according to the drive current, so the 90 degree phase difference is never reached. The "allowed" position difference is likely one microstep.If you want to get the maximum out of your stepper motor, then optimize for this 90 degree phase difference. Algorithms for this are pretty common. Research "FOC" (Field Oriented Control).There are some open source projects such as "Ananas Stepper" and "Mechaduino" and the "BigTreeTech S42B". All these projects use position feedback from a Hall sensor and separate PWM'ed H-bridges. You can also buy 3-phase stepper motors, and control them like the BLDC motors that they are (just with a higher pole count then usual).This higher pole count is not a real advantage anymore if you go this way. In "traditional" stepper motor applications, you rely on the high pole count to keep position by over driving the motor coils, but if you optimize with FOC for a 90 degree phase difference you optimize for the minimum current (or with a few small changes for the maximum torque / acceleration).With the higher pole count, it becomes more difficult to accurately measure the phase difference between the electrical and mechanical sub systems, especially with higher RPM and the lag in measurement of the motor position.

author: ricko_uk
author_rank: Super Contributor
timestamp: June 01, 2021, 12:13:05 pm
content: Thank you Doctorandus_P!

author: Andre Laloni
author_rank: Newbie
timestamp: April 28, 2024, 08:12:29 pm
content: Nominal Animal, I am Andre, a new member in the Forum. I really appreciated your contributions to this topic and I would really like to pick your brain on this topic, as I am trying too develop some C++ code for Arduino to drive stepper motors in different acceleration/deceleration scenarios. They will all have a 5 phase cycles, being.: Stopped, Accelerate, Constant Speed, Decelerate, Stopped.I am a mechanical engineer, having a my whole career working in investment banking. So coding and mechanical systems with stepper motors has ben my hobby! I am new and self taught in coding, however, my largest challenge has been getting the correct equations into the programs. The math is what is making my life mode complicated as it has been difficult for me to isolate n (number of steps), λ(delay), ω((speed), t (time), ω'(acceleration), and p(position).Is there a way I could get in touch with you.Thank you very much.Andre.

author: moffy
author_rank: Super Contributor
timestamp: April 28, 2024, 11:03:10 pm
content: Just an FYI for Andre, there is a project that might suit called GRBL:https://github.com/grbl/grblwhich runs on an Arduino, it takes GCode commands and controls the stepper motors, it is used quite extensively and would probably suit your application.

author: Nominal Animal
author_rank: Super Contributor
timestamp: April 28, 2024, 11:27:27 pm
content: There is alsoSmoothiewarefor LPC17xx (ARM Cortex-M3) licensed under GPL v3.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: April 29, 2024, 04:32:10 pm
content: Quote from: moffy on April 28, 2024, 11:03:10 pmGRBL is an old project. It has not been updated for several years. Development of GRBL has moved on to grblHAL. Development of GRBL was forked into many different uC architectures, and lots of forks on github and this made introducing new features difficult. GRBL has also outgrown the classic 8-bitters, and benefits from both more Flash a faster uC (Cortex M3, ESP32, etc, and probably more advanced features (DMA and such). With GrblHAL (= Hardware Abstraction Layer) a lot of forks of GRBL have come together again, and you can compile in extra modules (for example for controlling a frequency inverter over MODBUS).There is a quite popular article about calculating acceleration / deceleration written by David Austin. It is published on a lot of sites (EDN, EEtimes, etc). It has found it's way into several application notes (Including atmel back then, now microchip), and you find a lot of other references:https://html.duckduckgo.com/html?q=david+austin+stepperBut overall, I would probably just fork GRBL-HAL, add a self written module to generate some lines of G-code on the uC itself and put that in the right buffer and then be done with it. Some architectures with grblHAL support upto 8 motors.