Author Topic: uA and mA Current Sense via Microcontroller  (Read 11504 times)

0 Members and 1 Guest are viewing this topic.

Offline MobileWillTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
    • Mobilewill Blog
uA and mA Current Sense via Microcontroller
« on: March 04, 2016, 06:34:06 am »
Up until now I have been using the INA219B to sense mA/A over I2C. Great little chip. The problem I have been running into now is it doesn't seem to do well for less than 1mA. I have been doing research on designing a system to measure uA. It seems I would need a opamp with multiple shunt values to set the current range. But the problem is how would you do that without user intervention?

Here is one of the designs I found

http://www.kerrywong.com/2013/01/17/current-adapter-for-low-current-measurement-using-ts1001/

Ideally a chip like the INA219 that can do it and be read over digital means. It almost seems the INA219 could do it with a higher value shunt but that goes back to the multiple shunt values and the affect on the system.

Also I would like to sample quickly to catch short spikes. Looks like the way to do that is using a ADC instead of I2C which gives me a limited samples per sec.

I am using a Attiny85 in sleep as my test load which blinks an LED when it wakes. In sleep it is using 4.5uA and 3mA+ in wake, tested with the EEVBlog DMM.  :-+

So really I would need a system to measure uA and still measure mA when microcontroller wakes.


Thank you for the help
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4939
  • Country: gb
Re: uA and mA Current Sense via Microcontroller
« Reply #1 on: March 04, 2016, 08:09:34 am »
My circuit diagram is a very quickly drawn circuit, and could easily contain LARGE errors. It is mainly to give you a possible solution, starting point.

EDIT: Diode originally drawn the wrong way round, SORRY! Circuit updated, should be correct now.

The basic idea is that the micro power voltage regulator, keeps the voltage steady. Normal voltage regulators would use too much current (a few milliamps), which would ruin the readings. The micro power voltage regulator only seems to use about a micro amp (typ). Ideally remove the actual offset current from your readings, or improve the circuit to eliminate it.

The diode allows microamps to be read. But limits the max voltage drop, for higher (milli amp) currents. The vreg should remove the voltage changes (hopefully).

It would (ideally) need TWO current sensor ICs (like the one in your OP,  INA219B). You may not like this.

You may need to add some bits and pieces, such as decoupling capacitors etc. To finish the circuit off, and keep it stable.

An alternative would be to try and use an op-amp (as a fixed gain amp) to gain a much wider range, from a SINGLE sense/shunt resistor (hence 2 ranges, direct (mA's) and via op-amp (uA's) ). But you would probably get too poor a signal to noise ratio, for it to work well enough, for your purposes. But it could be worth a try.

Micro power voltage regulator http://www.onsemi.com/pub_link/Collateral/MC78FC00-D.PDF
« Last Edit: March 04, 2016, 08:27:03 am by MK14 »
 

Offline MobileWillTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
    • Mobilewill Blog
Re: uA and mA Current Sense via Microcontroller
« Reply #2 on: March 05, 2016, 09:32:14 pm »
Thank you. So is ST1/2 where I would connect a ADC?

Currently the measurement micro is separate from the device under test. I also power the measurement micro before the shunt so it doesn't affect measurement of course.
 

Offline MobileWillTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
    • Mobilewill Blog
Re: uA and mA Current Sense via Microcontroller
« Reply #3 on: March 05, 2016, 09:37:26 pm »
The regualtor is only 120mA so wouldn't the micro not be able to use more than that?
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: uA and mA Current Sense via Microcontroller
« Reply #4 on: March 05, 2016, 11:45:25 pm »
A typical I-V converter will do but not the best choice - I have done some that can measure well into na territory.

A better and simpler choice is a high-side current sense amplifier - either a commercial one or one that's built using your opamp of choice. It has an added advantage in that the output is referenced to the ground -> superb for a mcu + adc.

Quote
I am using a Attiny85

That mcu has a 20x gain amplifier in the (unipolar) adc. So the adc resolution can be as low as 1100mv / 1023 / 20 = ~50uv. Depending on the burden voltage you are willing to tolerate, it can measure very low current all by itself + a resistor.
================================
https://dannyelectronics.wordpress.com/
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4939
  • Country: gb
Re: uA and mA Current Sense via Microcontroller
« Reply #5 on: March 06, 2016, 11:19:14 am »
Thank you. So is ST1/2 where I would connect a ADC?

Currently the measurement micro is separate from the device under test. I also power the measurement micro before the shunt so it doesn't affect measurement of course.

Yes. But a significant weakness of the design I supplied, is that it is NOT ground based. It was intended to use YOUR original current sensing devices.

