Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Energy monitoring project (measuring DC-current with microcontroller)

Status
Not open for further replies.

olle

New Member
hi,

I have searched around for some time now on the topic of measuring DC-current with a micro controller (for example PIC which is what I'm used to), but I haven't found as much useful information as I had hoped. The problem is that I'm not well informed when it comes to OP-amps. Rather than just asking for OP-amp circuits I thought I'd better share the whole concept to give you guys a chance to determine if I'm on the right track or not.

The project is meant to monitor a system comprised of a generator (windmill/solar panel), a 12V battery system (I say system as it will in reality consist of an array) and load circuit (lamps, laptops, the usual).

instead of just having a regulator for ensuring that the batteries aren't overcharged, I'm interested in building a monitoring system that can keep track of used and charged amp/hours. And of course momentary consumption/charging. (something like the energy monitoring in a Toyota Prius)

This approach brings up some initial conclusions:

1. Accuracy. Inaccuracy in current measuring will not only cause display-fault as in an normal amp-meter, it will also cause a drift in the values so that after running the system for a while, it will no longer know the amount of energy really stored in the batteries. A slight inaccuracy is of course impossible or at least impractical to try to build around, so making the system self-tuning is my guess, reseting the default "fully charged capacity" whenever the batteries reach a preset voltage. (and a routine for making sure that they never come under a certain voltage either of course).

time for a question, has anyone here built a amp/hour-meter using a shunt+OP-amp and PIC/AVR? Searching around the net has at least given me the conclusion that other means than shunts is not preferable, am I right? (transducer etc).

2. Point of measuring. The measuring system and the target system has the same power source, thus the point of measuring becomes an issue. Would it at all be practical to put the shunt between the positive side of the battery and for example the charging circuit using the offset voltage on the OP-amp? Or is it much more practical to measure the current on the GND-side?

3. Currents measured will be in the 0-5A for generator side, and 0-5A and 0-10A on the load side. This is probably possible with the same OP-amp, just using different resistor-nets? I need some tutorial circuits to get started with, and recommendation of suitable OP-amps.

I will have both 5V and 12V available if there is more choices of circuits driven by higher voltage than 5V.

I'm not new to micro controllers, and I'm fairly into general electronics but if you know any good OP-amp tutorials I should read, or current sensing projects of this kind that is useful, please post some links.

Thanks!


(edit: I'm going through the OP-amp tutorials present on this site, but I still want to hear your ideas and experience on this particular project even if I can find a suitable configuration in Nigels graphic etc).
 
Last edited:
Read this thread. Hook the output to the PIC's A/D input.

If you can't monitor the current in the low-side of the load, I have previously posted "high-side-current-monitor" circuits.
 
Last edited:
Unless you want to waste a bunch of power, you are going to need to amplify the sense voltage. That means you need to deal with amplification whether u measure the high side or the low side. Measuring on the low side is more convenient, mostly because the high side restricts you to high voltage devices. You can get better amplifiers for cheaper if you only need to deal with under 5V, like this one, that is cheap and pretty much idiot proof: AD8293G80 | Low Cost, Zero-Drift In-Amp with Filter and Fixed Gain = 80 | Instrumentation Amplifiers | Amplifiers and Comparators | Analog Devices. The high is used more often because you often have multiple power rails that share a ground that you want to sense separately.

You don't have to deal with op amps if you don't want to (although u should eventually). Analog and Linear make i2c current monitors and pretty much everybody makes high side current sense amplifiers. See here: ADM1191 | Digital Power Monitor with Convert Pin and ALERTB Output | Current Sense Amplifiers | Amplifiers and Comparators | Analog Devices. An advantage of an i2c monitor is that you don't have to put your micro right up against the shunt. You could locate it 100 yards away if you wanted. Disadvantage is price and the fact that it is probably not fast enough to make an effective feedback loop (although it does have an alert pin for limited functionality of that type).
 
thanks!

Attaching a shunt to the negative side of the battery seams like a good idea and I might put one sensor like that on each battery to avoid having to have a gigantic current span of the shunt. It will make a nice reading of the balance of the system, if it's charging or draining.

However, I do want to isolate the reading to only a particular charging source as I have several, and also to get better precision of the system.

As I will have several different measuring points I figured I break it down to several circuits communicating over CAN. This makes it possible for me to have different supplies for them, as I can of course power the measurement of a charger with the charger itself.

How would the circuit in the attached picture work?

Am I right in the folowing assumption:

when the windmill is generating a higher voltage than the battery array, a current will flow through the diode and through the batteries (and the load also of course) and through the shunt resistor. There will be a measurable voltage over the shunt that only corresponds to the actual current generated by the windmill, and not any other current drawn between the batteries and load.

The question is what happens when the windmill shuts down. In this circuit I put the power source point for the measurement circuit after the diode, so if the windmill shuts off, it will be powered by the batteries. However, the sensor point will be slightly lower in potential than the GND reference, but with a micro-voltage as the current flowing through the shunt at that time is only what dries the microcontroller circuit.

Do you see any problems with this design? I could of course power the sensor circuit before the diode, but it would cause the circuit to shut off if the windmill isn't generating power, which could be annoying but of course manageable, as it's a only a probe circuit and could be integrated in the windmills controller.

Edit: CafeLogic, I didn't see your post until after I posted my reply. Of course I need amplification. But as you mentioned I will have several power sources, several batteries and so on, so I don't want all the power of the whole system to run through a shunt. (could be over 100A so it wouldn't be accurate). On the other hand, my charging sources will be solar panels and small windmill which will not generate any large currents each, so measuring them separately won't need expensive high-current shunts. I will prevent large fluctuations in voltage in the system so I guess the voltage will be around 10-14V normally, but it depends on the voltage of the battery array when fully charged.

I would like to avoid using ready current sensing chips as I want to learn how to construct this using OP-amps.
 

Attachments

  • windmill_circuit.jpg
    windmill_circuit.jpg
    50.7 KB · Views: 823
Last edited:
I have a similar project to monitor battery state of charge and solar power generation using a pic controller. I use hall-effect current sensors from AMPLOC on my design. It's very easy to interface them with 5vdc ADC inputs. AMP50 and AMP300. amploc current sensors

Link to google project page. Hardware diagrams are totally out of date but software is pretty current. solar-monitor - Project Hosting on Google Code
 
This link from backshed gives a few windmill examples. I likely would not have done it quite this way but it may give you yet another thought.

Ron
 
Thanks for the link, and as you say even if we might not do it that way information on that page can provide useful ideas.

As to the choice of OP-amp, I tried to post a link to a datasheet but the post was never published here, guess there was some error.
Anyway, the OP-amp I wanted to ask about is named LM324AN/NOPB. Any one have experince of it? I find there is a whole sea of OP-amps and I don't really know how to choose.
 
The LM324 is the industry standard, used for everything op-amp. The short answer to your question is no, it's not really a good choice for your application. There are a lot of things to consider when picking an op amp: supply range, power consumption, bandwidth, and sources of error are important.

You are measuring DC, so bandwidth is really a non-issue, it just needs to be higher than the intervals you'll be checking at.

You have three main sources of error, Offset Voltage (Vos), Bias Current (Ib), and Input Offset Current (Ios). The two current ones should not be as important to you because shunts are very low impedance sources. The consideration for you is that if the current errors are high, then you would need to use lower value resistors for your dividers which will waste some power. Basically if your Ib is 1 nanoamp, and your input impedance is 1 MOhms, you will lose 1mv from your input. You can balance your input impedance so you lose the same on both sides thus canceling out, and then only Ios matters which is the difference in Ib for the two inputs. When Ib and Ios are uncontrolled, they turn into Vos. However, you also have seperate static Vos.

Vos is the bigee that you need to be paying attention to for this application. Vos is the mismatch between voltages of both inputs. If your Vos is +/- 5mv, and you have both inputs grounded, -5mv to 5mv will be present out the output. When you are dealing with a low value shunt like 10milliohm, that is bad. Lets say for instance you get the typical LM324 offset of +2mv, that will make it look like 200ma is being used when really it is zero.

The good news is, it should be simple to calibrate for it in software. The bad news is that it drifts with temperature. Bottom line is, look for an op-amp with low Vos. It shouldn't be too hard because you have bandwidth to trade for it.

Places to look: manufacturer website of TI, Analog Devices, Maxim, National Semi, On Semi, and if you like taking it in the rear in the figurative sense, Linear Technology. They typically have a high precision/low Vos section.
 
Oh and you said something about measuring 100A. You can do that. A good choice at that point would be a Hall sensor. It measures a magnetic field rather than a voltage drop. Here you go: **broken link removed**

Also, if put 100A through anything, you are going to have significant voltage drop whether you like it or not. You don't need a shunt, you can just use a wire or trace that is already there. Figure out the resistance from the length, guage, and material (i.e. copper).
 
Last edited:
thanks for the useful input, I have a lot to learn about OP-amp theory, and I don't think my usual way of taking someones schematic and change until it do my job is going to be good for this, i rather sit down and learn it from the ground up. :)

About 100A, I didn't mean I need to measure that, I meant that if I was supposed to put the shunt on the negative side of the whole battery bank, it would have to cope with current up to that range, but I rather have several measuring points with better resolution, for example, one point on the windmill integrated in the windmills controller, one for the solar array, and several on the consumer side as well. It is indeed possible to put the measuring points on the low side as I can have several GND-rails for these split output. Like in any larger home system or automotive system, I want to split the consumer side into for example 10A-systems for securing them, meaning that each of these can have a measuring range of 0-10A. As this is for a composite sail-boat, I don't have a large common GND-rail like a frame in a car, so I can devide the systems in different GND-rails making measurement easier.
 
Browsing OP-amps for voltage offset seamed harder than expected, all present suppliers here don't categorize that. Elfa does, but most of their OP-amps has no rating there so you haveto open the datasheet for each and every one of the, a painstaking task.

I would really appreciate if I could get some recommendations for OP-amps to use.
My first project will be current control for a peltier element with a max current of 10A, so 0-10A will pass through the shunt with the shunt on the low-side.

For the rest of this project I've decided after all to have a go with the harder way of high side current sensing, but first I'm going to learn OP-amps with this cooling project.
 
Yes, Ive been there. Even if your suppliers did list it, it would probably be wrong, some products would have typical vos listed, some would have max. This is why I suggested you visit the manufacturer websites. If you supplier carries TI, then look at the the TI website.

As for a recommendation, for low side sensing, Microchip has very high precision, low power, and inexpensive 5 volt op amps.

The MCP6V01/MCP6V02 has 2uV Vos and costs $1.66/$2.59 at QTY 1

if thats too much:

The MCP6031/MCP6032 has 150uV Vos and costs $0.72/$0.96

Both have nearly ideal input bias meaning you can use very high value resistor dividers and save power. The MCP6031/6032 has < 2uA Iq (power consumption), so you could make a near zero power sensor with those.
 
Last edited:
Beyond Cafe Logic's fine suggestions when looking for operational amplifiers for a specific function try refining a Google search. For example a search for "current shunt amplifiers" or even "instrumentation amplifiers" will get you some good results.

Measuring the current to a "peltier element with a max current of 10A, so 0-10A" isn't all that difficult. Using shunts like these you can have a 0 to 10 amp shunt output 50 or 100 mV full scale. However, looking back to your initial post if we want to measure the current from a battery to a load or also the charge of a battery (curerent leaving or entering a battery) things change a little as the polarity of the signal from the shunt will reverse depending on if the battery is charging or discharging. This is where a good instrumentation operational amplifier with a differential input (and isolated input) can come in handy.

Ron
 
Thanks for the answers. Ron, I'm going to separate the circuits. I'm starting with a circuit for controlling this peltier element in a cooling-application, just to learn how to work with shunts+op-amps etc. This will be on the load-side, so no reversing currents or highly fluctuating voltages. (which I presume would be a problem when measuring on high side, but not when working on low side right? )

For the project that really is the topic of this thread, I'll be forced to measure high-side. But a friend told me that for example Microchip has of-the-shelf products for measuring high-side, have any of you worked with them?
 
high/low side is irrelevant to reversing current. If the current flows backwards the polarity of the drop will be reversed (as ron stated). If the negative supply rail of the amp is at ground then the amp will output 0 + offset. The solution is to have the negative supply below ground so it outputs a negative voltage. You then need to offset it so your micros ADC can read it. However, if your charge line is different from your drain line, then you don't need to worry about it.

If you do need current from going both ways, rather than dealing with the negative voltage ADC problem, it is easier to get a pre-made sense amplifier with digital output (the ADC is built in), like the INA209 from TI.

A pre-made current sense amplifier is a great way to go if it is in your budget, they have all the nitty gritty specs taken care of and all you need to worry about is the accuracy spec, usually expressed in percentage. Most current sense amplifiers are high side monitors (probably because the incentive to pay more for an IC is less with low-side). To the best of knowledge (and I could be wrong), Microchip does not make one but everyone else does. TI, for example, had 53 listed on their website. The one i mentioned before is a high-side monitor. Your supplier will typically have a category for current sense amplifiers that is separate from regular op-amps.

High-side sensing isn't that much more difficult than low-side. Really the only difference is you have to find an op-amp with a high enough voltage rating whos input extends to the upper rail.

Ron, I think the last part of your post can be confusing and possibly perpetuate a common misconception so I want to make something clear when people read this thread later.

Isolated inputs are awesome but unless your amplifier was billed as an "isolation amplifier" and cost at least $5, it does not have them. While working with your typically differential/instrumentation amp, with very few exceptions, you should not be sensing any voltage which is above or below the supply rails. That statement does not only apply to the difference. For example, your op-amp is powered by -5 and +5. You figure you can measure 10 volts at the non-inverting input and 12 volts at the inverting because the difference is only -2, wrong, no, don't try it. However, if your op amp, is powered by a separate isolated supply (like the op-amp in your multimeter, powered by batteries) then it cannot "see" the voltage of anything with respect to a different ground. In that case, only the difference matters.
 
Last edited:
Hello,

olle, have you considered using one of the hall effect current sensors made for monitoring bi-directional current?
They are fairly cheap and make life a lot easier.
 
This thread inspired my first blog post

**broken link removed**

Not that I don't like the hall effect suggestion. No burden voltage and intrinsic isolation are good things.
 
Hi,

thaks for the links!

I will in the first place not read bidirectional current, simply because I want to maximize resolution. I will instead have several measuring points.

my device will be split into several "consumer circuits" and several "charger inputs", so I can measure them both, and they will only have current flowing one direction.

If I did put the measuring on the batteries I would off course be forced to cope with current flowing both ways.

The GND must be possible to have common for all consumer circuits, therefor I won't be measuring low side.

I will check out what TI has to offer.
 
Status
Not open for further replies.

Latest threads

Back
Top