Author Topic: Sensing stepper motor winding currents  (Read 12883 times)

0 Members and 1 Guest are viewing this topic.

Offline hlavacTopic starter

  • Frequent Contributor
  • **
  • Posts: 536
  • Country: cz
Sensing stepper motor winding currents
« on: February 21, 2015, 02:48:27 pm »
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 stuff :)

My 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?
« Last Edit: February 21, 2015, 02:50:27 pm by hlavac »
Good enough is the enemy of the best.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21606
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Sensing stepper motor winding currents
« Reply #1 on: February 21, 2015, 03:14:50 pm »
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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline hlavacTopic starter

  • Frequent Contributor
  • **
  • Posts: 536
  • Country: cz
Re: Sensing stepper motor winding currents
« Reply #2 on: February 21, 2015, 03:28:44 pm »
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?
Good enough is the enemy of the best.
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6189
  • Country: us
Re: Sensing stepper motor winding currents
« Reply #3 on: February 21, 2015, 03:50:52 pm »
Can't you use a DMM with current measurement capabilities? The current is applied also in steady state.
 

Offline hlavacTopic starter

  • Frequent Contributor
  • **
  • Posts: 536
  • Country: cz
Re: Sensing stepper motor winding currents
« Reply #4 on: February 21, 2015, 03:55:47 pm »
I could, two of them (there are two windings).
Good enough is the enemy of the best.
 

Offline RR

  • Contributor
  • Posts: 30
  • Country: cz
Re: Sensing stepper motor winding currents
« Reply #5 on: February 21, 2015, 04:02:16 pm »
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6189
  • Country: us
Re: Sensing stepper motor winding currents
« Reply #6 on: February 21, 2015, 04:43:28 pm »
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.
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Sensing stepper motor winding currents
« Reply #7 on: February 21, 2015, 04:55:26 pm »
Can you measure before H bridge? that will be easier

This might help-
https://www.eevblog.com/forum/projects/high-side-current-sense-circuit-jelly-bean-parts-only/msg577040/#msg577040

was about to post the link to that thread, but you did the job for me  ;) :-+
 

Offline hlavacTopic starter

  • Frequent Contributor
  • **
  • Posts: 536
  • Country: cz
Re: Sensing stepper motor winding currents
« Reply #8 on: February 21, 2015, 05:04:41 pm »
What problem do you have with your drivers?

The 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...)
Good enough is the enemy of the best.
 

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4317
  • Country: us
  • KJ7YLK
Re: Sensing stepper motor winding currents
« Reply #9 on: February 21, 2015, 05:08:56 pm »
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 ACS712
https://www.sparkfun.com/products/8882
 

Offline hlavacTopic starter

  • Frequent Contributor
  • **
  • Posts: 536
  • Country: cz
Re: Sensing stepper motor winding currents
« Reply #10 on: February 21, 2015, 05:24:21 pm »
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 times :)
Opamps usually require input voltages to stay between the opamp power rails or they malfuction.

Anyway, I made a  crazy simulation in Falstad's circuit simulator that seems to work ;)
Good enough is the enemy of the best.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4391
  • Country: dk
Re: Sensing stepper motor winding currents
« Reply #11 on: February 21, 2015, 05:34:05 pm »
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.

that'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
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Sensing stepper motor winding currents
« Reply #12 on: February 21, 2015, 06:56:13 pm »

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 times :)
Opamps usually require input voltages to stay between the opamp power rails or they malfuction.



exactly that's solved here:

Can you measure before H bridge? that will be easier

This might help-
https://www.eevblog.com/forum/projects/high-side-current-sense-circuit-jelly-bean-parts-only/msg577040/#msg577040

you 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)
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6189
  • Country: us
Re: Sensing stepper motor winding currents
« Reply #13 on: February 21, 2015, 07:52:51 pm »
What problem do you have with your drivers?

The 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...)

Try better quality drivers then. For example, the Pololu Black Edition. They also have better heat dissipation due to the additional two layers.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4391
  • Country: dk
Re: Sensing stepper motor winding currents
« Reply #14 on: February 21, 2015, 09:02:12 pm »

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 times :)
Opamps usually require input voltages to stay between the opamp power rails or they malfuction.



exactly that's solved here:

Can you measure before H bridge? that will be easier

This might help-
https://www.eevblog.com/forum/projects/high-side-current-sense-circuit-jelly-bean-parts-only/msg577040/#msg577040

you 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)

you 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 than
the motor current


 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Sensing stepper motor winding currents