ADCs may not be able to cope with the big relative to ground, voltages.
I.e. you need something with a significant common mode voltage capability.

The regualtor is only 120mA so wouldn't the micro not be able to use more than that?

Very good point.
Yes that is a significant LIMITATION of that design.

You seemed to be mentioning small current, like uAs and mAs. So I may have thought it was rather low current.

A typical I-V converter will do but not the best choice - I have done some that can measure well into na territory.

na is very good.
But was it fast enough for the OPs purposes ?

I guess there could easily be a compromise between speed and accuracy, which meets his requirements.
« Last Edit: March 06, 2016, 11:29:30 am by MK14 »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: uA and mA Current Sense via Microcontroller
« Reply #6 on: March 06, 2016, 02:04:45 pm »
Quote
But was it fast enough for the OPs purposes ?

How fast can it be if reading is done via i2c?
================================
https://dannyelectronics.wordpress.com/
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4939
  • Country: gb
Re: uA and mA Current Sense via Microcontroller
« Reply #7 on: March 06, 2016, 02:13:43 pm »
Quote
But was it fast enough for the OPs purposes ?

How fast can it be if reading is done via i2c?

What I meant was that a 7.5 digit multimeter (for example).
Could easily meet his wide, dynamic range.
But if he wants to see, very fast, current consumption changes, such solutions would miss it.
Typically only taking a few readings per second.

Sorry if I was not very good at explaining what I meant.

When you said nA, I took that to mean slow (e.g. 10 per second), highly filtered readings.

Maybe they were fast ones ?
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: uA and mA Current Sense via Microcontroller
« Reply #8 on: March 06, 2016, 02:23:59 pm »
It was a "DC" current measurement instrument built around some jfets / cmos opamps: I-V converter + voltage amplifiers. Not meant to be fast but it can be made to be reasonably fast depending on the opamps used and gain settings.
================================
https://dannyelectronics.wordpress.com/
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4939
  • Country: gb
Re: uA and mA Current Sense via Microcontroller
« Reply #9 on: March 06, 2016, 03:01:29 pm »
It was a "DC" current measurement instrument built around some jfets / cmos opamps: I-V converter + voltage amplifiers. Not meant to be fast but it can be made to be reasonably fast depending on the opamps used and gain settings.

Ok, that partly (gave me the idea) helped me improve my circuit. It now references the current sensing, so that ground based ADCs will work ok.

Very, very ROUGH sketch to give a slight idea, one way of doing it. Needs to be properly designed and tested. Both current sense outputs, are relative to ground (0V), for convenience.

I could be over thinking this circuit.
Maybe you are just better off, with a simple (lowish resistance, shunt) sensor, and amplifying it with op-amps. But it may be too noisy.

EDIT: Schematic updated.
« Last Edit: March 06, 2016, 03:11:27 pm by MK14 »
 

Offline Skashkash

  • Regular Contributor
  • *
  • Posts: 118
  • Country: us
Re: uA and mA Current Sense via Microcontroller
« Reply #10 on: March 06, 2016, 03:21:39 pm »
I've been playing this week with some Silicon Labs Gecko Development boards. They have a real nice current monitoring function built in. It's pretty slick to see the MCU's current consumption profiled against code functions and ISRs in real time.

 In any case,  the dev board's schematic has the circuit they use for monitoring the current. uA resolution with decent accuracy.
 
  They do use a calibration technique against some fixed resistors to reduce op amp err. Unfortunately the debuggers code is not avail.
   It's probably overkill for your application but there may be some ideas in there you can use.


AEM circuit starts on page 7.
https://www.silabs.com/Support%20Documents/TechnicalDocs/efm32hg-stk3400-schematics.pdf


 
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4939
  • Country: gb
Re: uA and mA Current Sense via Microcontroller
« Reply #11 on: March 06, 2016, 03:35:27 pm »
I've been playing this week with some Silicon Labs Gecko Development boards. They have a real nice current monitoring function built in. It's pretty slick to see the MCU's current consumption profiled against code functions and ISRs in real time.

 In any case,  the dev board's schematic has the circuit they use for monitoring the current. uA resolution with decent accuracy.
 
  They do use a calibration technique against some fixed resistors to reduce op amp err. Unfortunately the debuggers code is not avail.
   It's probably overkill for your application but there may be some ideas in there you can use.


AEM circuit starts on page 7.
https://www.silabs.com/Support%20Documents/TechnicalDocs/efm32hg-stk3400-schematics.pdf

That is cool. Seeing the real live current consumption, against source code.

Surely INC A, uses no more current than ACC = LOG(SIN(X^Y)/PI)/1.23456789E308 ?

