Measure current with the adc of uC

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, i want to measure current with the use of the adc of the uC.I know i have to measure the voltage drop of the resistor(shunt) but i dont know much about the adc.What should Vref be? Should i use differential or single edged? What is the the gain on the adc and why would i need it?

Thank you in advance

Last Edited: Mon. Apr 2, 2018 - 03:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What current are you wanting to measure? Where does it come from?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wolky wrote:
I know i have to measure the voltage drop of the resistor(shunt)

That is one way to measure current - but it is not the only possible way ...

 

i dont know much about the adc.

Then, clearly, your first step is to find out about the ADC!

 

Have you looked at Application Notes, tutorials, books, etc - both for ADCs in general, and the (unspecified) AVR's ADC in particular ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

The only thing provided is you want to measure current.  Why are you so completely vague about what you want to do?

How fast? what amount (picoamps? nanoamps , kilo amps? 2mv,  2V or 2000V, AC, DC, etc)

 

You could use resistors, pcb traces,  current-measuring chips,   hall sensors, current transformers,  etc

Please try again, so help can be provided.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Hello wolky -

 

"Measuring current" is a very big topic. The first thing that we need to know is the nature of the current you want to measure. The first question is whether it is steady or changing? Changing might imply AC, it might imply pulsed, or it might just imply "not steady". If it is AC, what frequency? The next question is the size of the current. Is it kiloAmps, Amps, milliAmps, microAmps,  or maybe even nanoAmps?

 

The next question is a bit harder to describe. A circuit designer might just say "high side" or "low side"? Here, we might say "current flowing in some power circuit" or "current flowing from load into ground"?  It it is in the power circuit, what is the voltage present? On the latter point, you might appreciate the difference between measuring current in a high voltage power transmission line vs the current in a circuit powered by a 1.5V battery.

 

How often do you want to measure? What accuracy and precision do you need (the two are not the same)?

 

Do you want the current measurement to be a permanent part of the system where the current flows? Or, do you want something that is completely removable (like a hand-held meter)?

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok i guess i had to be more precise:)
So the current will be coming from a 12V solar panel (Isc=0.7 mA , Voc=22 V).And i want to measure the voltage and current so i can make an mppt that changes the PWM that goes to a dc/dc converter to charge a battery.For the voltage to measure its not something difficult i just measure Vout of the panel with ground(single-edged ADC).But for the current i dont know how

I want it to be a permanent part of the system of course because i want to track the MPP

Thank you all

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, we are talking about slowly changing high-side current measurement. The solar panel is really very small (Isc=0.7mA). Voc is not that high but high enough to make things difficult.

 

At that current, a standard current sensing chip should work. The challenge would be to find one with a high enough voltage rating. It will also be very hard to find something that does not use all of the power available from the solar "panel" (leaving nothing for battery charging - solar panel delivers no more than about 15mW; that is barely useful).

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Mon. Apr 2, 2018 - 05:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ohh my bad :)... Isc=0.7 A (not mA), so the solar panel delivers up to 10W (not 15 mW)...is it possible to measure using the uC's ADC and not with a chip...and if yes how?

 

Thank you

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Isc=0.7 mA

Are you 100% sure the panel current limit is 0.0007A??   That sounds quite suspicious, unless indoors   Even a little  "solar panel"  in a calculator  probably produces a few ma outdoors.

 

You can measure the current on the high side (positive lead) using a variety of amps, made for this purpose.  They used to be expensive, but like everything prices plummet.  They include matched differential  inputs, much better than you can make using your own resistorors to reject common mode voltage. 

 

here is one that is very cheap...spec get better if  you spent an extra 10 cents:

http://www.ti.com/lit/ds/symlink/ina180.pdf

 

However, if your current is 0.7mA max, you will face many other hurdles, since the circuits themselves must be micro power...get a real panel!

 

 

 

  

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That 0.7A makes a BIG difference.

 

Now, if you are willing to allow enough voltage drop across a current sense resistor (that wastes panel power), you might do something like this:

 

 

