Current sensing: Amplifier?

I am looking for a way to measure DC current on a positive rail.
The current will be in the range of 0-5Amps and the more precision the better (down to 50Ma or better).
I was thinking of using a 0.02 ohm resistor which, if my calculations are correct would give me

20mV / Amp
2uV / 1mA

As you can see, these are very low voltages.

I was thinking of using a opamp in differential mode. Since I am new to OpAmps (even newer then I am to mosfets :wink: ) I do not really know the circuit or resistor values required would be to give me 1V / Amp reference to ground.

Also scaling the voltage 50x is quite a bit of gain. Is it possible to do this without too much noise?

Using an bigger Rsense resistor would not be an option since the maximum tolerable drop is about 150mV at 5 amps draw.

Thats EASY just place the sense resistor before the regulator or the VR voltage feedback after the resistor. This is done to subtract the Sense Resistor voltage drop from the output voltage the other advantage of that connection is that you can use a larger value sense resistor... 10mA to 5A should be fairly easy @ 5% accuracy over the range. The prime disadvantage of pre regulator sensing is that the op-amp inputs have to be able to swing to the positive supply rail, in post regulator sensing the opamp is fed from the main supply... sometimes a small supply is generated just for the sense feedback amplifier. Draw me a circuit and I will look at it and If I can I will try to simulate it for you. there is another thought and that is LCD ammeters are sold on Ebay. A 4 1/2 digit device (~$15.00) would be accurate to 10 ma easily. I am a GREAT fan of purchased items where ever possible falling back to construction only where the OTS item is wrong, size, range, price and availability... For a laugh go look up a MAX471/2. I think that either device will work for you. They might well be out of production but they ARE available. There are also the Allegro ACS7XX devices. I need to go get dinner but I will look when I get back. Both the Maxim and Allegro devices are bi-polar in output, the Maxim thing has I think a sign output as well... More Later

Doc

I was thinking the same: there are special ic's that are designed for high-side current sensing. They are like normal OpAmps, but they are able to have a higher voltage on the inputs than their own supply voltage. They will give you an accurate value.

The analog inputs of the Arduino are 10-bits. 5A in 10-bits is 5mA resolution.

You could also use a hall current sensor.
http://www.lucadentella.it/en/2011/11/29/sensore-di-corrente-con-arduino/?utm_source=rss&utm_medium=rss&utm_campaign=sensore-di-corrente-con-arduino
But that's less accurate, and they will give false readings if placed next to magnetical field from a transformer or switching power supply or speaker.
But it's very cheap and very easy to use.

On the allegro site you will find this part...ACS714ELCTR-05B-T it is a high side current sensor that is bi-lateral, it will sense current in both directions at 185/mV/A. This value can apparently be scaled to 100mV/A easily for simpler scaling to amperage. The output is 1/2 Vcc and for the '714 Vcc is 5V... there are 3V3 parts available but the granularity of the measurement would tend to make them less manageable for an Arduino or at least require a 12 bit A/D.
The Max471 is a sensor W/O a sense resistor and the Max472 is the same part with a 3A measuring range W/Sense resistor, both are "Not Recommended For New Designs"
(The caps are from the first page warning about being a discontinued part...) and can be purchased on Ebay for 5 - 10 dollars, maxim also makes several current sensors... I haven't yet looked for them... I did look for the ACS714... No Joy. Now it's your turn... Want to buy a LM338 Steel... 1.2 to 32 V out A 5A? linear and a great space heater... But a real Quick and Dirty 0 to 35V out supply regulator (0 V out requires a -1.2 V reference which is also not any issue to create a neg supply a TIL431 and 2 resistors. Probably better to find a Buck-Boost converter and have to live with ~80% Efficiency... @ 50 W out it would be 10W lost as heat.

Doc

Ok let me give more information.
I am trying to design from scratch a variable lab power supply with variable stabilize voltage and variable current limiting.
Using a prebuilt amperage meter is not an option because the MCU need to know the current draw and act upon it.
I am thinking of using a microcontroller driven non-isolated switching design. I know I am reinventing the wheel but no IC solutions give me the versatility that direct software control can provide. I did a breadboard test with a few BJT and the results were almost jaw dropping. Voltage was within 30mV of what it was set to, loads between 0 and 300 mA caused less then 20mV of change and transient response was acceptable and could be improved with software adjustment. There was some ripple but filtering was crude.
It even worked well at settings below 1v.

I want to scale the design up and I think something very usable could be produced and run variable voltage with ~2-3 amp output.

Docedison:
On the allegro site you will find this part...ACS714ELCTR-05B-T it is a high side current sensor that is bi-lateral, it will sense current in both directions at 185/mV/A. This value can apparently be scaled to 100mV/A easily for simpler scaling to amperage. The output is 1/2 Vcc and for the '714 Vcc is 5V... there are 3V3 parts available but the granularity of the measurement would tend to make them less manageable for an Arduino or at least require a 12 bit A/D.

With 185 mV / A, it seems like it would waste alot of the ADC resolution since there would be no currents over ~5A. .185 * 5 = 0.925. 0.925 is significantly less the 5v full scale of the ADC.

The Max471 is a sensor W/O a sense resistor and the Max472 is the same part with a 3A measuring range W/Sense resistor, both are "Not Recommended For New Designs"
(The caps are from the first page warning about being a discontinued part...) and can be purchased on Ebay for 5 - 10 dollars

I am not too concerned about being discontinued since I only need 1-2.

, maxim also makes several current sensors... I haven't yet looked for them... I did look for the ACS714... No Joy. Now it's your turn... Want to buy a LM338 Steel... 1.2 to 32 V out A 5A? linear and a great space heater... But a real Quick and Dirty 0 to 35V out supply regulator (0 V out requires a -1.2 V reference which is also not any issue to create a neg supply a TIL431 and 2 resistors. Probably better to find a Buck-Boost converter and have to live with ~80% Efficiency... @ 50 W out it would be 10W lost as heat.

The LM338 does not really meet the requirements I need. It would be controlled with an analog potentiometer which means its less stable and not easily controlled in software which is required for this application. Also implementing variable current limiting would be difficult. Furthermore, I need it to be to operate from 0-1.2 i.e. 1.2 is not low enough. I am going to have a switchable voltage divider on the analog input for when the voltage is greater then 5v, otherwise run it straight through for more precision on lower voltages. I will have a zener clamp on the analog inputs to protect it during the time it takes the divider to kick in. I am thinking of using one microcontroller that runs in a tight loop for regulation then using another microcontroller that monitors button presses, the rotary encoder, updates the LCD and watches current draw then sends commands to the regulator MCU. This way it does not drop regulation during handling button events etc... I plan to use first two voltage regulators, one to regulate the +18v input to +15v and another to regulate the +15 down to 5v for the MCU and other logic circuits.

I welcome your opinion.

You might want to watch Dave Jones blogs about designing a lab power supply:

(more episodes follow)

He goes into a lot of detail about how he controls the voltage and current, and senses the current.

both of your comments about the acs thing are wrong 100mV/A would give you 10 mv/100 ma @ 4.88MV/step for a 5v reference you would have the +/- 50 ma accuracy you spec'd if the output was set to 150mV/A you would be down to about +/- 30 mA accuracy and with a 1.1V Vref you could have mA accuracy easily all of this without a scaling amplifier... and as to the LM338 Steel (TO3 Metal 5A regulator... just tie a 200 300 ohm resistor from out to adjust and connect a dc voltage from ground to the adj pin and the output voltage will be 1.25V below the Adj pin voltage. can be sensed by the arduino and regulated by the arduino up to about 3.75 volts you would need to use a scaling amplifier as the analog write only goes to 5 V, as for the current control of either just control the voltage for a constant voltage or the voltage for a constant current, one or the other, usually the voltage feedback is used and current feedback is ignored. In CC mode Current is held constant by controlling the applied voltage.

Doc

The reference can be set to 1.1V : analogReference() - Arduino Reference

Your idea sounds very good. I would even be possible to program voltage or current ramps for testing.
Or program a certain voltage for a certain time.
Perhaps you could add a temperature sensor on the transistor or a temperature sensor inside the device.
Perhaps you could add a command interface via the serial connection and for logging.

What are your plans for a display and knobs ? A potmeter for variable voltage and buttons for digital preprogrammed voltages perhaps ?

Docedison:
both of your comments about the acs thing are wrong 100mV/A would give you 10 mv/100 ma @ 4.88MV/step for a 5v reference you would have the +/- 50 ma accuracy you spec'd if the output was set to 150mV/A you would be down to about +/- 30 mA accuracy and with a 1.1V Vref you could have mA accuracy easily all of this without a scaling amplifier...

I forgot about the 1.1V reference. This sounds like a good idea and I will probably go with it.

and as to the LM338 Steel (TO3 Metal 5A regulator... just tie a 200 300 ohm resistor from out to adjust and connect a dc voltage from ground to the adj pin and the output voltage will be 1.25V below the Adj pin voltage. can be sensed by the arduino and regulated by the arduino up to about 3.75 volts you would need to use a scaling amplifier as the analog write only goes to 5 V, as for the current control of either just control the voltage for a constant voltage or the voltage for a constant current, one or the other, usually the voltage feedback is used and current feedback is ignored. In CC mode Current is held constant by controlling the applied voltage.

Honestly, I feel like I am still going to go with the original plan because I am looking for alot of flexibility.
I want it to operate in "hybrid" mode where it is at a set constant voltage until it exceeds the current limit, then it will scale back the output voltage until it is within the current limit.
Basically constant voltage until the current hits threshold, then constant current.

I realized the Allegro is only available in surface mount packages. I can still make it work but it will take some effort.
Bed time now...

Krodal:
The reference can be set to 1.1V : analogReference() - Arduino Reference

One issue with using the 1.1v reference is I will not only be measuring current but also voltage which will range 0-5.
I guess I will have to switch to the 5v reference before measuring voltage then back to the 1.1v reference before measuring current.
Is it safe to apply voltages over Vref? Like 5v with the 1.1v reference set?

Your idea sounds very good. I would even be possible to program voltage or current ramps for testing.

The versitility of a software controlled power supply is amazing.

Or program a certain voltage for a certain time.

I was thinking of this.

Perhaps you could add a temperature sensor on the transistor or a temperature sensor inside the device.

I was thinking about this if I could get the core circuit going (missing some parts right now).
A temperature sensor could turn on a small fan at once level and do a protection shutdown at another level.

Perhaps you could add a command interface via the serial connection and for logging.

A serial interface for logging, debugging and control could be useful and I will think about implementation.

What are your plans for a display and knobs ? A potmeter for variable voltage and buttons for digital preprogrammed voltages perhaps ?

I was thinking of a rotary encoder to set the voltage, lock button to prevent accidental changes, output enable/disable button, HD44780 LCD to display voltages and current and monitor status, programmable current limit, programmable voltage limits so you do not apply for example 9v to a 5v circuit.
Various status LEDS to indicated fault, power and output status.
Peizeo electric buzzer for button feedback and protection faults. And to build the thing into some sort of case.
This is one of the biggest electronic projects I have ever planned.

Nice to read that we think alike.

A cheap HD44780 LCD display is rather slow. If you can read for example the current only 3 times a seconds, that might be too slow.

The analogReference can be switched from 5V to 1.1V and back. No problem.
You need to wait for about 20ms for the voltages to become stable after swithing the analog reference.
That delay is not implemented in the Arduino library, you have to use delay() in your own code.
Reading 5V with 1.1V reference is okay, but the value of analogRead() will soon be the maximum of 1023. But no harm is done.

Krodal:
A cheap HD44780 LCD display is rather slow. If you can read for example the current only 3 times a seconds, that might be too slow.

3 times/s might be enough but I do not want to waste all the microcontrollers processing time updating the LCD display.
Any suggestions?

The analogReference can be switched from 5V to 1.1V and back. No problem.
You need to wait for about 20ms for the voltages to become stable after swithing the analog reference.
That delay is not implemented in the Arduino library, you have to use delay() in your own code.

20mS is a bit long for my taste but I think I can use strategic delays to get some work done during the 20mS like monitoring buttons and knobs.

Reading 5V with 1.1V reference is okay, but the value of analogRead() will soon be the maximum of 1023. But no harm is done.

This is not really a problem.

I am also thinking how to send data from one atmega to another? I2C? SPI? UART?
I need to send a 2 byte data string on occasion to the regulator atmega with updates to the regulation voltage.
BTW the bloody server ate my last post with a #500 internal server error

Yeah it ate mine this morning too... always with one of my "Short Missives"... I hate to type as my hands are arthritic and painful. This happens often enough that I have taken to copying messages to the clipboard from time to time... just for luck. Seems to work as the only time the crashes happen to me is with a full page of text, un-copied. Magic, I guess

Doc

Docedison:
Yeah it ate mine this morning too... always with one of my "Short Missives"... I hate to type as my hands are arthritic and painful. This happens often enough that I have taken to copying messages to the clipboard from time to time... just for luck. Seems to work as the only time the crashes happen to me is with a full page of text, un-copied. Magic, I guess

Doc

Or Murphy's law at work :wink:

On another topic, what would recommend to transmit data between to MCUs?

Communicate with other ATmega, SPI I2C UART, you can use them all. SPI is the fastest and most used for this. UART is to be able to test the modules seperately with a serial terminal.

That 20ms delay is when there is an 100nF on Aref. That 100nF is according to the datasheet for best analog result. If you leave it as it is, perhaps no delay or a very small delay is okay.

Here is the first prototype schematic. Unfortunately I am missing many of the parts...

According to this, there is a huge problem with ACS714...Its output is centered on 2.5v meaning I cannot use the 1.1v reference.

smeezekitty:
http://www.pololu.com/catalog/product/1185
According to this, there is a huge problem with ACS714...Its output is centered on 2.5v meaning I cannot use the 1.1v reference.

That's a hall current sensor. They are cheap an easy to use, but they can never ever get the accuracy of a special high-side current opamp.
I would avoid it. The power supply needs a transformer or switching adapter, and if that hall current sensor is somewhere near that, it's reading is very inaccurate. In the schematic I see a relay, the hall current sensor might also be influenced by the coil of that relay. But if you use it, you must indeed use the 5V reference.

I use a hall current-sensor for rough current sensing to stop a 12V motor at a certain current, to prevent that the motor will break things. For a better result with that hall current-sensor, I use the average of 27 samples during 500ms (27*185mv/A = 5A which equals the range).

I can't say much about the schematic. There's too much going on for me to say anything meaningful. Perhaps using a larger area and placing the parts not so near each other might make it more clear what is going on ?

Krodal:
That's a hall current sensor. They are cheap an easy to use, but they can never ever get the accuracy of a special high-side current opamp.

What would you suggest? I need to read down within about 10mA and handle up to 5A. I also need the results to be within 5% of so.

I would avoid it. The power supply needs a transformer or switching adapter, and if that hall current sensor is somewhere near that, it's
reading is very inaccurate. In the schematic I see a relay, the hall current sensor might also be influenced by the coil of that relay. But if you use it, you must indeed use the 5V reference.

Ok. FWIW The main power supply with be an 18V 3 amp switch mode printer power supply that I picked up at the thrift store.
The powersupply will remain quite a distance from the main system but I feel the hall effect sensor may not give the precision required. Also a 10 bit ADC will not provide much resolution with a 5v reference.
There will be two relays so that may cause a problem with the hall effect sensors.

I use a hall current-sensor for rough current sensing to stop a 12V motor at a certain current, to prevent that the motor will break things. For a better result with that hall current-sensor, I use the average of 27 samples during 500ms (27*185mv/A = 5A which equals the range).

I need more precision then that.

I can't say much about the schematic. There's too much going on for me to say anything meaningful. Perhaps using a larger area and placing the parts not so near each other might make it more clear what is going on ?

I used tinycad and couldn't figure how to make it bigger or split it up.
[/quote]

smeezekitty:

Krodal:
That's a hall current sensor. They are cheap an easy to use, but they can never ever get the accuracy of a special high-side current opamp.

What would you suggest? I need to read down within about 10mA and handle up to 5A. I also need the results to be within 5% of so.

Did you find a high-side current sensing opamp yet ?
LadyAda choose the INA219, but it's only 3.2A and uses I2C (slow): NEW PRODUCT – INA219 High Side DC Current Sensor Breakout – 26V ±3.2A Max « Adafruit Industries – Makers, hackers, artists, designers and engineers!
I found these: MAX4172, LT1787, LT1494 (maxim and LT have more like these).
Mixed-signal and digital signal processing ICs | Analog Devices
The best choice would be a high side current sensing opamp that operates at +5V with an output that can be connected to an AVR analog input.

I don't know if your project will be Arduino compatible, but the people at http://www.avrfreaks.net are more into electronics. They would probably know a good high-side current sensing opamp.