Thursday, 30 July 2009

Lessons from the A3977

Having established that I want to move to a stepper driven extruder I set about designing a new extruder controller for HydraRaptor. I fancied using one of the Allegro micro-stepping chopper drivers.

With these chips there are a few things you can adjust by changing component values, like the off time, minimum on time and percentage fast decay. The data sheet explains what they do and gives the formulas but it's not obvious what you should set them to for a particular motor.

Not having any previous experience with Allegro drivers I decided I needed to knock up an evaluation circuit. Fortuitously Zach had sent me some PCBs a long time ago that were his first version of the Stepper Motor Driver v2.0. They used the PLCC version of the A3977.

PLCC packages were a bit of a halfway house between through hole and surface mount. They have leads which come out of the side and then curl underneath.



They are handy for programmable devices because you can either surface mount them or put them in sockets (which can be either SMT or through hole). The problem with them in this application is that using a socket is not recommended for current and heat dissipation reasons.

That makes the package a worst of both worlds solution. It is big and bulky like through hole parts but still difficult to hand solder because the pins are underneath. The surface mount version of the A3977 is a fine pitch (0.65mm) TSSOP with a heat slug underneath, so again not easy to solder by hand, it really needs to be done by the solder paste and oven / hotplate method.

Zach moved to the A3982 on subsequent versions, which is easy to hand solder because it is in a SOIC package with 1.27mm pitch. It also has a lower external component count. The down side is that it does not do micro stepping and is only 2A rather than 2.5A. I will probably use the A3983 (which is like the A3982 plus micro stepping and in a TSSOP package).

I managed to hand solder the PLCC at my second attempt. My first attempt had a short, which damaged the chip. I damaged the board removing it (with a cutting disk), so I had to start again on a second PCB. Lots of cursing! The lesson is always to meter a PLCC for sorts before powering up as you can't see shorts underneath it.

Here is my test lash up: -



I can set the step rate with a signal generator, vary the supply voltage from 8 to 35V, see the temperature of the chip and look at the current waveform on a scope .

The initial results were disappointing due to a couple of problems: -

The first was that the chopping occasionally had glitches in it. With the motor stationary I could hear it clicking, and with a scope I could see some cycles shorter than they should be. It got worse with higher supply voltages. At low speeds it did not make much difference, but it did lower the maximum speed. I tracked it down to a lack of high frequency decoupling on the 12V rail. I added a 220nF de-coupler close to the chip and the problem went away. Adding it further from the chip actually made it worse.

The next problem was that the microstepping was very uneven. I had noticed that same effect with the z-axis of my Darwin using the $800 microstepping drivers (that I got cheap) that I use on HydraRaptor. At the time I put it down to the small, large step angle tin can motors I was using at the time not being very linear. When I moved to larger 7.5° tin can motors I still had the same problem, and even with the Keling NEMA23 1.8° motors it did not seem right. This puzzled me because they are very similar to the NEMA23 motors on HydraRaptor, which work well with the same drivers. The shaft encoders have the same resolution as the ×10 microstepping and they are always spot on or one count out, so pretty linear.

With the A3977 it is easy to get an idea of the current waveform of the motor by measuring the voltage on the sense resistors. It should be a stepped sine wave like this: -



Regardless of which way the coil is energised, the current flows to ground through the sense resistor, so the waveform looks like a full wave rectified sine wave. The current only flows in the sense resistor when the chopper is in the on state though. In the off state the current is circulating through the coil and the bottom two transistors of the H-bridge, so the current in the resistor is zero. That is why there is a bright line along the X-axis. On the falling edge of the wave you can see the sense current goes negative. That is because the chip switches to fast decay mode. When the chopper is in the off state, instead of short circuiting the coil, it reverses the voltage on it, causing the current to flow backwards through the sense resistor onto the supply rail. It only spends part of the switching cycle in fast decay so you see positive current, a lot of zero and some negative current, hence the relative brightness of the lines. This is a case where an analogue scope gives you more information than a digital one.

Initially the waveform looked like this, it was somewhat distorted: -



The current rises too quickly at the start of the waveform. The chopper has a constant off time (20uS in this case) and varies the current by changing the on time simply by turning it on until it reaches the target value. But, there is a minimum on time of about 1.4uS, called the blanking period. During that time it ignores the current sense signal to avoid false readings due to ringing on the switching waveform. That means there is a minimum mark space ratio of 1.4 : 21.4 in this case. That sets a minimum current, which also depends on the ratio of the supply voltage to the motor voltage. If this minimum current is more than the lowest microstep value (19.5% of the peak for 1/8 steps) then you get a distorted waveform as above, and the steps are uneven.

To fix it you can lower the supply voltage, raise the current setting or increase the off time. The latter reduces the chopping frequency. If it is below about 15 kHz it will be audible when the motor is stationary. It can also start to beat with the stepping frequency when running at high speeds, particularly when micro stepping, as the step rate is n times faster.

This form of distortion is analogous to crossover distortion on a class B audio amp. You can also get the equivalent of clipping if you use a high voltage motor on a low supply voltage. If the current setting is set to a value which is more than the motor will draw when connected to the supply, then the top of the waveform is flattened off and again the microsteps will be uneven.



Yet another form of distortion occurs when running at high speed: -



Here the back EMF from the motor acting as a generator is preventing the current from falling fast enough to follow the sine wave. This can be fixed by increasing the Percentage of Fast Decay, set by the voltage on the PFD pin. If there is too much you get excessive ripple as shown here: -



For a particular speed and motor there is a sweet spot which sounds audibly quieter: -



So setting up a microstepping drive is not straight forward unless you have an oscilloscope. You can tune the PFD by ear though, as this video demonstrates: -

Tuning PFD from Nop Head on Vimeo.

You can also see the other forms of distortion if you attach a long pointer and step it round slowly.

Another lesson is that you cannot simply just set the current to accommodate different types of motor. You really need to be able change the off time and the PFD as well, especially if you use different supply voltages.

So I solved the mystery of why microstepping does not work well with the expensive drives on my Darwin. They are rated at 7A but I am only using them at 1A, I am also using low voltage motors on a 36V supply. I bet it is a constant off time chopper and the minimum current is too high.

23 comments:

  1. Wow, once again very impressive. I thought you must have been on holiday as you havent posted for a while - silly me to doubt that you would be beavering away in the background!

    I have to say I wish I understood all of the details but it is a real insight into the way we all SHOULD be working.

    Do you think this kind of chip will make its way into a new stepper motor driver or has it already been discounted? Ive avoided SMC as my soldering experience is limited but I can see the time when I have to make the jump!

    ReplyDelete
  2. Hi Phil,
    My blogging has got behind real time by about a month, so I am doing my best to catch up.

    I have just made the jump to SMT at home. I find soldering is no problem with paste and a small oven or a hot plate with PID control. I will be blogging details soon. You can buy suitable ovens in places like ALDI cheaper than a decent soldering iron.

    Also MakerBot have now started selling assembled boards, so they are no longer limited to easy to assemble chips.

    Any "details" that I can clarify?

    ReplyDelete
  3. Whew! What chance has your average ten thumbed amateur got to achieve high performance using those sorts of chips using surplus steppers without an oscilloscope and a clone of your brain? :-(

    ReplyDelete
  4. Well hopefully a bit more chance having read this, but yes it is not as straight forward as I would like. However, you never get worse performance than a non microstepping drive would achieve.

    It should be possible to do a software implementation of micro-stepping that self tunes and / or tells you when it can't acheive the required current waveform.

    Some of the problems come from it being a constant off time chopper. Constant frequency would probably be less dependent on the motor.

    ReplyDelete
  5. Also it should be possible to calculate the component values from the motor resistance, which you can measure with a multimeter.

    I have been doing the sums but can't make the figures match the measured values at the moment. Maybe I have got something wrong somewhere, or perhaps the eddy current losses account for the discrepancy. Still I might be able to publish a worst case formula.

    ReplyDelete
  6. I just finished reading all of your posts from the very beginning (well, skipping the posts I deemed boring) and I must say, it's easy to see that you're very dedicated to getting things working and improving them, so good job. It's people like you that make the world go round.

    ReplyDelete
  7. nophead: Have you evaluated the AVR based open source stepper motor controller?:
    http://www.avrstmd.com/

    It seems they have microstepping, with nice waveform and 3A/coil. Maybe Im mistaken, Im just curious...

    Khiraly

    ReplyDelete
  8. Very expensive, $85, and very big.

    ReplyDelete
  9. > Very expensive, $85

    Yepp, but the LMD18245T part (DMOS full bridge) costs alone 15.47$ and it requires 2/motor.
    However this is responsible for the nice curve....
    Maybe its not "that" expensive this way.

    http://parts.digikey.com/1/parts/577573-ic-h-bridge-3a-55v-220-lmd18201t-nopb.html

    So Im thinking replacing this expensive part, and it would suddenly turn into a real option.

    >and very big
    Cant be an issue... If it really that big, we can use smd parts.

    Khiraly

    ReplyDelete
  10. The two LMD18245T plus an Arduino cost a lot more than an A3977 that does the same job.

    They are still constant off time choppers and will have all the same distortions when run under the same conditions. Their advantage is a bit more current and twice the resolution. There is an Allegro single chip with twice the resolution as well.

    Size is an issue because I am making an extruder controller that mounts on the extruder, plus PCB is costed by the area.

    ReplyDelete
  11. > constant off time choppers
    If you have a microcontroller it is not necessary to have a constant off time chopper. (or this 20us comes from the LMD18245T limitation? ie, it has a minimum switching time)

    I admit that having a microcontoller is a way bigger project then simply buy an off the shelf product. I just wanted raise your attention to this possible solution. (I dont want to convince you at all)

    Best regards,
    Khiraly

    ReplyDelete
  12. Yes a micro with a fast ADC could do the chopping itself. I don't think the Arduno would be up to it, something like an ST ARM Cortex would be ideal. But you still need two H-bridges per motor, so why not use a chip that has two H-bridges and the chopper built in?

    It gets more practical with a unipolar motor as you only need 4 transistors and a micro, but the motor gives less performance.

    ReplyDelete
  13. > But you still need two H-bridges per motor, so
    > why not use a chip that has two H-bridges and
    > the chopper built in?

    You know when you have a hammer, you see the world as nails;)

    No, I dont think an arduino is enough, but there is dsPic at microchip, or browse what atmel has oriented to signal processing.

    I have seen servo drive using a microchip, I have an electric bike (brushless DC motor), where a pic is inside with dozens of FET, and I even saw an inverter drive project for AC motors. Maybe there are some common things in them.

    But having a target circuit designed for the job has its advantage I agree.

    Khiraly

    ReplyDelete
  14. If I was trying to design the cheapest system possible I would use unipolar motors, with four cheap FETs per motor and a single MCU fast enough to do the chopping.

    Maybe that would work out at about $3 per drive. The Allegro solution would be more like $6 per drive, but less effort and better performance. It also has overload protection, etc.

    As soon as you go to bipolar you need at least 12 transistors per drive and have to worry about shoot through protection (both transistors must never be on at the same time), so a single chip solution becomes much more attractive.

    But using two big chips and a micro to do the same job as single chip that is cheaper doesn't make any sense to me unless you really need 3A instead of 2.5A.

    ReplyDelete
  15. Fair enough. You have a point.

    Khiraly

    ReplyDelete
  16. Could this board (i think currently it is 3.3 version at makerbot) take smth like a 2.2 or 3.0 A source transistor? Or is that too high versus its 1.0 or 1.5A not sure which is atm. Or it will just fry it all over. Btw, tyvm for all the info in your blogs.

    ReplyDelete
  17. The A3799 will supply an absolute maximum of 2.5A but it will need a good heatsink to achieve that. Without a heatsink the maximum is somewhere between 1.5 and 2A.

    You can't increase that by adding transistors.

    ReplyDelete
  18. Forgot to paste a link to the similar PIC mcu driver board here, i think more or less close to the other driver linked above. http://www.piclist.com/techref/io/stepper/linistep/index.htm Was reading some tips on increasing its motoring currents.
    For the a3977 version 3.3: how to calculate the 50k pot adjustment for a motor (got ~3ohm http://www.reprap.org/wiki/StepperMotor#Keling_KL23H51-24-08B)
    Tyvm again btw and sry for the previous post, i see it has nothing to do with that transistor, just my brain neurons falling between the two webpages.

    ReplyDelete
  19. Hi! Great post! I got some trouble with this allegro IC. Over a certein value of REF voltage the motor start to become random! (turn without step command). What can be?
    Thank you!

    ReplyDelete
  20. Maybe a bad ground or poor decoupling causes noise on the step signal when the current is high.

    ReplyDelete
  21. Great articles and I like the oscilloscope views. Your scope is an analog? What were the values you concluded for setting your controller values? I saw your motor tables on another article you did about the A3977 but I am having difficulty converting to PFD, REF, RC1&RC2 for the MakerBot v3.3 steppers. P.S. I did post to another of your articles. I could not find contact information for you even though you are posting in many venues. Regards...

    ReplyDelete
  22. Very informative!

    But I have to warn using as supply voltage above 25V. This is because the motor generates back EMF, which is conducted trough the syncronous rectification mosfets of the driver chip onto the supply rail. So it is possible that the supply rail gets above 35V, because the energy of the back EMF has to go someware. I so destroyed two A3977 drivers, using a motor voltage of 30V and so as the motor was stopped quickly the voltage on the supply rail raised up to 42V, destroying the H-bridges of the driver. Although the supply rail had 4700uF capacitance to dampen the voltage spike. A sufficent method to prevent that is using a power zener diode. I'll use it in a improved future design

    ReplyDelete
    Replies
    1. Yes that can happen if there isn't enough load on the PSU to absorb it.

      Delete