It won't work without precision resistors. The ratios do not have to be exactly as given, but both dividers MUST generate a voltage less than Vref for the ADC. You can choose Vcc as Vref or the internal reference.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Mon. Apr 2, 2018 - 06:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good, now it appears you have 1000x power!   First note, ST makes MPPT chips, which I have used   (SPV1020, SPV1040) a few times.

http://www.st.com/content/ccc/resource/sales_and_marketing/promotional_material/brochure/67/f0/0f/23/95/f2/43/d4/BRSOLAR.pdf/files/BRSOLAR.pdf/jcr:content/translations/en.BRSOLAR.pdf

 

In their data/apps are some specs on their adjustment algorithms, which might be of use during your programming.

 

 

also here is a paper that  might have some useful info:

https://ac.els-cdn.com/S1876610212004262/1-s2.0-S1876610212004262-main.pdf?_tid=9e0b242e-1837-44ed-a285-ef50d1c1bdd9&acdnat=1522692239_ef4efa768b18d29f004a45d76c9171a0

 

You can also search here on the freaks, using the term MPPT

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Linear Tech also has MPPT switcher chips. TI probably does also.

 

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You want to build a MPPT system because you want to squeeze as much power as you can out of your solar panel.

Wasting a lot of enery over a shunt resistor is not a good idea.

Jim's #10 schematic reduces the resolution by another factor of 5.

That are the most important reasons that external hardware is used for this.

 

If you really want to do it with only AVR hardware, then usa an AVR with a built in PGA for the ADC.

 

But MPPT is very common. there are probably a multitude of existing solutions.

https://www.aliexpress.com/wholesale?SearchText=mppt

 

If you sort on price @ Ali then it starts with < USD 3 PCB's to charge lingle Lithium Cells, and it goes up all the way to multiple kW systmes for mains connected systems.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wolky wrote:
make an mppt

MPPT (Maximum Power Point Tracking) has been around for years, and is pretty much de rigueur in solar PV systems.

 

So have you studied how existing systems do this ?

 

I'm pretty sure Atmel have an App Note on it - others certainly do.

 

And, as Jim says, chips are widely available.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For my solar controller, I used an ACS723LLCTR-10AU-T current sensor, it has a very easy to use voltage out that connects to the ADC in!

 

Jim

 

 

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ahh, yes. The Allegro Hall-Effect current sensors. Forgot about that option. The current sense is isolated from the output part, and that is good. You can often select a scale factor fairly well optimizes the maximum panel current and the ADC full scale. And, there is very little voltage drop through them, unlike using a current sense resistor. The Hall-Effect current sensors may not be high precision or highly stable, but modern ones are pretty good.

 

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did think about the hall effect sensors, but did not mention hem because of their low accuracy, possible dift and/or temperature effects.

Galvanic isolation also does not seem to have clear use here.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim's suggestion in Post #10 is a great one if you wish to use the AVR's ADC.

 

If you go that route I might suggest that one leg of the circuit have three resistors in the divider, not just the normal two.

If the central resistor is a low value, multi-turn POT, then one can tweak the voltage divider to exactly match the other leg.

Totally optional, and can be done in software as well, but old design strategies are hard to give up.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Galvanic isolation IS important here, where the measured current is at 10-20V above ground.

 

Correct, Hall-Effect sensors have modest accuracy and a bit more temperature drift than the IC solutions. However, modern Hall-Effect devices are much, much, better than even 10 years ago. The technology has improved. Tempco and accuracy should be in the selection criteria for any device of any technology. 

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

At these relatively low voltages, the high side current monitor chips will do a fine job...they have the divider or other means built in:

 

Using your own resistors spells trouble if you have a high common mode voltage & want to only drop 40mV (say, out of 24v)for measuring purposes.

As mentioned, any imbalance (drift, offsets, or otherwise) in the dividers easily blur out the 40mv you hope to see.

The chips take care of all this for you & usually much better than you can do yourself.

They allow "over the top"  input voltages, meaning a 5V chip can handle 40V input, no problem.

 

...the chips have come a long way.   We barely appreciate rail-rail inputs any more...they were a big deal 25 years ago!

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!