 # Calculating current...

Greetings,

My question involves the use of a Mega2560 R3 to measure and compare the current through a 12v dc linear solenoid. Is it feasible to measure the voltage through the solenoid, knowing the resistance of the solenoid/circuit, to calculate the current passing through the solenoid/circuit without using another IC, using only the Mega?

Also, the circuit is a low frequency(~300-600hz) pwm signal driving the high side of the solenoid.

Thanks,

Bill

If you are passing a PWM current through the solenoid its inductance will have a big impact on the current. You could only use the voltage and resistance if you have a constant DC current.

You could put a low resistance (0.001ohm ?) resistor in the circuit and measure the voltage drop across that. The ADC in the Mega can measure the differential voltage between 2 analog pins and contains an amplifier to increase the voltage to match the range of the ADC.

You would need to measure the current at several points in each PWM cycle to get useful information.

...R

use a DC current sensor and a capacitor on its output to filter the peaks / or use software to filter. just using the analog input is not working correct as the waveform is very complex. lots of harmonic signals.

pwm signal driving the high side of the solenoid.

That makes no odds.

Use ohms law for the DC case. Then take that and work out the inductive reactance. ( 2Pi F L ) Then do a vector addition of the resistance ( at 0 degree phase ) and the reactance ( -90 degree phase )

You get a current vector representing a current phase shifted from the resistive load. A projection of this vector onto the real axis will give you a current value you can use to calculate power.

AFIK...

The inductive reactance formula is only valid for a sine wave.

PWM is square waves, so you can't directly use the same formula.

Robin, I have looked into the solenoid inductance, and from what I can discern the initial inductance to get the solenoid moving will be the highest, after that point the solenoid is basically always on the move and the actual inductance lowers considerably allowing for more uniform measurement until the next "start from rest" cycle. Upon startup I can "fire up" the solenoid to say 50% DC, then after things have settled for a second I can begin measuring current through the circuit. It's a theory at this point but wondering if it makes sense to you. I am not opposed to adding a current sensing IC to the circuit just considering the feasibility and "easability" of the mega to measure.I will likely just include the extra hardware and a little software as opposed to trying to use just the mega as its gonna have a lot going on as is.

Thanks,

Bill

Billdefish: wondering if it makes sense to you.

Sorry, Bill, that's far beyond my pay grade :)

I know a little about digital stuff but virtually nothing about analogue stuff.

...R

"that's far beyond my pay grade"

Lol. Either way I appreciate your input. It's always nice to have someone outside the box even if they are taping up the box with you in it. :)

Bill

In a solenoid (ie, something like a pinball solenoid, not a solenoid-wound inductor), the inductance is at first much lower, until the core is fully engaged. Once the core is fully bottomed out, the inductance does not change.

If the PWM is fast enough that the current has very little ripple in it, then you can wait long enough for it to stabilize and then measure the current. However, this relies on the PWM duty cycle remaining the same.

Hmm… I think at that point, only the resistance limits current. So (Vcc x duty cycle)/I should equal the DC resistance of the solenoid.

Imagine this: a 50% PWM from 0-12V can be broken into a 6Vdc signal with a 50% duty cycle AC squarewave of 6Vpeak. The DC component of the stabilized current will come from 6Vdc / 36 ohms = 166.66mA.

So for a solenoid with the core fully engaged and no longer moving, and waiting long enough for the current to stabilize:

Assume a solenoid inductance of 50mH and a DC resistance of 36 ohms. The time for an RL circuit to stabilize is 5Tau, where Tau = L/R. So the time to stabilize current must be equal to or greater than 5 x 50x10^-3 / 36 = 6.9444ms or about 7 milliseconds.

The ripple on the current will be due to the squarewave component across the combined inductance and resistance. However, you can’t just use XL = 2 x pi x freq x inductance, as stated that only works with a sine wave. Instead, we will look at the charge/discharge time.

I = Imax(1 ? e? t/?au )

Imax = 6V (the peak value) / 36 ohms (the DC resistance) = 166.67mA

Tau = 50mH/36 ohms = 1.3889ms
t = 0.5 (50% duty cycle) x 1/freq of PWM
To get a reliable measurement, I’d suggest the ripple current should be <= 1/20th of the DC current. At 50% duty cycle, that is about 8mA.

8x10^-3 = (6/36)(1 ? e? (0.5/f)/(0.05/36) )

48x10^-3 = 1 ? e? (0.5/f)/(0.05/36)
1 - 0.048 = e? (1/(2f))/(0.05/36)
ln(0.952) = ? (1/(2f))/(0.05/36)
-ln(0.952) x (0.05/36) = (1/(2f))
f = 1/(-ln(0.952) x (0.05/36))
f = 14.6387kHz

So if you can use a PWM of at least 15kHz (higher is better), then you can simply measure the current with a small series resistor.

Otherwise, you could use 300 to 600Hz, and add a lowpass filter between the series current sense resistor and the Arduino. It’ll require a fairly low frequency knee, and will respond more slowly than if you just used fPWM >= 15kHz.

If you have a signal generator with adjustable DC offset and an oscilloscope, you can test it.

rogerClark: AFIK... The inductive reactance formula is only valid for a sine wave. PWM is square waves, so you can't directly use the same formula.

Yes but it is close enough, I suppose you could do a Fourier analysis of the rectangular wave and apply it to each harmonic but the contribution of each harmonic would drop off quite quickly.

My main point was not to have the OP calculate the current but to show him that the concept of current in an AC circuit is a two dimensional quantity, not a simple figure like he assumes.

and from what I can discern the initial inductance to get the solenoid moving will be the highest,

No the inductance is always the same, you might mean current here.

and the actual inductance lowers considerably

Again no the inductance does not change.

Upon startup I can "fire up" the solenoid to say 50% DC, then after things have settled for a second I can begin measuring current through the circuit.

There is a hysteresis effect where it takes more energy to start a thing moving than to keep it moving, this is due to the inertial mass. So once you have got it moving at say 50% you could drop it down to 40% to keep it moving.

Are you trying to measure the current -while- the solenoid core is in motion?

Inertia does not stop something from moving. I think you are thinking of stiction aka static friction, -that- is the property where friction is higher between two surfaces before they start moving. Inertia just means it takes longer to come up to speed.

polymorph,

Yes, I am wanting to measure the current through the solenoid as a means of more accurately controlling it.The system voltage is 11vdc-14vdc adn the solenoid max current in limited to 1.1A. Just measuring the voltage drop doesn't quite deliver the desired results although it functions I would prefer more precise control/measurement. And you are correct when referring to the static friction, guess I had inductance stuck in my head for some reason. The frequencies this project requires are 50hz, 293hz, and 585hz, give or take a few hz so 15khz is out of the question. The solenoid connected to the 293/585hz outputs duty cycle is constantly varying depending on the position of a potentiometer. Both solenoids control a pressurized hydraulic system which must meet certain criteria for proper operation. I do have a function generator but no scope as of yet.

Bill

So… what “linear solenoid” are you using? I think I’m not understanding which one you are using.

I thought you meant an on-off solenoid. Like a pinball solenoid.

Do you mean a linear actuator?

polymorph: Inertia does not stop something from moving. I think you are thinking of stiction aka static friction, -that- is the property where friction is higher between two surfaces before they start moving. Inertia just means it takes longer to come up to speed.

No inertia is the initial resistance to a change in the velocity of movement it is proportional to mass and has nothing to do with static friction which is also a factor for some sorts of friction. Ever noticed how you can push a car so much eiser once it is rolling.?

Inertia is the continuing resistance to change in velocity. You can push a car easier after it is moving because you are no longer altering the speed, so you only have to overcome the rolling resistance. Inertia does not change.

The solenoid in question is an automotive transmission pressure control solenoid.

So this is not an on-off device? But one that is continuously variable?