Author Topic: Measure voltage and current with a micro??  (Read 6325 times)

0 Members and 1 Guest are viewing this topic.

Offline ChristopherTopic starter

  • Frequent Contributor
  • **
  • Posts: 429
  • Country: gb
Measure voltage and current with a micro??
« on: April 07, 2012, 05:38:40 pm »
I'm looking to accurately measure voltage and current, to then display on an LCD (Either be boring and use an HD44780 or use a large 7 segment LCD panel http://www.lumex.com/specs/LCD-S401C52TR.pdf), for the output of my bench power supply.

I'm looking for 10 or 100 mV/mA accuracy, probably 100. From what I can see, Dave's rev C board steps down the voltage and passes it to an ADC.   Can anyone shed some light onto this? Current is probably not needed, but voltage is a must.
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 11948
  • Country: us
Re: Measure voltage and current with a micro??
« Reply #1 on: April 07, 2012, 06:21:51 pm »
You can buy digital panel meters that will measure and display voltage for you just like analog panel meters do. They don't start out super accurate, but you can probably trim them to improve the accuracy somewhat. How accurate do you want the display to be?
 

Offline ChristopherTopic starter

  • Frequent Contributor
  • **
  • Posts: 429
  • Country: gb
Re: Measure voltage and current with a micro??
« Reply #2 on: April 07, 2012, 06:48:28 pm »
To the hundred milli-volt  or similar, like 5.1V or 6.34V. The problem with the panel meters is the fact they're so expensive £15-20. I'm sure that some digital circuit can reduce this cost.
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 2000
  • Country: dk
Re: Measure voltage and current with a micro??
« Reply #3 on: April 07, 2012, 06:52:54 pm »
Whats the measured Range ?

A voltage divider and an AVR would give 10 bit resolution (1024 steps)

/Bingo

 

Offline ChristopherTopic starter

  • Frequent Contributor
  • **
  • Posts: 429
  • Country: gb
Re: Measure voltage and current with a micro??
« Reply #4 on: April 07, 2012, 07:05:40 pm »
Let's say about 20v max or something? I see how a potential divider could be used, because the Aref max is Vcc which happens to be 5v,

Aref=5v so we have to step down the input voltage to something between 0 and 5v.

R1 = 30k
R2 = 10k

If Vin = 20v, Vout = 5v
If Vin = 15v, Vout = 3.75v
If Vin = 10v, Vout = 2.5v
If Vin = 5v, Vout = 1.25v
If Vin = 0v, Vout = 0v

This is a really neat solution! One that I wouldn't have thought of in a billion years! I'd probably use an aref of something divisible by 1.024v so it'd make the calcumalations simple, but that's not really important.

Is this very accurate? I'd say it depends on the resolution of the ADC (May use internal 10 bit, but external 12 bit could be used.)

EDIT: 2.048*(2^-8) gives a resolution of 8mV. Very nice! Hopefully going to lay down a schematic soon, seems rather simple!
EDIT AGAIN: Math simplifying fail, 2.048/2^8 seems "cleaner" to me.
« Last Edit: April 07, 2012, 07:47:49 pm by Christopher »
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: Measure voltage and current with a micro??
« Reply #5 on: April 07, 2012, 07:56:27 pm »
You likely won't want to use Vcc as your reference unless you know just how precise the voltage regulator is.  Even still, you should probably use either an external precision reference or one of the MCU's internal references (if it has any.)

Don't forget that the tolerance of the resistors you use for your divider are going to play a big part in the precision as well.

Finally, don't expect to get great accuracy and don't confuse resolution with accuracy.  I'm sure someone will chime in about that.  But don't worry about it.  Just build your project and have fun.  You'll learn a lot.
 

Offline ChristopherTopic starter

  • Frequent Contributor
  • **
  • Posts: 429
  • Country: gb
Re: Measure voltage and current with a micro??
« Reply #6 on: April 07, 2012, 08:07:19 pm »
I'm thinking now about the uncertainty and the sources. I can see the main source is going to be the tolerance of the resistor, 90K and 10K will turn 20v into 2v, which is less than the 2.048v reference, and I've found these resistors in 0.1% tolerance which gives a value of 90K+-90 ohms which should be sufficient.

The last step is the plug 'n chug the min and max values into the potential divider formula (too late for that now), and determine an accuracy measure. Accuracy doesn't matter too much, as long as it's accurate to 0.5V, I'll be measuring it with a multimeter anyway, it's just nice to have a readout on the panel!

Oh, I'll be extracting the bulk of the circuit from old electronics, get me a 20V reference from an old DVD player or something, then take that down to 5v for the logic, and use some kind of regulator for the "user defined" voltage. Anyway you can leave this part to me ;).

Oh quick offtopic question, can anyone recommend a decent enclosure?
 

Offline T4P

  • Super Contributor
  • ***
  • Posts: 3697
  • Country: sg
    • T4P
Re: Measure voltage and current with a micro??
« Reply #7 on: April 07, 2012, 11:21:06 pm »
Hammond 1590BB ? If that's too small get those empty NAS Shells that are made of metal
Or Multicomp MB5W
« Last Edit: April 08, 2012, 01:53:59 am by Dave.S »
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1314
  • Country: us
