# Filtering PWM output to stepper motor coil to read voltage drop of sense resistor

#### Travm

Joined Aug 16, 2016
363
I'm trying to simulate a simple coil and feeding it a pulse signal representative of a 25khz pwm signal. The current regulates itself half decently with only the coil and sense resistor in this simple circuit, but i'm trying to make it smoother. However no matter where I add a capacitor to this, it throws the voltages all over the place. Usually I get a negative voltage at the sense resistor, which doesn't make sense to me.

This is just simulation at this point, but is what i'm trying to do possible? and if so whats wrong with my thought process on this.
Here's an image of my super simplified stepper coil and sense resistor.

We're totally disregarding that in operation there would be 2 coils both driven by H-bridges.

Joined Mar 10, 2018
4,057
My guess is that you are seeing resonant effects when you add the
cap.

Regards, Dana.

#### Travm

Joined Aug 16, 2016
363
My guess is that you are seeing resonant effects when you add the
cap.

Regards, Dana.
Ive tried many things, including another inductor and cap, many values.
So what i'm trying to do isnt possible?

Another question, Dont caps absorb resonance? While Inductors create?

Last edited:

Joined Mar 10, 2018
4,057
Google this "java resonant circuits", several java demonstrations of
how resonance circuits work.

Basically energy is put into the circuit, and it will, under the right conditions,
transfer back and forth between the L and the C. If there is any loss, like a
resistance R, then the sinusoidal waveform that is created by the energy
exchange will also have an exponentially declining wave shape over time,
and ultimately all energy, if not replaced, will be dissipated as heat in the R.

Regards, Dana.

#### Travm

Joined Aug 16, 2016
363
Capacitor is in parallel always, I guess I didnt specify.
Series capacitors ring, in parallel they absorb, no?

#### crutschow

Joined Mar 14, 2008
31,097
To average/smooth the voltage, add a resistor from the sense resistor with a capacitor to ground.
That will minimize any resonant effects.
For a 45us pulse period, try an RC time-constant of a ms or so (such as 10kΩ and 100nF).

#### Travm

Joined Aug 16, 2016
363
To average/smooth the voltage, add a resistor from the sense resistor with a capacitor to ground.
That will minimize any resonant effects.
For a 45us pulse period, try an RC time-constant of a ms or so (such as 10kΩ and 100nF).
I was wondering about doing this.
This is simply filtering the vdrop @ the sense resistor right?
That may be the best way to achieve what i'm looking for.

Is the idea of actually filtering the current in the coil not something to pursue?
Dana left some heavy reading I haven't been able to sit down with yet.

#### ebp

Joined Feb 8, 2018
2,332
One thing it is very important to realize in simulations is that an ideal voltage source, which is what you get unless you specify otherwise, has zero impedance. That means that when the voltage goes to zero it isn't an open circuit but a short circuit.

Similarly, unless otherwise specified, passive components are normally "ideal" - inductors have no resistance, capacitors have no series or parallel resistance, resistors have no parallel capacitance or series inductance, etc.

Here's a little experiment:
Make a very simple circuit with a square wave source that swings from 0 V to 1 V at 1 kHz connected to a series circuit of a resistor set to zero ohms and an inductor of 100 µH. Run a transient analysis for 20 cycles or so, looking at the current through the inductor.
Repeat with the resistor set to 1 ohm, then some more experiments with different resistor values.

#### crutschow

Joined Mar 14, 2008
31,097
Is the idea of actually filtering the current in the coil not something to pursue?
I see no reason to do that, as it will tend to mess with the circuit operation.

#### Travm

Joined Aug 16, 2016
363
One thing it is very important to realize in simulations is that an ideal voltage source, which is what you get unless you specify otherwise, has zero impedance. That means that when the voltage goes to zero it isn't an open circuit but a short circuit.

Similarly, unless otherwise specified, passive components are normally "ideal" - inductors have no resistance, capacitors have no series or parallel resistance, resistors have no parallel capacitance or series inductance, etc.
I hadnt considered the voltage source going short circuit rather than open. I admit my understanding of simulations is limited. I also understand simulations and most of our theories and calculations are at best approximations of super complex physical phenomena we only partially understand, but for the most part are repeatable.

I will try this again with a BJT driving the circuit as in reality thats how this will work.

As for the inductor(motor coil) I have loaded spice with the series resistance from the datasheet.

If i had a circuit that appeared on the right track I would have tuned it up with all the actual values for the components I would use, however as soon as I add a capacitor, the voltage hits the fan.

#### Travm

Joined Aug 16, 2016
363
I see no reason to do that, as it will tend to mess with the circuit operation.
Filtering the current would make the circuit work better would it not? As in thats the objective, pwm to regulate current to a lower value. I understand the constant vibrating in teh coil can help overcome static friction by keeping the rotor moving, but in a perfect world, wouldn't constant smooth current be ideal?

#### crutschow

Joined Mar 14, 2008
31,097
but in a perfect world, wouldn't constant smooth current be ideal?
Yes.
But there's no ready way to do that in you coil with a capacitor.
The two ways to smooth the current more are to either increase the inductance or increase the PWM frequency.

#### Travm

Joined Aug 16, 2016
363
I forget now what I was reading, but it was suggested an L-C filter would clean up the line, but it got real messy everytime I included a capacitor. It did in fact level the coil current but the sense resistor and voltages went nuts

#### crutschow

Joined Mar 14, 2008
31,097

#### Travm

Joined Aug 16, 2016
363
Exactly where did you add the capacitor?
Honestly I think i tried every possible location parallel to motor coil.

#### Travm

Joined Aug 16, 2016
363
Figure 7 in the below document was my starting point.
Obviously i'm not using this driver, but I figured the current filtering should be the same no matter the driver.

#### Attachments

• 134 KB Views: 23

#### crutschow

Joined Mar 14, 2008
31,097
Figure 7 in the below document was my starting point.
That circuit has an inductor in series with the motor.
You can't arbitrarily leave that out of the circuit and expect the same results.
With no inductor, the drive current pulse is shorted through the capacitor instead of going through the motor.

#### ebp

Joined Feb 8, 2018
2,332
Think about the fundamental properties of capacitors and inductors in terms of changing the voltage across them and the current through them.

Try a simulation with a zero-resistance inductor across an AC (that is, swinging equal voltage positive and negative) square wave and look at the current. Use a very small resistance in series with the inductor - 1 µΩ should be OK. Look at the current in the circuit.

Replace the inductor with a capacitor and run another transient analysis.

Replace the square wave voltage source with a square wave AC current source and repeat the above two runs, this time looking at the voltages.

The tiny resistance is required so the simulator doesn't have to do a "forbidden" calculation. You'll see why. We need to keep it small so that we don't alter the circuit's behavior significantly.

dV/dt = i/C the rate of change of voltage across a capacitor is proportional to the current through the capacitor divided by the capacitance
di/dt = V/L

#### Travm

Joined Aug 16, 2016
363
That circuit has an inductor in series with the motor.
You can't arbitrarily leave that out of the circuit and expect the same results.
With no inductor, the drive current pulse is shorted through the capacitor instead of going through the motor.
Of course I included the inductor, why assume I didnt? However, no matter what when the capacitor was added it went wonky. Tried many many combinations values as well.