Going one step better, they could make a custom version of GCC/Clang, have an optimize power consumption setting(s).
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: uA and mA Current Sense via Microcontroller
« Reply #12 on: March 06, 2016, 03:52:22 pm »
Quote
AEM circuit starts on page 7.

A typical high-side current sense amplifier.
================================
https://dannyelectronics.wordpress.com/
 

Offline MobileWillTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
    • Mobilewill Blog
Re: uA and mA Current Sense via Microcontroller
« Reply #13 on: March 06, 2016, 07:29:32 pm »
Quote
But was it fast enough for the OPs purposes ?

How fast can it be if reading is done via i2c?

Right now the INA219B without averaging takes 500us plus time to process and output the data. I am using a set 10Hz to calculate mAh but a fast blinking LED will miss spikes. I get about 1 out or 2 or 3 blinks.

I've been playing this week with some Silicon Labs Gecko Development boards. They have a real nice current monitoring function built in. It's pretty slick to see the MCU's current consumption profiled against code functions and ISRs in real time.

 In any case,  the dev board's schematic has the circuit they use for monitoring the current. uA resolution with decent accuracy.
 
  They do use a calibration technique against some fixed resistors to reduce op amp err. Unfortunately the debuggers code is not avail.
   It's probably overkill for your application but there may be some ideas in there you can use.


AEM circuit starts on page 7.
https://www.silabs.com/Support%20Documents/TechnicalDocs/efm32hg-stk3400-schematics.pdf

Thanks, that has some good stuff.

The secret for your application is to use a zero-drift current sense amplifier, such as LTC6102 (I have no affiliation with LT). It's a low noise device (2µV peak-peak @ 10Hz BW. Even less with extra filtering.) and offset is ultra stable.

This plus an ultra high resolution ADC (Such as LTC2400 from LT, or MCP3550/1/3 from Microchip) and you'll achieve a microamp resolution AND miliamp capability with a simple design and low component count.

The INA219B is also a zero-drift. The LTC6102 looks like it almost fits the bill but I should add I would need a 3.3v supply capable part. But I suppose I could power it before the regulator directly from USB VCC.
 

Offline MobileWillTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
    • Mobilewill Blog
Re: uA and mA Current Sense via Microcontroller
« Reply #14 on: March 06, 2016, 07:36:12 pm »
It was a "DC" current measurement instrument built around some jfets / cmos opamps: I-V converter + voltage amplifiers. Not meant to be fast but it can be made to be reasonably fast depending on the opamps used and gain settings.

Ok, that partly (gave me the idea) helped me improve my circuit. It now references the current sensing, so that ground based ADCs will work ok.

Very, very ROUGH sketch to give a slight idea, one way of doing it. Needs to be properly designed and tested. Both current sense outputs, are relative to ground (0V), for convenience.

I could be over thinking this circuit.
Maybe you are just better off, with a simple (lowish resistance, shunt) sensor, and amplifying it with op-amps. But it may be too noisy.

EDIT: Schematic updated.

Is the 12V an example or required? Can it vary?

Any recommended parts for the op-amp?
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4939
  • Country: gb
Re: uA and mA Current Sense via Microcontroller
« Reply #15 on: March 06, 2016, 08:09:42 pm »
It was a "DC" current measurement instrument built around some jfets / cmos opamps: I-V converter + voltage amplifiers. Not meant to be fast but it can be made to be reasonably fast depending on the opamps used and gain settings.

Ok, that partly (gave me the idea) helped me improve my circuit. It now references the current sensing, so that ground based ADCs will work ok.

Very, very ROUGH sketch to give a slight idea, one way of doing it. Needs to be properly designed and tested. Both current sense outputs, are relative to ground (0V), for convenience.

I could be over thinking this circuit.
Maybe you are just better off, with a simple (lowish resistance, shunt) sensor, and amplifying it with op-amps. But it may be too noisy.

EDIT: Schematic updated.

Is the 12V an example or required? Can it vary?

Any recommended parts for the op-amp?

I think if you go for a rail to rail input (common mode) one, it can cope with just a single supply.

LMC6482IN, but there are plenty of others.
Its a bit pricey (£1.18), cheaper ones will probably do just fine (as long as they are rail to rail inputs, and suitable max voltage ranges). (The search *jammed* up on me, I will try it again).

The 100 ohm resistor I showed, should probably be more like 270 ohms, to play safe.

The 12V was only an example. It is NOT critical.
But stay well below the maximum supply voltage of the op-amp, and it will need to be at least a few volts or so, above the MCU supply voltage, to ensure it can drive the transistor, and work ok.

EDIT:UPDATE:
I could not find cheaper op-amps. I was being a bit foolish.