« Reply #15 on: February 21, 2015, 09:19:57 pm »

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 times :)
Opamps usually require input voltages to stay between the opamp power rails or they malfuction.



exactly that's solved here:

Can you measure before H bridge? that will be easier

This might help-
https://www.eevblog.com/forum/projects/high-side-current-sense-circuit-jelly-bean-parts-only/msg577040/#msg577040

you 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)

you 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 than
the motor current

can 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.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4391
  • Country: dk
Re: Sensing stepper motor winding currents
« Reply #16 on: February 21, 2015, 11:52:44 pm »

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 times :)
Opamps usually require input voltages to stay between the opamp power rails or they malfuction.



exactly that's solved here:

Can you measure before H bridge? that will be easier

This might help-
https://www.eevblog.com/forum/projects/high-side-current-sense-circuit-jelly-bean-parts-only/msg577040/#msg577040

you 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)

you 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 than
the motor current

can 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.

the ones you mention :) the 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?


 

Offline Seppy

  • Supporter
  • ****
  • Posts: 189
  • Country: au
  • Curious
Re: Sensing stepper motor winding currents
« Reply #17 on: February 22, 2015, 01:23:06 am »
If you wanted to use something pretty nifty there are these IC's
http://www.allegromicro.com/en/Products/Current-Sensor-ICs/Zero-To-Fifty-Amp-Integrated-Conductor-Sensor-ICs/ACS712.aspx

Shove 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 :)
« Last Edit: February 22, 2015, 10:04:25 pm by Seppy »
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Sensing stepper motor winding currents
« Reply #18 on: February 22, 2015, 08:23:53 am »

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 times :)
Opamps usually require input voltages to stay between the opamp power rails or they malfuction.



exactly that's solved here:

Can you measure before H bridge? that will be easier

This might help-
https://www.eevblog.com/forum/projects/high-side-current-sense-circuit-jelly-bean-parts-only/msg577040/#msg577040

you 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)

you 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 than
the motor current

can 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.

the ones you mention :) the 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?

i would strongly suggest you to study the mode of operation of those a bit ;) but i will not say that for now... i'll be politically correct :D

so 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 Rdson ;) it's the poor winding of the stepper who is suffering in this picture ;)

from the allegro fatasheet:
Quote
Internal PWM Current Control. Each full-bridge is controlled by a fixed off-time PWM current control circuit that limits the load current to a desired value

and

Quote
Synchronous Rectification.  When a PWM-off cycle is triggered by an internal fixed-off time cycle, load current recirculates according to the decay mode selected by the control logic.  This synchronous rectification feature turns on the appropriate FETs during current decay, and effectively shorts out the body diodes with the low FET R DS(ON) .  This reduces power dissipation significantly, and can eliminate the need for external Schottky diodes in many applications.


sorry, no buck converter there ;)
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21606
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Sensing stepper motor winding currents
« Reply #19 on: February 22, 2015, 09:32:35 am »
Rob,

That's the definition of a buck converter.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Sensing stepper motor winding currents
« Reply #20 on: February 22, 2015, 06:30:14 pm »
Rob,

That's the definition of a buck converter.

Tim

i know it's very similar , but it's not the same ;) there 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.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4391
  • Country: dk
Re: Sensing stepper motor winding currents
« Reply #21 on: February 22, 2015, 07:04:22 pm »
Rob,

That's the definition of a buck converter.

Tim

i know it's very similar , but it's not the same ;) there 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.

if 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 inductor 

Same as a buck energy stored and released from the inductor end up in the load




 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Sensing stepper motor winding currents
« Reply #22 on: February 22, 2015, 08:24:41 pm »
Rob,

That's the definition of a buck converter.

Tim

i know it's very similar , but it's not the same ;) there 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.

if 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 inductor 

Same as a buck energy stored and released from the inductor end up in the load


ok.. 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).
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4391
  • Country: dk
Re: Sensing stepper motor winding currents
« Reply #23 on: February 22, 2015, 10:34:41 pm »
Rob,

That's the definition of a buck converter.

Tim

i know it's very similar , but it's not the same ;) there 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.

if 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 inductor 

Same as a buck energy stored and released from the inductor end up in the load


ok.. 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).

Yes _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
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21606
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Sensing stepper motor winding currents
« Reply #24 on: February 22, 2015, 11:56:08 pm »
i know it's very similar , but it's not the same ;) there 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.

This is probably a far more subtle argument than you are aware; however, it would only interfere with buck type operation on one condition[1], 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).

[1] 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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf