# Current measurement and control

Discussion in 'The Projects Forum' started by Dream-, Mar 18, 2011.

1. ### Dream- Thread Starter Active Member

Nov 26, 2010
69
0
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: Mar 18, 2011
2. ### Dream- Thread Starter Active Member

Nov 26, 2010
69
0

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.

3. ### CDRIVE AAC Fanatic!

Jul 1, 2008
2,223
101
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.

• ###### Vdiv.JPG
File size:
12.7 KB
Views:
37
Dream- likes this.

Jul 7, 2009
1,585
141
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.

5. ### Dream- Thread Starter Active Member

Nov 26, 2010
69
0
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.

6. ### Dream- Thread Starter Active Member

Nov 26, 2010
69
0
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.

7. ### Dream- Thread Starter Active Member

Nov 26, 2010
69
0
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.)

8. ### CDRIVE AAC Fanatic!

Jul 1, 2008
2,223
101
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: Mar 19, 2011
9. ### CDRIVE AAC Fanatic!

Jul 1, 2008
2,223
101
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.

10. ### jpanhalt AAC Fanatic!

Jan 18, 2008
5,699
912
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

11. ### GetDeviceInfo Senior Member

Jun 7, 2009
1,571
230
If it was not a given, why would you choose a high side instead of emitter to ground?
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: Mar 19, 2011
12. ### Dream- Thread Starter Active Member

Nov 26, 2010
69
0
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.

13. ### Dream- Thread Starter Active Member

Nov 26, 2010
69
0
For this implementation I will be working with 0-4A, but after prototyping we will be looking at 50A at least.

14. ### jpanhalt AAC Fanatic!

Jan 18, 2008
5,699
912
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

15. ### GetDeviceInfo Senior Member

Jun 7, 2009
1,571
230

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.

Dream- likes this.
16. ### Dream- Thread Starter Active Member

Nov 26, 2010
69
0
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: Mar 20, 2011
17. ### CDRIVE AAC Fanatic!

Jul 1, 2008
2,223
101
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.

Dec 26, 2010
2,147
301
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: Mar 20, 2011
19. ### jpanhalt AAC Fanatic!

Jan 18, 2008
5,699
912
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: Mar 20, 2011
20. ### Dream- Thread Starter Active Member

Nov 26, 2010
69
0
The signal going to the ADC will be filtered to get an analog voltage out of the PWM.