It's (almost certain) because I went for only through hole, dip packaged ones for you. As I assumed that was what you would want. That's what has probably made the price surprisingly high.

Surface mount ones, would probably be really cheap.

Some components can still be bought, very cheaply, in dip/through hole packages.

But others are either very expensive (especially newly released stuff), or too frequently these days, not available in DIP packages at all.

There are many exceptions, for some things. I was using rules of thumb, to explain the situation.

There are still cheap DIP op-amps, but they did not seem to be obviously suitable in our circuit, on quick examination.
« Last Edit: March 07, 2016, 01:52:34 am by MK14 »
 

Offline dadler

  • Supporter
  • ****
  • Posts: 851
  • Country: us
Re: uA and mA Current Sense via Microcontroller
« Reply #16 on: March 06, 2016, 08:21:00 pm »
There are many useful circuits in this document:

http://cds.linear.com/docs/en/application-note/an105fa.pdf

 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4939
  • Country: gb
Re: uA and mA Current Sense via Microcontroller
« Reply #17 on: March 07, 2016, 11:30:33 pm »
It was a "DC" current measurement instrument built around some jfets / cmos opamps: I-V converter + voltage amplifiers. Not meant to be fast but it can be made to be reasonably fast depending on the opamps used and gain settings.

Ok, that partly (gave me the idea) helped me improve my circuit. It now references the current sensing, so that ground based ADCs will work ok.

Very, very ROUGH sketch to give a slight idea, one way of doing it. Needs to be properly designed and tested. Both current sense outputs, are relative to ground (0V), for convenience.

I could be over thinking this circuit.
Maybe you are just better off, with a simple (lowish resistance, shunt) sensor, and amplifying it with op-amps. But it may be too noisy.

EDIT: Schematic updated.

Is the 12V an example or required? Can it vary?

Any recommended parts for the op-amp?

I've had more time to think it over. As I tried to point out earlier. It is a VERY ROUGH sketch, to give you an initial idea as to one possible solution to solve your problem. But it really needs to be designed properly.

If it had been for one of my projects, I could have simulated it and/or breadboarded it. Playing about, until I had something which works reasonably well. Or just do it by thoroughly spending time designing the circuit on paper.

Since that process has NOT been done by me, you have NOT got anything like a finished circuit. I can already see a number of problems with it.

The concept of it is possibly basically sound, but it would need proper sorting out and designing. Sorry.

I was originally hoping, and thought that you might be able to do that yourself.

Final point. I have not really got the kind of information from yourself, which would be needed to design it properly, anyway. E.g. What voltages you are using, the maximum currents, how it is being powered, what sort of bandwidth (maximum update rate) you need, are you breadboarding this, or PCBs or whatever, etc etc.

tl;dr
I was trying to give you a quick/rough sketch on the back of an envelope, to give you one option on how to progress this project of yours.

Good luck with it.

If you try and breadboard something like this yourself. I will try and give you quick pointers as necessary. But as it stands, the circuit I supplied, is some way from a working version. The op-amp configuration would need to be significantly revised. As it stands I don't think it would work. It was a quick/rough sketch ONLY!

I don't know if this is just a quick curiosity of yours, worth only spending $0.29 on, and ten minutes, between TV programs.

Or you are happy to spend a month on it, it is of vital importance and budget is unimportant, but try to keep it below $1000.
 

Offline MobileWillTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
    • Mobilewill Blog
Re: uA and mA Current Sense via Microcontroller
« Reply #18 on: March 07, 2016, 11:40:00 pm »
I appreciate the help and this question is part of a project so I need to get it work one way or another. I am finishing up one more smaller design and then I can dive deeper into this.

I am doing a digikey order tonight hopefully so I can throw in some parts to test\play with so I at least I have something to start with.
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4939
  • Country: gb
Re: uA and mA Current Sense via Microcontroller
« Reply #19 on: March 07, 2016, 11:45:41 pm »
I appreciate the help and this question is part of a project so I need to get it work one way or another. I am finishing up one more smaller design and then I can dive deeper into this.

I am doing a digikey order tonight hopefully so I can throw in some parts to test\play with so I at least I have something to start with.

That's good.

If it was me, I'd try a simple, one stage (i.e. ONLY one sense/shunt resistor) configuration. Then see if it can be made to work over the micro amps to milliamp ranges that you want. With op-amp gain (e.g. x10 or x100) and high resolution Analogue to digital converters as necessary.

See if that can be persuaded to give you the results (speed and accuracy), that you require. If that fails to work out, then you can consider the other options, which a number of posters have suggested in this thread.

Good luck!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf