Current measurement and control

Thread Starter

Dream-

Joined Nov 26, 2010
69
I am working on a research project that requires that we build a specific type of controller.

I have a PIC microcontroller that feeds a PWM signal to a transistor that delivers a DC voltage between 0-20V (from a constant 20V source).

All that is working fine.

Now, I need to be able to measure the current through the load and adjust the voltage such that we obtain a specific current that will vary programatically. The load is purely resistive, so I was thinking of using a high-side shunt, and measure the voltage drop, convert that to current and adjust the PWM accordingly.

Now, there are some tricky bits, and that's where I am seeking advice:

1.The resistance is unknown and has to be measured in order to compute current (V=IR). I was thinking of either time-multiplexing the operation of the system so that at certain intervals the source stops and we make a measurement of the load or to have a "sensor"in parallel to the load that we can take continuous resistance measurements from.

2.I don't know how to go about the shunt: how exactly could I measure the voltage drop across the shunt in the load circuit from the control circuit since I cannot set the measurement points of the shunt to ground? (because both the control and the load circuit have the same ground, I would be effectively shorting the circuit at the shunt)

I hope my explanations are sufficiently clear, but let me know if you need to know any other piece of information.

All your ideas and suggestions are welcome :)
 
Last edited:

Thread Starter

Dream-

Joined Nov 26, 2010
69

Here is a simplified schematic showing the shunt test points (TP1, and TP2). I can't simply hook them to the PIC analog inputs because I would have to ground a test point and that would short the circuit.
 

CDRIVE

Joined Jul 1, 2008
2,219
Have you considered something like this? You could have the PIC do the Ohms Law to convert the voltage drop to current.
Alternatively, you could also pic off the Emitter and subtract the base current in code.
Note: The values for the voltage divider resistors shown are ballpark.
 

Attachments

someonesdad

Joined Jul 7, 2009
1,583
I can't simply hook them to the PIC analog inputs because I would have to ground a test point and that would short the circuit.
Assuming you have two analog input ports free, why not hook them to each side of the resistor? Then measure the voltages and subtract to get the voltage across the resistor. They're relatively high input impedances and can withstand up to slightly beyond Vdd IIRC.

Of course, there are things to worry about, like loss of numerical significance and the fact that it's a high-side shunt -- you might exceed the allow voltage level inputs of the PIC. The latter can be fixed by either putting the shunt on the low side or using some voltage dividers. Read the PIC datasheet about recommended limitations on the impedance of such dividers.
 

Thread Starter

Dream-

Joined Nov 26, 2010
69
Have you considered something like this? You could have the PIC do the Ohms Law to convert the voltage drop to current.
Alternatively, you could also pic off the Emitter and subtract the base current in code.
Note: The values for the voltage divider resistors shown are ballpark.
That's a plausible solution.

So now the problem becomes measuring RLoad in the circuit during operation, because my load resistance will have important variations as time elapses.
 

Thread Starter

Dream-

Joined Nov 26, 2010
69
Assuming you have two analog input ports free, why not hook them to each side of the resistor? Then measure the voltages and subtract to get the voltage across the resistor. They're relatively high input impedances and can withstand up to slightly beyond Vdd IIRC.

Of course, there are things to worry about, like loss of numerical significance and the fact that it's a high-side shunt -- you might exceed the allow voltage level inputs of the PIC. The latter can be fixed by either putting the shunt on the low side or using some voltage dividers. Read the PIC datasheet about recommended limitations on the impedance of such dividers.
I can't directly hook up the shunt test points to the microcontroller because the voltage levels exceed 5V. But I could indeed use voltage dividers to get to an acceptable level. It would have to be a very well matched voltage divider pair, or well calibrated in software. But definitely doable. And since the shunt resistance is known in advance, I would not need to do a resistance measurement of the load.
 

Thread Starter

Dream-

Joined Nov 26, 2010
69
Something just occured to me after looking at the two proposed solutions.

If I have a well regulated 20V Vcc then I could just use the voltage divider idea from CDrive and apply it to the shunt instead of the Rload. And with only that input I can compute current from the voltage drop. (If I don't have a well regulated Vcc, then I would have to take another measurement right after Vcc, but that would not be too problematic either.)
 

CDRIVE

Joined Jul 1, 2008
2,219
Yes, that should work but don't exclude the option of taking the voltage off of your Emitter resistor either. After all the Emitter current is equal to the Collector current minus the Base current.

Edit: After reconsidering this option it's a bad idea.
 
Last edited:

CDRIVE

Joined Jul 1, 2008
2,219
I forgot to ask... What's the emitter resistor (R2) for in your schematic? Emitter resistors are not normally used in switching applications as they will prevent the transistor from going into saturation.
 

jpanhalt

Joined Jan 18, 2008
11,087
If you use a low-side mosfet instead of a transistor and your sense resistor on the low side to ground, you can just measure the drop across the sense resistor with one input to the MCU. It will never go above 5V, unless you have one heck of a lot of current.
John
 

GetDeviceInfo

Joined Jun 7, 2009
2,196
so I was thinking of using a high-side shunt, and measure the voltage drop, convert that to current and adjust the PWM accordingly.
If it was not a given, why would you choose a high side instead of emitter to ground?
1.The resistance is unknown and has to be measured in order to compute current (V=IR). I was thinking of either time-multiplexing the operation of the system so that at certain intervals the source stops and we make a measurement of the load or to have a "sensor"in parallel to the load that we can take continuous resistance measurements from.
you don't need to know the load resistance. The shunt (known) indicates current.

Your real trick is going to be resolving modulated current, if current is in fact your controlling quantity. Even though modulated power is applied, the real world hysteresis of the device typically results in a more uniform output of whatever it's outputing, and in resistive elements that is typically heat. That then becomes a useful feedback quantity for your control algorithm.
 
Last edited:

Thread Starter

Dream-

Joined Nov 26, 2010
69
I forgot to ask... What's the emitter resistor (R2) for in your schematic? Emitter resistors are not normally used in switching applications as they will prevent the transistor from going into saturation.
I am not switching, I am amplifying. The simplified schematic doesn't show the filtering of the PWM signal. I am getting a varying voltage out of the PWM and feeding that to the transistor to amplify into the 0-20V range.
 

Thread Starter

Dream-

Joined Nov 26, 2010
69
If you use a low-side mosfet instead of a transistor and your sense resistor on the low side to ground, you can just measure the drop across the sense resistor with one input to the MCU. It will never go above 5V, unless you have one heck of a lot of current.
John
For this implementation I will be working with 0-4A, but after prototyping we will be looking at 50A at least.
 

jpanhalt

Joined Jan 18, 2008
11,087
To keep your power loss low, you will need to use a low-value resistor. .01 Ω @ 50 A is 0.5 V (i.e., 25W), you could even go with 0.005 Ω, which will get you a more reasonably sized resistor.

I have seen some devices that monitor the voltage drop across the mosfet (RDS\(_{on}\)) to control current.

John
 

GetDeviceInfo

Joined Jun 7, 2009
2,196
I am not switching, I am amplifying. The simplified schematic doesn't show the filtering of the PWM signal. I am getting a varying voltage out of the PWM and feeding that to the transistor to amplify into the 0-20V range.
You realize of course that's a contradiction to your first post.

If you place your shunt from emitter to ground, then all your really doing is building a voltage regulator over the shunt.

Unless you have some other unsaid adaptations, you realize that at your current range you'll run into heat issues. An option might be to carry your PWM onto the switching element, but then condition the signal across the emitter based shunt.
 

Thread Starter

Dream-

Joined Nov 26, 2010
69
You realize of course that's a contradiction to your first post.

If you place your shunt from emitter to ground, then all your really doing is building a voltage regulator over the shunt.

Unless you have some other unsaid adaptations, you realize that at your current range you'll run into heat issues. An option might be to carry your PWM onto the switching element, but then condition the signal across the emitter based shunt.
I did not realize the contradiction :)

I did think there were going to be some heat considerations and the emitter resistor bothered me for that reason (especially problematic to me is the power loss as this has to be as efficient as possible).

As per your consideration, should I then just send the PWM signal to the transistor so that it is just switching and then filter the high voltage, high current signal?

I think I may be able to get away with filtering the signal and just applying the raw PWM to the load. I such case, here is a more heat conscious design (I hope), which will only do transistor switching:

 
Last edited:

CDRIVE

Joined Jul 1, 2008
2,219
Something else for you to think about.. Your ADC output off of the Source resistor is not really analog at all. I've used the ADC input on a Picaxe but only with a pure analog signal. I'm fairly certain that all uCs are sampling the ADC input at a very rapid rate so maybe someone can opine on how it will react to pulses of varying width, as you will be feeding it. Perhaps it's not an issue at all.
 

Adjuster

Joined Dec 26, 2010
2,148
If you are using a very low value shunt resistor, you would be best advised to handle it as a four-terminal device (at least in terms of track layout, whether or not the resistor has separate current and potential connections). You would therefore need to use either two A/D inputs to your device, or else use a differential buffer amplifier.

If you try to use a simple resistor of just tens of milliohms, with significant wiring or track resistances in series, you may find the voltage is noticeably in error, and this error will move around with temperature because the temperature coefficient of resistance of copper is relatively big.
 
Last edited:

jpanhalt

Joined Jan 18, 2008
11,087
What you seem to be developing is a typical mosfet driver/controller with pulse by pulse current limiting. I believe those may still be available as a single chip. They use comparators to sense an over current situation. You could use one or two comparators to sense your shunt, depending on whether you want control or just a limit. Then generate a control PWM followed by D/A converter (low-pass filter) for the comparison voltage or use a digital potentiometer, if on the low side, for that voltage. That will avoid the potential A/D issue with the PWM.

John

Edit: Look up the TPIC2101. It may still be made. http://pdf1.alldatasheet.com/datasheet-pdf/view/29139/TI/TPIC2101.html
 
Last edited:

Thread Starter

Dream-

Joined Nov 26, 2010
69
Something else for you to think about.. Your ADC output off of the Source resistor is not really analog at all. I've used the ADC input on a Picaxe but only with a pure analog signal. I'm fairly certain that all uCs are sampling the ADC input at a very rapid rate so maybe someone can opine on how it will react to pulses of varying width, as you will be feeding it. Perhaps it's not an issue at all.
The signal going to the ADC will be filtered to get an analog voltage out of the PWM.
 
Top