Re: Measure voltage and current with a micro??
« Reply #8 on: April 08, 2012, 12:53:17 am »
I have this PIC-based voltmeter bookmarked, because I plan on using it for my power supply:
http://embedded-lab.com/blog/?p=396

For current, you just measure the voltage across a precision resistor.
« Last Edit: April 08, 2012, 12:55:03 am by MikeK »
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10014
  • Country: nz
Re: Measure voltage and current with a micro??
« Reply #9 on: April 08, 2012, 01:21:52 am »
For current, you just measure the voltage across a precision resistor.

You can either do this by

- Putting the resistor on the negative side of the supply and then reading the voltage to ground. (Very easy to do but negative side resistors are annoying since you no longer have a ground on the output)

- Putting the resistor in the positive side and using two of the micros differential inputs to read the voltage difference across the resistor.  (Still relativity easy but you need to work out what resistor value to use and if your micro has enough differential gain for it to work)

- Same as above but using a dedicated current sensor resistor IC or your own opamp circuit. (Requires a separate chip but then you get a nice 0-5v output to read with a clear ratio of volts to current.)


Since you only need 100mA option 2 is probably what i'd try first.
« Last Edit: April 08, 2012, 01:24:23 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 2000
  • Country: dk
Re: Measure voltage and current with a micro??
« Reply #10 on: April 08, 2012, 08:09:55 am »
Several of the AVR's have differential ADC's

Here is a link to a tutorial (you need to be logged in to get the files)
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=93557

http://www.avrbeginners.net/architecture/adc/adc.html
http://extremeelectronics.co.in/avr-tutorials/using-the-analog-to-digital-converter/
www.extremeelectronics.co.in/avrtutorials/pdf/adc.pdf

http://lecturer.eepis-its.edu/~eru/artikel/Microcontroller/ADC%20AVR.ppt

I seem to remember that the AVR-ADC likes around 10K as input impedance

I'd go for a >=8K AVR , as you would probably use floatingpoint (single precision is supported , by avr-gcc), and the price difference isn't that big between 8..16K.

Also you'd need min. 6 pins for the lcd , 4-data , RS and E.
RW could be tied to "W" only to save a pin.

This leaves out the 8-pins , but maybe a Tiny84 would fit the bill , else i'd go for a Tiny861.
But for the first proto i'd prob select a Mega328 (Lots of ram & flash).
I haven't chscked if they all have differential ADC's , look it up.

This sheet is rather handy , for basic selecting of AVR's ,
and should be understadable even for non germans -  ja/nein = yes/no
http://www.mikrocontroller.net/topic/242328#2465810


Edit:
AVR120: Characterization and Calibration of the ADC on an AVR
http://www.atmel.com/Images/doc2559.pdf

AVR121: Enhancing ADC resolution by oversampling
http://www.atmel.com/Images/doc8003.pdf
http://www.atmel.com/Images/AVR121.zip


/Bingo
« Last Edit: April 08, 2012, 08:17:26 am by bingo600 »
 

Offline ChristopherTopic starter

  • Frequent Contributor
  • **
  • Posts: 429
  • Country: gb
Re: Measure voltage and current with a micro??
« Reply #11 on: April 08, 2012, 08:48:20 am »
Brilliant guys!

I've been experimenting with the LM317 which I have here (probably going to use a decent linear regulator) with the SET pin connected to a PWM pin, which I have been slowly increasing the voltage from 0-5v (in bit steps, should be about 5/2^8=2mV steps), in the final design I will use an Opamp to amplify the voltage by 4 times.

Does the LT3080/3 set pin work in this way? I can just chuck 0-20V in the pin, and the output will be the same? If so this is going to be easy :).

For current I plan on using V=RI, with a 0.01% resistor and an ADC (Same as measuring voltage). Surely I can put the resistor between the output and the ADC? Current isn't really too nessasary so I'll probably scrap that, also the circuit controlling current on the reg will be quite complex, I just want this simple for now :P
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10014
  • Country: nz
Re: Measure voltage and current with a micro??
« Reply #12 on: April 08, 2012, 10:20:44 am »
Current isn't really too necessary so I'll probably scrap that, also the circuit controlling current on the reg will be quite complex, I just want this simple for now :P

It doesn't have to be. If you're monitoring the current you can do the current limit in software and reduce the voltage when you detect current above a set limit.

However, doing it in software like that will be quite slow compared to hardware, so it won't protect sensitive devices very well.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 2000
  • Country: dk
Re: Measure voltage and current with a micro??
« Reply #13 on: April 08, 2012, 10:43:26 am »
Current isn't really too necessary so I'll probably scrap that, also the circuit controlling current on the reg will be quite complex, I just want this simple for now :P

It doesn't have to be. If you're monitoring the current you can do the current limit in software and reduce the voltage when you detect current above a set limit.

However, doing it in software like that will be quite slow compared to hardware, so it won't protect sensitive devices very well.

If the dV current sense is connected to the AIN (Analog comp) , the detection (IRQ) would be quite fast. The challenge would be the PWM to set the "other AIN pin"

/Bingo
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf