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.


Tuesday, March 8, 2022

New 3D Printed Sci-Fi Lamp Design

For some reason, I find myself designing and printing a lot of lamps. Here's the latest, designed in Fusion360 to fit a Feit Electric G63 vintage LED filament bulb that is 8" in diameter.

I like combining the antique look of the bulb with a "modern" base- it looks like something out of an old Buck Rogers movie (the movies from the 30s and 40s, not the awful TV series from the 80s).

The lamp base prints in vase mode. I printed it using PETG, a 1 mm nozzle, 1.2 mm line width, 0.5mm layer height, in about 4 hours at 30 mm/sec. Prusa Slicer vase mode has been broken for years and leaves a seam down the side of the print, so I sliced with Cura. No seam at all!


The overall height is 400 mm, the print is 300 mm tall. The bulb barely rises above ambient temperature, even after hours of operation, so there's no danger of melting or softening the PETG print.


A look down inside the print. You can see the tiny facets that make up the "curved" surface of the print. Maybe I need to export the STL file with even smaller segments.


Power off.


Power on- the bulb socket is quite visible at this angle. View it from a little higher or lower and the socket all but disappears due to the way the print layers scatter light.




Bottle for scale...

I'll probably print a cone using opaque white filament to cover the socket for this lamp. I'm also going to try printing the whole thing in opaque filament to see what that looks like. I'll post pictures when I do.

The Fusion360 Step file is here. You'll need a 280x280x300 mm (or larger) print capacity machine to print it, and I recommend a 1mm nozzle. You'll find the lamp is saved as a solid object. In the slicer you will use vase mode which will have no infill, a single wall, and no top layers. I printed in PETG, used 3 or 4 bottom layers, and set the line width to 1.2 mm. The resulting print is quite sturdy and very tough. I drilled a hole between the fins near the bottom of the lamp to feed in the line cord because I thought it would look better than running the cord out through a hole in the edge of one of the fins.

Thursday, February 17, 2022

Ultimate 3D Printed Wire Twister

Update 3/20/22

You can now find this design at the Wago Creators web site: https://wago-creators.com/design/185


"Let's Do The Twist"

When you're wiring things like 3D printers, sand tables, model train layouts, and almost anything else, you often need to use wires to connect things that are separated anywhere from a few cm to a few meters. If you want to do it neatly, you want the wires twisted together, especially if they carry motor or bed heater currents. Twisting wires carrying high currents helps prevent them from inducing currents in adjacent wires.

A few years ago I designed a wire twister and posted it on Youmagine.com. It was a simple, two-part 3D printed tool. The spinning part had screw clamps to hold two wires and a hex shaft to fit in an electric drill/screwdriver. The fixed part was intended to be held in a bench vise. The wire clamps in both parts used screws to hold the wire tightly, so you had to use a screw driver to secure each end of each wire, creating four opportunities to stab yourself with a screwdriver in the process. Operation was simple- just pull the wires tight and pull the trigger on the drill. Bob's yer uncle, instant twisted wire pair!

A few days ago, I got an email notice that my old wire twister design was added to someone's collection at Youmagine.com. That same day I had demonstrated Wago lever nuts to my boss who is getting into model train layouts. And then, just like this old commercial...




...something clicked and I realized I could redesign the wire twister to use Wago lever nuts so all you'd have to do is lift the levers, shove the wires into the holes, snap the levers down and spin. No more screwdriver, no more risk of stab wounds! Wagos and 3D printing are the greatest combo since peanut butter and chocolate! The Wago 221-412 lever nuts are good for 24-12 gauge wire, solid or stranded, so they're good for almost any wires you'll ever need to twist.


The New Spinning Clamp Design

I previously designed some printable screw-down mounts for the Wago lever nuts and they worked very well. The lever nuts snap into the mounts so securely you have to use a screw driver to pry them back out. This is the basic unit I started with for the screw-down mounts, and for the new wire twister design:


I grabbed the design for the Wago holder above and reworked it to include a hex shaft to go into a drill:



The model for the Wago lever nut came from partcommunity.com and is supposed to be accessible from inside Fusion360 (Insert>Insert a manufacturer part). It refused my login name/password when I tried to insert the part that way, so I just logged into the site in a web browser, downloaded the .stp file, then "uploaded" it to Fusion360. The model isn't very detailed, and doesn't include the concavity on the sides of the part that allow it to be held in place by the bumps inside my holder design. This is why it is sometimes better to make your own models or at least to measure the parts you want to use in CAD.


The New Fixed Clamp Design

My initial design was for a fixed clamp that you'd use with a C-clamp to hold it on the edge of a table or shelf, or in a bench vise. Then I decided it would be better if the fixed wire clamp actually was a C-clamp so you wouldn't need another tool. Here's what it looks like:

The fixed wire clamp is a clamp! Printed in 3 parts, the thumbwheel, the end cap, and the clamp body.


You can still use a vise to hold the C-clamp, if you prefer, or skip printing the fixed clamp and just hold a Wago in a bench vise.

The hardware consists of a 5/16"-18 bolt, 3-4" long, two nuts, and a washer. Those of you who live in the civilized world (you know, metric) may have to edit/scale the design file a little to use 8mm hardware. Assembly is obvious.


Printing


I used PETG filament for this one because it's pretty tough stuff and can take a lot of abuse. I arranged the parts on the print bed like this:





I have a 1mm nozzle on UMMD and the print came out OK, but I recommend you use a smaller nozzle and print in 0.2 mm layers. The extra cylinder is there to help the hex shaft of the spinning clamp print nicely. You could just print 2 or 3 of the spinning clamps (your friends are going to want one of these tools when they see it) instead.

I printed a bright color so I'd be able to find the thing in the bottom of a bag or toolbox.


The Result


The clamps were printed in 0.2 mm layers. I used contact cement to glue a piece of rubber to the fixed clamp to keep it from slipping when you pull the wires tight. I also used a drop of hot melt glue under each Wago to ensure they'd stay put. Shown here in "storage" mode- a piece of wire will keep the two parts together in your tool box so they don't get lost/separated. 


The Wago lever nuts snap into the tool, but dimensions are critical for retention and depend on your printer settings, so you may find that they will pop out of one or both clamps when you twist thick wires. The solution is as easy as a single drop of glue on the bottom of each Wago when you assemble the clamps. If you use ABS to print, superglue will work. You might want to use other glue depending on the plastic you use to print the clamps. Hot melt glue seems to work well on the Wagos.

It's a good idea to glue a little piece of rubber to the fixed clamp so it's less likely to slip when you clamp it to a smooth table top and start pulling on the wires.

The CAD File


You can download the .stp file here and open it in almost any CAD program you like.

Video, or it didn't happen!




How to Use It

In case it isn't obvious from the video above, just cut two wires to equal lengths, strip the ends, and insert them into the Wagos, and snap the levers down. Put the spinning clamp in the chuck of your drill/screwdriver, clamp the fixed clamp to a table or or shelf or put it in a vise, pull the wires tight, and pull the trigger. Keep tension on the wires as they twist, and when you feel you have enough twists in the wires, let go of the trigger. Give them one last tug to "set" the twist and then release the wires from the Wagos.