Sunday, May 8, 2022

Bank Account Protection Circuit for Servo/Stepper Motors

Update 6/11/22

The parts I ordered from Mouser finally arrived, after 6 months of delays in getting the connectors. Here's one of the boards, fully assembled, using the 1W wirewound resistors and including the connector:




If you decide to build some of these circuits, you can skip the connectors and just solder the power in and out wires to the board.

Now back to the original post...



Prologue:

I wrote most of this post a couple months ago but didn't publish it because I was waiting for the connectors I ordered from Mouser Electronics. When I first ordered them, one piece was out of stock and due to be back in stock in a couple weeks. In a couple weeks I got an email informing me that the back ordered parts wouldn't be in for another month. A month went by and I got notice that the backordered parts were in stock but one of the other pieces was now out of stock. They're telling me that the parts should be in stock at the end of May. 

I decided to try using the servomotors in my corexy 3D printer, Ultra MegaMax Dominator and wanted to have protection for the controller board and all the other stuff that connects to the power supplies that power the XY motors, so I went ahead and wired in the protection circuits without the In/Out connectors.

Next time I order parts, I guess I'll have them ship as they arrive in stock instead of holding shipment until all parts are available.


Why Does My Bank Account Require Protection?

A while back, when I was working on the Arrakis sand table, I discovered that one really needs to take some special precautions when driving servomotors (or steppers) at high speed and acceleration. I had a Duet controller board, a couple buck converters to power LED strips, and servomotor, all connected to a single 200W 24V power supply. I made the mistake of driving the mechanism into the end of an axis at 1500 mm/sec. The sudden stop caused the motor's kinetic energy to be converted to electrical energy which ended up on the power supply line, blowing up the controller board, power supply, and buck converters, about $200 worth of electronics, hence the title of this post.

Motors generate voltage that opposes the voltage trying to make them turn. Under certain conditions, they can generate more voltage than the driving voltage. Those conditions include driving them at excessive speed, manually turning them (such as when sliding around the extruder in a 3D printer by hand), and slamming into physical stops while they are moving at high speed (like I did). In the Arrakis sand table, a simple error in generating the pattern file that's a little bigger than the actual table dimensions (combined with an incorrect axis maximum definition in the config file) can cause such a sudden stop. In servomotors like the iHSV series parts I used in Arrakis, the specified maximum rotational speed, 3,000 rpm, is limited by the self-generated voltage. When generating a pattern file for Arrakis, it's easy to make a mistake that will drive the motor beyond the 3,000 rpm limit.

Protection can take different forms. In Arrakis, which runs RepRap firmware on a Duet WiFi 3D printer controller board, I can program speed, acceleration, and travel limits in the Duet's configuration files. In theory, the fault condition should never occur. However, all that assumes that the controller hasn't lost its mind, that there are no mechanical failures, and that the dumbass (specifically, me) experimenting with the mechanism remembers to set the correct software limits in the controller.

What is really needed is a device that will protect my bank account from my stupidity, an insane controller board, or a mechanical failure in the mechanism. Preferably it will be a circuit that will sense a fault condition and keep it from damaging the electronics that might be sharing a power supply with the motor.

Someone on a web forum pointed out a protection circuit in an app note from Gecko Drives, a company that makes stepper and servo motor drivers. 




The circuit is pretty simple- the 1,000uF cap absorbs small current spikes that may occur under normal operation of the motor. Normally, motor current from the power supply goes through the diode to the integrated motor/driver. In the event of a sudden motor stop due to hitting the limit of an axis, or a bearing seizing up, or some object blocking the motion, the motor will put a reverse current spike on its power line. That will cause the voltage on the capacitor to rise above the power supply voltage, reverse biasing the diode (switching it off) which will turn on the transistor, dumping the current coming from the motor to ground via the 33 Ohm resistor. The power supply and anything else connected to it will never see the voltage/current spike from the motor.

I ran a simple simulation in LTSpice to see how it works. The voltage source on the left is the 24V power supply and the current source on the right stands in for the motor.


It's not much of a model, but it roughly demonstrates what happens in the circuit:



The green trace is the current in the motor. It starts at -3.4A, which represents the loaded motor current supplied by the 24V power supply (V1). When the current reverses direction (the fault condition) the voltage across the motor (blue trace) rises. Current through R3 (33 Ohms) starts at about zero because the transistor is off. When the voltage across the motor rises above 24V, the transistor turns on and current through R3 (red trace) rises. The power supply voltage is the light blue trace- notice it barely moves.

I decided I needed to build some of these circuits as I have 4 more of the motors waiting for projects (in addition to the two that are in Arrakis). I thought about hay wiring them, but it didn't seem like a good idea, so I needed a printed circuit board. I asked around the makerspace and a couple people recommended KiCAD, so I gave it a try.


Parts Selection

When you lay out a PCB, you need to know exactly which parts you're going to use in order to select appropriate footprints. The app note doesn't say too much about the parts so I made some calculations of basic specs then went shopping. I decided to use through-hole mounting for all the parts because they're easy to handle and solder.

The motor current normally flows through the diode so it has to be rated to handle it. The data sheet on the motors seems to indicate that the nominal load current for the motor is 3.4A  (3.4A x 24V=81.6W, and the motor is advertised as a 78W motor, so the current seems about right) and that the driver will alarm (and hopefully shut down?) at 300% of that. 300% of 3.4A is 10.2A, so I chose a 15A 100V Schottkey diode (SMC 15SQ100). In normal operation, with 3.4A going through the diode and voltage drop of 0.5V, the diode will have to dissipate about 1.7W, so it's going to get warm/hot (assuming the motor is loaded and drawing full current).

In the "Arrakis Incident" the motors were brought to an abrupt stop which is what caused the voltage/current spike that blew up the power supply and other electronics. If there had been a protection circuit like the one here, after the stop and current spike, the motor might have started up again (the power supply wouldn't have been dead) and run until it slammed into another hard stop. And it might have kept going, over and over. Hopefully, I'll be there watching it and will shut off power before the repeated slamming around does any damage.

The iHSV motor's integrated drivers appear to monitor the motor speed and/or supply voltage and will shut down the motor/driver if you try to drive it so fast that the self generated voltage exceeds the power supply voltage by some unknown amount. Other motor and driver combos may not do that.

If you try to drive a motor beyond it's spec rpm limit, the voltage at the motor will rise, Q1 will shut off, and the motor will slow down or stop until Q1 turns off again, and then the motor speeds up again repeating the cycle (again, the iHSV motors don't seem to do this). In some mechanisms it might keep doing that until someone notices that something is wrong and shuts down the machine. That means R1, R2, R3, and Q1 will all be working to dissipate energy from the motor on a repeated basis.

I point out the different types of faults because it affects the component selection. When Q1 is off, the normal state, R1 and R2 have very tiny current passing through them. In a fault condition, the current goes up and depends on the magnitude of the voltage/current spike produced by the motor. A 20V rise will cause 20 mA to go through R1 and R2. A 76V rise (which puts us up to 100V, the rating of capacitor C1) will drive 76 mA through them. 20 mA will dissipate 0.4W and 76 mA will dissipate 5.8W. Unfortunately, I can't really predict how the iHSV motors behave. There's no way to know what the voltage/current spike will look like under different fault conditions, and I'm not prepared to risk destroying a motor to find out. I chose to use 1W resistors for R1 and R2 and hope that will be sufficient. I used wire wound resistors because they can tolerate power surges better than other types. The ones I used are good for 10x their rated power (=10W) for 5 sec.

The app note specifies a TIP147 Darlington PNP transistor, so I chose one in a TO-220 package. Does it need a heatsink? This also depends on the magnitude and duration of the fault. I think it will only operate for a few seconds at a time under fault conditions, so I think it is safe to dispense with a heatsink.

This is a relatively high current circuit, so I chose a 4 pin Molex MegaFit connector rated for 23A per pin. I also ordered crimp terminals and shell for the plug that mates with J1.

I put together a BoM with part numbers from Mouser and Digikey here. You can make all sorts of substitutions and find the same or similar parts from other dealers. Prices in the BoM are approximate, of course. 


Designing the PCB

I watched a few youtube tutorials on using KiCAD, and dove in. One thing I found out is that if you're going to have PCBs made by OshPark or other board maker, it's best to set up the board maker's design rules before starting the board layout. 

I went to the OshPark website and looked up their design rules and checked them against the defaults in KiCAD. It turns out there were no issues so I didn't really have to change anything. A more complex board or using surface mount parts might require some of the changes.

Next I drew the schematic diagram:


Once the schematic was entered, I selected footprints for the parts. I checked data sheets for part dimensions and selected appropriate footprints from the KiCAD libraries. Then I just dragged the parts into position, paying attention to the net connections, defined the outline of the board, placed mounting holes, and started putting down traces. I used a filled area on the top of the board for a ground plane and put the rest of the wiring on the bottom of the board.

I had to change the connections to the connector a few times before arriving at the final pinout. Some pinouts led to difficult arrangement of the components on the PCB that required jumpers, etc. I found that by playing with the connector pinout I could create a very simple layout for the board.

The diode will carry the full motor current under normal operation, so the metal traces on the board need to be pretty wide to ensure low resistance and heating. There are a bunch of on-line PCB trace width calculators that will give a pretty good idea of the required trace width for any given current, trace length, and temperature rise. I used this one. I put the diode very close to the connector pins to minimize the high current trace lengths and used 10mm wide, filled areas for those connections for the same reason. They should be able to handle the fully loaded motor current and even the peak current without burning up, even with 1 oz copper.



The capacitor and transistor CE loop are the only other places that are likely to see much current so I used wider traces for those to minimize resistance/heating.

The final steps before ordering the board are to run a design rule check, fix any problems that it reveals, and then export Gerber and drill files.

This is the final layout which I have named REDump for "returned energy dump":

The board layout just before design rule check. The outline of the connector extended beyond the edge of the board so I had to edit it back to pass DRC.


The board is relatively large, 60 x 65 mm, due to the large sizes of the capacitor, 33 Ohm resistor and the connector. I used 4 mm mounting holes set at 50 and 55 mm spacing. I kept the edges of the board clear so that it could be mounted in slots in the walls of a case instead of using the screw holes.

I deliberately hung the connector beyond the edge of the board so that if I print a case for it the connector can protrude through the wall and mechanically support the connector. This overhang was flagged during the design rule check so I edited the footprint silkscreen layers so they wouldn't be drawn beyond the edge of the board.

I ordered a prototype run of 3 of the boards for about $30 from OshPark.

You can download the gerber and drill files in a zipped archive here if you just want to order boards, or the entire set of KiCAD project files is here if you want to do some editing for other parts/footprints.

And here it is:


I probably should have used bigger holes, pads, and pad spacing for the diode and the 1K resistors. When I order more boards I will make the changes to the files.


Assembly

There are no tricks- just put the leads through the holes and solder them down. Pay attention to polarity of the diode and capacitor, and make sure you put the transistor in the right way- the heatsink tab should be toward the connector. 

Note- the 1W resistors and connector are all still back-ordered after about 4 months, so I built it using 1/2 watt resistors and no connectors.


Testing

I did some static tests to verify operation- first just applying supply voltage to the input and making sure it appeared at the output with a resistor substituting for the motor. Then I applied a voltage to the output to make sure sure the diode turned off and the transistor turned on. 

Finally, as I was preparing to install the servomotors in UMMD, I made a test video that indicates the protection circuit will indeed protect the power supply and other circuits from a voltage spike generated by the servomotor.



Installation

When you connect potentially high current wires it's best to avoid ground loops. That means each ground wire should go all the way back to the power supply. That's how I wired this into UMMD. The REDump board ground has a wire back to the power supply ground, and the ground from the motor goes back to the supply ground, not to the REDump board ground.

That means a 3 wire cable is required at the REDump connector. The crimp terminals listed in the BoM are for the plug that fits the jack on the PCB, and are for 14 or 16 gauge wire. If you're going to use some other gauge you'll need to order a different part number for the crimp terminals.

It's also a good idea to twist high current wire pairs, so when I installed the REDump boards in UMMD, I twisted the ground and supply leads from the REDump board back to the power supply, and twisted the motor ground lead around the supply wire from the REDump board together, then continued twisting the ground lead from the motor around the ground and supply leads from the REDump board back to the power supply.

In the future I'll be installing these boards in Arrakis so I can start experimenting with really high speed drawing without having to worry about what might happen if there's a mechanical failure.