Having set the correct off time to suit my motor I can now micro step it with equal spaced steps, but only if I disable the mixed decay mode.
When the chopper switches off it can do it two ways. It can turn on both low side transistors. That short circuits the motor and lets the current recirculate. If the coil was a perfect inductor and the transistors perfect switches, the current would circulate forever and you would have a superconducting magnet. Real coils and transistors have some resistance, which causes the current to decay, but as these are relatively small the mode is called slow decay.
This is fine and efficient until you take the motor's back emf into account. During the rising part of the sine wave the magnet is moving towards the pole piece, so it generates a voltage that causes the current to fall faster. The on time gets longer to compensate and all is well.
On the trailing edge of the sine curve the magnet has gone past the pole piece and generates a voltage that increases the current in the coil. If it is going fast enough it can mean that the current doesn't fall at all during the slow decay period. As I showed previously that can cause a severely distorted waveform which makes the motor noisy.
The Allegro chips offer a mixed decay mode, where they switch to fast decay for part of the chopping cycle on the downward half of the sine curve. In fast decay mode one low side and one high side transistor turn on and reverse the voltage across the motor. That overcomes the BEMF and causes the current to fall much faster. It also returns current to the supply rail, which can upset some power supplies if there isn't some other load to absorb it.
Mixed decay gives a current waveform like this: -
The off time is fixed, so the current falls further making the ripple greater. If you set the percentage fast decay to give a clean waveform at your top speed, then the ripple increases at slower speeds. It is maximum when stationary, when there is no BEMF and fast decay is not required at all.
The problem is that the target current is the trip point of the comparator, so it is the peak of the chopping waveform. That means the average current is less by half the ripple current giving a positional error.
With the low inductance motor I am using, the ripple current has a large amplitude, so the error introduced when the motor is stationary is about the same as a micro step. That means the first step with fast decay is about twice as big as it should be and the last step is virtually zero.
With the A3977 I can disable fast decay and the steps are fairly even, but fast running is then distorted. The PFD setting needs to change with speed.
With the A3983 that I have used on my new extruder controller the PFD setting is fixed at 31.25%. That means I can't get evenly spaced microsteps with the NEMA17's that I have, when running slowly. Not a big problem with the extruder because I plan to gear it down 40:1, which means one micro step is only about 0.02mm. I am only using microstepping to give smooth motion rather than extra resolution.
The problem is exaggerated because not only am I using a low inductance motor, but I am also trying to run it at 1A, whereas it is rated for 2.5A. At 2.5A the off time would be about 2.5 times smaller, so the ripple would be 2.5 times less. The steps in the current waveform would be 2.5 times bigger, so the distortion would be reduced by 6.25 times. As it is about one microstep now, it would reduce to 1/6th of a microstep, so would be acceptable. The temperature rise would then be 6.25 times greater of course.
I was planning to use A3977s for my axis control though, where positional accuracy is important. I am beginning to think I will be better off just using dual H-bridges and doing the rest in software using a powerful micro with a fast ADC.
To be able to cope with a wide variety of motors you need to change the current, the off time setting and the percentage of fast decay. You also need to take the ripple current amplitude into account to control the average current, rather than the peak. All these things could be automated with a software solution.
Hi Nophead,
ReplyDeleteVery informative and useful post, as always. Recently I haven't been able to make much progress with my own stepper driver experiments, but hope to resume in September when the kids are back in school.
In my tests with the RRRF v1.2 Stepper Motor Driver boards, I've found that the L297 chip is more of a hindrance than a help. In particular, it seems that a properly programmed AVR Tiny in DIP-20 packaging can do a better job at a lower cost, and with more flexibility. My current idea is to hack one of my SMD v1.2 boards to use an AVR chip and program it in a way to provide some form of microstepping.
Right now, I have a bunch of direct lines from my Arduino to the various L297 pins to monitor and graph sense voltages and such. I think it is very doable to determine the lag between the actual phase of the motor and the phase of the signal driving it and use that to determine maximum speeds and safe acceleration profiles. Really, all the L297 seems to be doing can be done by using the analog comparator of the AVR Tiny and some smart programming. As bonus, we'd be able to actually use feedback to determine positioning at a sub-step scale.
My initial goal isn't so much increased resolution (though that's certainly a secondary goal), as well as increased smoothness and decreased noise. Also, I'd like to invert the driving method from giving step pulses at varying frequencies to giving step pulses at a fixed frequency, alternatively stepping forward, backward and pausing in order to obtain smooth motion.
This will in the end make motion control easier, because all dimensions (X,Y, Z, extruder speed, temperature, ...) can be updated at 10 kHz or so, instead of each needing its own interrupt. So, motors would always be microstepping at a given frequency (somewhere between 4 and 25 kHz). Basically, the process would be similar to recording and playing 5-channel music. The input signal is analog (continuous), and then sampled at a fixed frequency. WIth proper dithering and filtering (both in electronics and mechanical factors such as inertia), it should be possible to trade speed against resolution on a smooth scale. In this mode, any noise from the motors should be spread over the audible spectrum and be much less objectionable than the current characteristic stepper glissandos.
Driving steppers is an unexpectedly rich and complicated field, and I think in the long run the RepRap project will indeed be helped more by programmable electronics that can be upgraded through Free Software firmware than by fixed controllers such as the L297 or even the Allegro chips.
Hi Geert,
ReplyDeleteI agree the L297 and L298 have had their day, about 20 years ago!
You have an interesting approach. I look forward to seeing if it works.
One thing to bear in mind is that the BEMF has a big effect so any current control has to be closed loop.
Hi.
ReplyDeleteI'm pleased to find your blog. I´m toying around with stepper drivers myself, and I deal with some of the same problems as you are.
I've used the UDN2916 to drive some smaller motors and I've had some luck with an "adaptive off-time" control. I use a PIC to switch between to different off-times. That improves microsteppeing. If you would like to discuss these things further toy can reach me at dtugeek(at)hotmail.com.
Google me at "kofoedmejer" to see my blog.
Kind Regards Troels Mejer