Measure voltage and current with a micro?? - Page 1
Forum section: electronics / beginners

author: Christopher
author_rank: Frequent Contributor
timestamp: April 07, 2012, 05:38:40 pm
content: 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 panelhttp://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.

author: IanB
author_rank: Super Contributor
timestamp: April 07, 2012, 06:21:51 pm
content: 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?

author: Christopher
author_rank: Frequent Contributor
timestamp: April 07, 2012, 06:48:28 pm
content: 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.

author: bingo600
author_rank: Super Contributor
timestamp: April 07, 2012, 06:52:54 pm
content: Whats the measured Range ?A voltage divider and an AVR would give 10 bit resolution (1024 steps)/Bingo

author: Christopher
author_rank: Frequent Contributor
timestamp: April 07, 2012, 07:05:40 pm
content: 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 = 30kR2 = 10kIf Vin = 20v, Vout = 5vIf Vin = 15v, Vout = 3.75vIf Vin = 10v, Vout = 2.5vIf Vin = 5v, Vout = 1.25vIf Vin = 0v, Vout = 0vThis 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.

author: TerminalJack505
author_rank: Super Contributor
timestamp: April 07, 2012, 07:56:27 pm
content: 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.

author: Christopher
author_rank: Frequent Contributor
timestamp: April 07, 2012, 08:07:19 pm
content: 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?

author: T4P
author_rank: Super Contributor
timestamp: April 07, 2012, 11:21:06 pm
content: Hammond 1590BB ? If that's too small get those empty NAS Shells that are made of metalOr Multicomp MB5W

author: MikeK
author_rank: Super Contributor
timestamp: April 08, 2012, 12:53:17 am
content: I have this PIC-based voltmeter bookmarked, because I plan on using it for my power supply:http://embedded-lab.com/blog/?p=396For current, you just measure the voltage across a precision resistor.

author: Psi
author_rank: Super Contributor
timestamp: April 08, 2012, 01:21:52 am
content: Quote from: MikeK on April 08, 2012, 12:53:17 amYou 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.

author: bingo600
author_rank: Super Contributor
timestamp: April 08, 2012, 08:09:55 am
content: Several of the AVR's have differential ADC'sHere 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=93557http://www.avrbeginners.net/architecture/adc/adc.htmlhttp://extremeelectronics.co.in/avr-tutorials/using-the-analog-to-digital-converter/www.extremeelectronics.co.in/avrtutorials/pdf/adc.pdfhttp://lecturer.eepis-its.edu/~eru/artikel/Microcontroller/ADC%20AVR.pptI seem to remember that the AVR-ADC likes around 10K as input impedanceI'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/nohttp://www.mikrocontroller.net/topic/242328#2465810Edit:AVR120: Characterization and Calibration of the ADC on an AVRhttp://www.atmel.com/Images/doc2559.pdfAVR121: Enhancing ADC resolution by oversamplinghttp://www.atmel.com/Images/doc8003.pdfhttp://www.atmel.com/Images/AVR121.zip/Bingo

author: Christopher
author_rank: Frequent Contributor
timestamp: April 08, 2012, 08:48:20 am
content: 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

author: Psi
author_rank: Super Contributor
timestamp: April 08, 2012, 10:20:44 am
content: Quote from: Christopher on April 08, 2012, 08:48:20 amIt 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.

author: bingo600
author_rank: Super Contributor
timestamp: April 08, 2012, 10:43:26 am
content: Quote from: Psi on April 08, 2012, 10:20:44 amIf 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