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.


28 comments:

  1. What am I missing in the schematic? As I read that, if the motor starts pushing back-EMF, it will go back through R1, but then you expect it to also go through R2 to turn on the transistor, then go through R3 despite the huge resistance. After going back through R1, why wouldn't it (at least in part) just go back through Power_in instead of bothering with R2 and especially R3?

    ReplyDelete
    Replies
    1. Under normal conditions, there's about 0.5V drop across the diode. That holds the transistor off and all the current from the power supply goes to the motor. When the voltage at the output side rises above the power supply voltage, the transistor turns on creating a low resistance path to ground through the 33 Ohm resistor. When the output voltage again drops to about 1/2V below the power supply voltage, the transistor turns off and current goes through the diode again to the motor from the power supply.

      Delete
  2. nice one.. i am using a delta ac servo drive,wich has an internal resistor in the driver ( 30k/200watt) for braking and emf. the supplier demonstraties the safety of the drivers by yanking the gantry as hard as he can from side ro side for a minute while the driver was running a program... does absolutely no harm.. my eyes where almost. popping out, if you do this you will fry every 3d printer..


    could you alternatively drive the power to the drivers through an optocoupler?? this beqause i use 2 stacked 85 amp server psu's in series for my printer.. every drive a separate mosfet breakout board or does the server psu still gets fried when back emf occurs?

    i have 12 steppers and 2 servo's on my rig so needing to protect alot!!
    or 8s there a 9ever voltage protection circuit for the controller input?

    ReplyDelete
    Replies
    1. There's no way to pass power through an optocoupler.

      Everything connected to the input side of the REDump circuit is protected. If a single power supply is used for all the motors/drivers, and the total current is under about 10A (limited by the 15A diode on the REDump board), you could use a single REDump circuit, probably best mounted at the power supply, and then split all the motor/driver power leads there, from the output side of the REDump. Be sure to connect the controller power input on the protected input side of the REDump circuit.

      Delete
  3. ohh yeah flipperwinkel.nl sells heavy wattage resistors off the shelf ( are used a lot in pinball machines)

    ReplyDelete
  4. Alternative for your BOM to be able to source all the parts from one place:

    Mouser has a STR15100SS_AY_00301 as Mouser # 241-STR15100SSAY0301 for D1
    They also have the UVR2A102MRD6 as Mouser # 647-UVR2A102MRD6 for C1

    ReplyDelete
  5. Do you have opinions about silkscreen labeling for variants? I'm looking making at a variant that takes the more widely-available (right now) TO-220 dual schottky diodes (e.g. VS-30CTQ100-M3, NRTSV30H120CTG) and is more compact (needs to fit in a constrained space). I started with your design but it won't look the same way when I'm done.

    ReplyDelete
    Replies
    1. I don't understand the question, but it should be easy to modify the layout for whatever parts you want to use. Just go to the schematic, enter the new part and select the package and footprint that match. The rest should update automatically, I think, though you may have to do some rerouting of traces to make the new package work.

      Delete
    2. Sorry, my question was very poorly formed. I've used KiCad on and off for a decade. It was only a question about your preference. Let me try again.

      I'm redesigning it and will probably make the new design available. I don't know how much credit you want to claim vs. the original gecko drive circuit. I'd seen RED circuit years ago, but I'm starting from your implementation, and don't know if you want credit on the back silkscreen, or would rather not get questions about my reimplementation. ☺

      Delete
    3. No credit required. Have at it. Send me a link to your design when it's done.

      Delete
    4. Will share!

      How did you arrive at the 24-36V range for input voltage? The 1K/33R divider across the darlington BE junction will keep Vbe well below the max 5V as far as I can tell, and everything else is at least 100V max. The simulation has a 24V input peaking at about 91V across the power resistor, so if that was the problem I'd think 36V would be a stretch. Is it a limit based on the particular servomotors you are using and their inductance?

      Delete
    5. Two things- power dissipated in the diode- 36V motors typically take more current than the 24V motors, getting the diode/PCB even hotter, and an unknown maximum voltage spike at the output. I feel pretty confident the board will work for 24-36V, but not so sure if you go higher.

      Delete
  6. I haven't measured the space that I might want to put it in (I'm thinking of converting a mill power feed to servo drive, and it would live in the existing case), so I might have to change it substantially before fabricating it, but I put the WIP up at https://gitlab.com/mcdanlj/ReturnedEnergyDump

    A couple pictures at https://social.makerforums.info/web/@mcdanlj/108734148151791530

    I added a netclass to define a 4mm primary track width, and an extra track width of 2mm. I used that for ends of traces where 4mm can't fit. The 4mm traces should substitute for those really thick traces for the pads you used. I'm just going to solder wires in rather than use a connector. I shrank the board a bit, but could easily shrink it more. I chose different mounting holes.

    A lot of the 4mm traces are ridiculously oversized for current, but they double as part of the heat sink for the diode during normal operation. I'm sure the board won't sink 10W if the diode is dropping .67V with 15A of current, so that would need a heat sink on the diode base, but I don't ever foresee doing that myself.

    ReplyDelete
  7. Looks good! Mastodon looks interesting, too. Thanks!

    ReplyDelete
    Replies
    1. Thanks!

      I've also been thinking of integrating an optionally-populated optocoupled fault signal which could be used by a servo controller. There should be plenty of room for it. And it would be specifically handy for my use case, where in normal use the motor is disconnected and can freewheel down and would spike only when driving the mill table into hard stops, or in case of a bad crash, where I'd love to have the controller sense and stop.

      At some point I'd like to characterize this on the bench with my scope and a few different motors.

      By the way, some of your old Google+ and Smoothie forum posts were imported as part of the migration to Maker Forums when Google+ went away and Arthur wanted to leave wikidot, so if you ever use your google account to log in at https://forums.makerforums.info/ you'll own them all. https://forum.makerforums.info/t/please-use-google-login-once/326 for details on that. And that login will also get you an invite to the maker forums Mastodon. No pressure or expectation, only if you are interested.

      Delete
    2. The error detect could be a useful feature. I think my motors have some built in protection against the high voltage spike and will output an alarm signal if the protection ever kicks in, but that occurs at 60V (I think) where it would already have destroyed a switching power supply and almost anything else connected to it, so an alarm external to the motors could be useful.

      I'm not a huge fan of so-called social media. Decades ago I used to use usenet, but it devolved to a cesspool of trolls, hate, and general all-around idiocy. I had an FB account for a couple months back in 2008 or so, and realized what a potential disaster it was and deleted my account. I never got on twitter- didn't seem like a good idea from the start. More recently I was on reddit but found it similar to usenet, especially with regard to idiocy.

      Since your posts I have been looking at Mastodon. It looks like it might be worth trying.

      Delete
    3. Thanks for the thought on error detect. I'll put some more thought into that.

      I have come think that active moderation is essential for a healthy community. Not censorship, just rules that people agree to and people who help remind others of them. As a moderator on Maker Forums, I have occasionally reached out to folks who are upset with each other in private and helped smooth over trouble, and one good thing about an edit button there is that people can go back and rewrite to be kind when they have gotten heated. ☺

      I wish Mastodon had an edit button. The underlying protocol has support for it. But at least it decentralizes control and gives each user more control than whatever Twitter et al. might deign to bestow at any particular point in time. The content rules for stuff posted on our Maker Forums Mastodon are pretty simple — https://social.makerforums.info/terms — it is relatively new but so far zero attacks to moderate. Fingers crossed. ☺

      Delete
  8. I have a question about the Protection Circuit (Returned Energy Dump). if you have 3 Brushless Motors connected to 3 ESC's do you need 3 Protection Circuit (Returned Energy Dump)? Would I have to connect each motor to this circuit in order to protect the power supply ESC's and the motor itself? 1 Protection Circuit (Returned Energy Dump) for each motor?

    ReplyDelete
    Replies
    1. The ReDump circuit won't protect the ESC or the motor, but it will protect the power supply and anything else connected to it. The ReDump is good for a maximum of about 10A, so unless your BLDCs are low current type (they usually aren't) you'll need one ReDump per motor.

      Delete
  9. Hello, Thank you for this project! My CNC project is built around JMC motors so this is really usefull
    I am about to build this board for quite a few motors, do you have any recomendations before I start ?
    Only one component from your BOM is out of stock and I found this TIP147FTU-ND instead, will it be okay ?
    WHat should I update if I drive my motors at 48V and their rating is 400W instead of your 78W example? Thanks!!!

    ReplyDelete
    Replies
    1. The leads in that TO3P package have wider spacing so you'll want to modify the PCB layout accordingly.
      The peak current drain for a 400W motor is going to be very high, much higher than this circuit can handle. I think you'd better find a different circuit!

      Delete
    2. I see, would it be possible to just scale up some components from your circuit?
      Or use some in parralel? Maybe using multiples resistances in parralel instead of one? To make it possible to handle more power, but I guess others components would need a scale up as well?

      I have no extensive electrical knowledge and would appreciate any help
      You think there is an other kind of circuit that could protect my motors as well? Before I found your circuit I never heard of protection like this but it make sense to have one I think

      Delete
    3. I'm not an expert in this area, so I'd suggest that you do what I would do- spend some time with your friend Google...

      Delete
  10. Does the circuit work just as well without the capacitor? Is it sharing the fault absorption with the transistor +resistor? I guess its effectiveness depends on the shape of the back EMF pulse (magnitude and duration)

    ReplyDelete
    Replies
    1. No, at least not generally. You don't want to to turn on the transistor for transients. You only want it for large sustained high-energy pulses.

      Delete
  11. Is this circuit "needed" for anything involving high powered steppers? If you're running a similar sized stepper but only at 50rpm maximum, is this sort of thing needed, to protect both from actual crashes and from when an e-stop button is hit to cut power AND command a motor to stop? Or only if they will be run at high speeds? Where would it go in the case of using a power supply, a microstepping driver unit, and a big stepper? Between the power supply and the driver unit surely? I guess that means it would not protect the motor's own driver unit from electrical damage if the motor crashes in to something, protecting only other things powered off the same supply rail? Thanks

    ReplyDelete
    Replies
    1. For a low speed stepper application it's probably not needed. This circuit protects things on the power supply side of the circuit, not the motor side. It will protect the power supply and other things connected to that supply.

      Delete

Leave comments or a questions here and I'll try to post a response as soon as I can.