Sensing stepper motor winding currents - Page 1
Forum section: electronics / projects

author: hlavac
author_rank: Frequent Contributor
timestamp: February 21, 2015, 02:48:27 pm
content: I'm thinking about making a little tool for mesuring total current thru a bipolar stepper motor on my 3D printers, as setting current thru potentiometers on the driver boards seems to be very unreliable.It would plug between the stepper motor and driver board onto the four wires going to the stepper motor.I guess it would put small current sense resistor in series with each winding, measure the voltages, rectify them and sum the two rectified voltages to get the measure of the total current thru both wingings.But the devil is in the details and I'm not too experienced in the analog stuffMy naive implementation would consist of:resistor dividers getting the 30V-ish voltages from the ends of the shunts to within the allowable range of the opamps. The windings are driven from H-bridges with up to 25V so the ends will jump around... These will further attentuate the voltage from the shuts but what can I do?two instrumentation amplifiers to get the voltages across the two shunts referenced to my ground,precision rectifiers to flip the voltages to the positive side when the bipolar driver drives the current in the negative way,a summing circuit to add them together,simple RC element to collect and lowpass the overall voltage for use in the indicator part of the circuit (probably small microcontroller with ADC driving LED display or bargraph).I'm a bit worried about having to use symmetric power supply. Having to use two batteries sucks.Any good ideas on how to do this? Mybe some interesting components for current sensing?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: February 21, 2015, 03:14:50 pm
content: I should think this would be solvable in the first place based on the driver boards... are they really that bad? Get better ones, that actually work... This is all stuff that can be solved in the design phase. Or, if the driver board / controller datasheet simply doesn't tell you enough to be able to make a solid design... it doesn't get to play in your design. Simple as that.I'd suggest a hall effect type sensor, so you don't need all that isolation stuff. Yes it's possible to resolve a small shunt voltage drop over a high common mode voltage (even one that's rapidly switching), but the less you have to deal with, the better.Tim

author: hlavac
author_rank: Frequent Contributor
timestamp: February 21, 2015, 03:28:44 pm
content: I don't design the drivers, they are off the shelf stuff like the Pololu step sticks and compatible variants...One of the things I'm not sure about is - how to handle ground? I don't have a ground connection to the driver, and all four of the wires are jumping between 0 and 12/24V... My device is floating, does it matter at all? I'm a bit confused... do I pick one of the leads as my ground maybe? Other leads will then jump +/- 30Vish?

author: zapta
author_rank: Super Contributor
timestamp: February 21, 2015, 03:50:52 pm
content: Can't you use a DMM with current measurement capabilities? The current is applied also in steady state.

author: hlavac
author_rank: Frequent Contributor
timestamp: February 21, 2015, 03:55:47 pm
content: I could, two of them (there are two windings).

author: RR
author_rank: Contributor
timestamp: February 21, 2015, 04:02:16 pm
content: Can you measure before H bridge? that will be easierThis might help-https://www.eevblog.com/forum/projects/high-side-current-sense-circuit-jelly-bean-parts-only/msg577040/#msg577040

author: zapta
author_rank: Super Contributor
timestamp: February 21, 2015, 04:43:28 pm
content: What problem do you have with your drivers? I am using the rule to adjust up until it doesn't miss steps and then an extra 1/8 of a turn.Make sure everything moves smoothly with no mechanical obstruction. I had a problem for example with my spool holder that didn't turn smooth and created mechanical load on the x carriage that damaged the driver.

author: rob77
author_rank: Super Contributor
timestamp: February 21, 2015, 04:55:26 pm
content: Quote from: RR on February 21, 2015, 04:02:16 pmwas about to post the link to that thread, but you did the job for me

author: hlavac
author_rank: Frequent Contributor
timestamp: February 21, 2015, 05:04:41 pm
content: Quote from: zapta on February 21, 2015, 04:43:28 pmThe tiny smd trimmers for setting current are flaky, sometimes wipers seem to lose contact, and its hard to get feedback on what the current is (have to measure voltage on the tiny wiper while moving it...)

author: Richard Crowley
author_rank: Super Contributor
timestamp: February 21, 2015, 05:08:56 pm
content: 1) Put the current sense shunt in a common node like the power supply or the ground return. No reason to sense the current in each winding separately.2) You should not need any voltage dividers. A proper shunt will put out millivolts and will require amplification, NOT attenuation.3) Use a Hall-effect sensor which has very low burden and built-in amplification. Like Allegro ACS712https://www.sparkfun.com/products/8882

author: hlavac
author_rank: Frequent Contributor
timestamp: February 21, 2015, 05:24:21 pm
content: My interface to the circuit is just the motor wires. I'd have to pull out the driver module and put something in between it and the RAMPS board to measure on the low side.Millivolts across the shunt, but the shut is floating high in the sky as either end of it is connected to the driver voltage by the H-bridge at different timesOpamps usually require input voltages to stay between the opamp power rails or they malfuction.Anyway, I made acrazy simulation in Falstad's circuit simulatorthat seems to work

author: langwadt
author_rank: Super Contributor
timestamp: February 21, 2015, 05:34:05 pm
content: Quote from: zapta on February 21, 2015, 04:43:28 pmthat'll work for wimpy drivers and big steppers, setting the current higher that the stepper is rated will just cook it.I don't see the big problem, look at the datasheet and the current senses resistor, use voltmeter to set the reference voltage

author: rob77
author_rank: Super Contributor
timestamp: February 21, 2015, 06:56:13 pm
content: Quote from: hlavac on February 21, 2015, 05:24:21 pmexactly that's solved here:Quote from: RR on February 21, 2015, 04:02:16 pmyou just have to sense the current before the H_bridge (stepper controller module), it's worth of cutting a trace and use the circuit(instead of trying to sense at the motor wires)

author: zapta
author_rank: Super Contributor
timestamp: February 21, 2015, 07:52:51 pm
content: Quote from: hlavac on February 21, 2015, 05:04:41 pmTry better quality drivers then. For example, the Pololu Black Edition. They also have better heat dissipation due to the additional two layers.

author: langwadt
author_rank: Super Contributor
timestamp: February 21, 2015, 09:02:12 pm
content: Quote from: rob77 on February 21, 2015, 06:56:13 pmyou can't just measure the supply current, anything but the most primitive stepper driver is basically a switch mode converter , so the supply current is much less thanthe motor current

author: rob77
author_rank: Super Contributor
timestamp: February 21, 2015, 09:19:57 pm
content: Quote from: langwadt on February 21, 2015, 09:02:12 pmcan you name some examples ? because the most common ones (e.g. allegro A4988 , texas instruments DRV8825) are just a pair of H bridges with control logic and PWM + control for micro-stepping.

author: langwadt
author_rank: Super Contributor
timestamp: February 21, 2015, 11:52:44 pm
content: Quote from: rob77 on February 21, 2015, 09:19:57 pmthe ones you mentionthe PWM into an inductor basically makes it a buck converter, how else would you regulate say 1A in a 2 Ohm stepper from a 24V supply without setting the controller on fire?

author: Seppy
author_rank: Unknown
timestamp: February 22, 2015, 01:23:06 am
content: If you wanted to use something pretty nifty there are these IC'shttp://www.allegromicro.com/en/Products/Current-Sensor-ICs/Zero-To-Fifty-Amp-Integrated-Conductor-Sensor-ICs/ACS712.aspxShove one on each of the motor coils, or ideally have the 2 H-Bridge supply intercepted before it reaches either H-Bridge.EDIT: Didn't see Richard Crowley's post linking to allegro hall effect, pretty cool stuff they do

author: rob77
author_rank: Super Contributor
timestamp: February 22, 2015, 08:23:53 am
content: Quote from: langwadt on February 21, 2015, 11:52:44 pmi would strongly suggest you to study the mode of operation of those a bitbut i will not say that for now... i'll be politically correctso where in the data sheet you can find that BUCK-converter feature ?the IC will not burn down because it's mosfets are fully on and it dissipates only current squared times Rdsonit's the poor winding of the stepper who is suffering in this picturefrom the allegro fatasheet:QuoteandQuotesorry, no buck converter there

author: T3sl4co1l
author_rank: Super Contributor
timestamp: February 22, 2015, 09:32:35 am
content: Rob,That's the definition of a buck converter.Tim

author: rob77
author_rank: Super Contributor
timestamp: February 22, 2015, 06:30:14 pm
content: Quote from: T3sl4co1l on February 22, 2015, 09:32:35 ami know it's very similar , but it's not the samethere is no energy stored in the inductor in this case... the inductor (stepper's windoing) is converting the energy to mechanical, not storing it and releasing it... so technically it's not a buck converter.

author: langwadt
author_rank: Super Contributor
timestamp: February 22, 2015, 07:04:22 pm
content: Quote from: rob77 on February 22, 2015, 06:30:14 pmif it quacks like a duck ...consider a stepper that isn't moving, it doesn't make any mechanical energy, the energy stored and released from the inductor ends up the DC resistance of the inductorSame as a buck energy stored and released from the inductor end up in the load

author: rob77
author_rank: Super Contributor
timestamp: February 22, 2015, 08:24:41 pm
content: Quote from: langwadt on February 22, 2015, 07:04:22 pmok.. let's asume it's a buck converter (...sort off)but still there is no issue to measure the current at the controller input (finally back to the topic), because the input current is proportional to the current through the winding. so it completely makes sense to use a high side current sensing in front of the controller and then scale the readings accordingly to indirectly measure the current through the windings (quiescent current of the controller chip is insignificant in this case).

author: langwadt
author_rank: Super Contributor
timestamp: February 22, 2015, 10:34:41 pm
content: Quote from: rob77 on February 22, 2015, 08:24:41 pmYes _proportional_ but figuring out the ratio will involves a fair amount of guesswork, the right way to do it is to measure the reference voltage or the voltage over the sense resistor

author: T3sl4co1l
author_rank: Super Contributor
timestamp: February 22, 2015, 11:56:08 pm
content: Quote from: rob77 on February 22, 2015, 06:30:14 pmThis is probably a far more subtle argument than you are aware; however, it would only interfere with buck type operation on one condition, which isn't met here.The reason it is subtle is:- An induction motor performs work based on applied flux, not by applied current. Yes, the current shows up as a necessary, inseparable part of operation, but the work performed is proportional to EMF. Such motors are mechanical-to-EMF converters. Examples: DC (brushed, or brushless with static (e.g. Hall effect) commutation), synchronous AC, AC induction (non-synchronous) less slippage.- A reluctance machine (whether a motor, solenoid, relay coil, etc.) does operate by current; however, the work is again dependent upon flux. As the inductance goes from low to high (say, as the solenoid armature closes, reducing space for magnetic field and therefore removing work from the magnetic field and converting it to mechanical work), in order for the current to remain constant, more and more flux must be added to the coil, which means if you merely apply a fixed voltage, current must dip as the solenoid closes, or if you apply a constant current, the voltage must spike.- What's even more subtle than this, is that a real stepper motor is a combination of these types. This is a necessity resulting from the small step size: to implement a stepper using an induction design would require N poles for 180/N degrees per step, and would be expensive to produce. A pure reluctance machine can be easily designed for fine steps (by notching the rotor and driving complementary notched stators in quadrature), but has weak holding force (the force is due to the difference in magnetic field strengths between the two sides of each notch, which isn't much distance for the field to drop off over, especially when made of iron parts). Instead, a hybrid combination is used, so that nearly the strength of an induction machine is produced, while doing it with only a pair of coils and a little machining. (I forget exactly how this is achieved, but this is the general result. Proof: if a stepper motor produces voltage -- as a generator -- for every step as it spins, it is of this type. If it does not generate, or the amount it generates is suspiciously small, it's a reluctance type.)The consequence is, electrically, a stepper motor must be driven as a hybrid of these two methods. You must deliver enough flux (i.e., a spike of voltage for some duration of time) to build the magnetic field, in addition to the flux (voltage / frequency) required to advance the rotor due to its EMF.If you look at only the V/I conditions at the terminals, averaged over a typical cycle (at constant frequency, say at a typical 'cruising' speed), you will measure real and imaginary components of current flow. The real part can only ever do work or dissipate power; the imaginary part can only ever recycle it. Physically, some of that real work will be done by induction as well as reluctance mechanisms, and some of the imaginary work will be done by stray fields (i.e., true leakage inductance) as well as mechanical effects (i.e., alternately stretching and squashing the magnetic field). But the point is, electrically, we don't care what the physical mechanisms are; we just care that, there's a real part doing work, and the imaginary part we can recycle with diodes, or play tricks with on energy (like using it for an implicit buck converter). And so, here's the catch, and where my footnote comes from, all the way at the top:The condition is, as long as the input frequencies are orthogonal to the rotational frequencies, over the course of one cycle -- there cannot be any real power consumed of those frequencies. They must be recycled, reactively and therefore inductively*, back to the circuit.(*Well, I guess inductively isn't a necessity. It could be capacitive under suitable conditions -- maybe not for a stepper motor, but a synchronous AC machine can be used to produce capacitive power factor. But whichever phase it is, it's not on the real axis!)Indeed, often times this is forgotten -- bad motor controllers will succumb to such failure modes at the edges of operation. An old fashioned L297/298 pair will typically PWM at 10-20kHz; if you attempt to spin the motor above maybe 1kHz, operation shifts noticeably, as the number of "on" pulses per winding drops from more than 4 (reaching a reasonably steady-state current regulation condition before switching off), down to 2 and 1, and finally to zero as the winding isn't even able to develop rated current in the allotted time (or discharge fully to zero while off!).Although the pulses of the L297 are not fixed frequency or phase, the orthogonality condition still applies as it does. When the applied flux gets terminated early (the winding gets turned off, due to peak current control, before the clock frequency would've turned it off ideally), the holding force or available torque both drop accordingly. When the current-control pulses are so coarse that they take up appreciable chunks of the operating time, the drop in torque becomes so severe that, eventually, it simply stops rotating at all, and stalls (torque < friction). This is ultimately why all steppers have a maximum operating frequency, but this is furthermore what limits the practical operating frequency of a PWM type stepper motor driver.Now, I'm not saying this is what's happening in the OP's situation; this is just about steppers.FYI,Tim

author: langwadt
author_rank: Super Contributor
timestamp: February 23, 2015, 12:45:14 am
content: The limiting factor on stepper speed is generally that you run out of voltage to counter the inductance and emf so you can no longer ramp the current up fast enough, doesn't really matter if you use switching, linear or series resistors to limit the current.The other one is that in any kind of switching controller, your switching frequency needs to be substantially above the frequencies you are trying to generate to faithfully reproduce the desired waveform, as an example a class-d audio amplifier.

author: Siwastaja
author_rank: Super Contributor
timestamp: February 24, 2015, 03:39:08 pm
content: Quote from: rob77 on February 22, 2015, 06:30:14 pmActually, it is storing it... That's why the freewheeling diodes play a very important role - and that's why synchronous rectification is used. Windings of course also play the role of the load, but that doesn't change the fact that it's a buck converter. Of course, the stored energy is used by the motor itself (minus losses in freewheeling diode / FET).Similarly, a boost LED driver which combines the role of the diode and the LED is still a boost converter.A PWM motor controller converts higher input voltage to lower output voltage, and low input current to higher output current (yes, really!). You can measure it. That's the very definition of a buck converter. This is the same for high-power industrial VFD's, electric vehicle motor drives (brushed DC or AC, doesn't matter), and yes, steppers. The difference is that steppers usually have quite a lot of resistance in the windings, too, and can survive "holding" DC current; hence, the efficiency of a stepper is poor. But the PWM stepper driver is still a buck converter and the controller part has a great efficiency even if the motor does not.So, you were just plainly wrong. It happens, life goes on. This was once a learning point for me, too. It's great when you learn things.

author: rob77
author_rank: Super Contributor
timestamp: February 25, 2015, 01:03:16 pm
content: Quote from: Siwastaja on February 24, 2015, 03:39:08 pmI think Tim explained it above very acuratelybtw.. if my statement "it's very similar , but it's not the same" was plainly wrong, then should i assume you're stating the exact opposite ? because the opposite of my statement which would be "it is the same" is even more far away from realitybut anyways... i learned something... any inductive load with PWM control which requires a fly-back diode (or a synchronous switch replacing the fly-back diode) is a buck converternow the remaining mystery is how to name the real buck converter (electric energy on both input and output) to distinguish it from the many other "buck converters"

author: hlavac
author_rank: Frequent Contributor
timestamp: February 25, 2015, 03:18:23 pm
content: I absolutely love these allegro current sensor chips!Don't they make a version that returns voltage proportional to the absolute value of the current? That would save me the rectifying/flipping...Or maybe I could whack a bridge rectifier around the sensor? That will take off some of the voltage from the motor (two diode drops) and require beefy diodes, but that should not matter too much for the application I intend (the motors will be probably static, just in unknown phase/microstep position)...

author: Siwastaja
author_rank: Super Contributor
timestamp: February 25, 2015, 11:45:48 pm
content: Quote from: rob77 on February 25, 2015, 01:03:16 pmNo need to, as there is no mystery; a buck converter is something that takes in high volts, low amps, and outputs low volts, high amps. A motor controller does exactly this; the motor wires have more current flowing than the input wires, but at a lower voltage. It's the textbook example of a buck converter, and it has "electric energy" on both sides: at the power supply, and at the motor terminals.And, I have never seen a practical converter of any kind that only "outputs" "electric energy" (whatever that would ever mean) - they always have a useful load connected! What do you do with a DC/DC if you don't have any load, anyway?Heck, in some cases (low-inductance motors), the motor controller may even have the inductor present, in which case it's a standard stand-alone buck converter, as it is always drawn, with a motor connected to its output like any load - which makes it two inductors in series.But it only makes sense to work with one inductor instead of two inductors in series when the one happens to have enough inductance on its own. You are not getting rid of any basic circuit elements of a buck converter; the inductor is there anyway, in the motor. This of course limits the possible applications; the product is only be a buck controller for motor control applications, not a generic one.

author: rob77
author_rank: Super Contributor
timestamp: February 27, 2015, 01:12:42 pm
content: Quote from: Siwastaja on February 25, 2015, 11:45:48 pma DC/DC step down converter is a standalone circuit which will work regardless of attaching a load => buck convertera pwm motor controller is not complete buck convereter without the inductance of the motor (it won't convert anything without the motor's inductance) , therefore the motor itself must be a integral part of the buck converter => the controller alone is NOT a buck converter like the DC/DC one. and once you consider the motor's inductance as a integral part of the circuit, then there is no electrical output energy anymore, it's mechanical output energy at the motor's shaft