PDA

View Full Version : Measuring Volts and Amps digitally



The Master
- 14th July 2008, 10:11
Hi, Is it possible to measure voltage (6-50V) and Amps (600mA-1A) and send the value to a PIC chip? Im more bothered about the Amps because i want to display how much current is being drawn from a transformer. I have a digital multimeter that does both so im sure there are components out there, i just dont know which ones.

Acetronics2
- 14th July 2008, 13:19
Hi,

I think you'd better browse Microchip AN's ... Energy meters described !

Alain

The Master
- 14th July 2008, 13:48
I assum AN means App Notes. I had a look on the microchip website and i found a document that describes how to measure watts. It seemed to be what i wanted because it measured amps and volts to get watts but it either wasnt clear enough or i just dont get it.

What i understand now is that i need a device to measure volts/amps. That device sends an analogue signal to the PIC through an ADC pin. I also read that 2 volts has to be added to the analogue signal and it needs amplifying so the PIC can read it more accurately.

First thing, did i understand it correctly? Second thing, what is the component used for measuring amps?

skimask
- 14th July 2008, 13:59
Measure volts? Easy enough with a voltage divider, Sounds like you already know that much.

Measuring amps? Low value series sense resistor (mainly DC), current transformer (mainly AC), hundred different ways to do it...
Check Wiki under 'current source', some halfway decent information there. Same thing for 'ammeter'.

mikeh
- 14th July 2008, 14:01
Look At Maxim
Try Max4372

dhouston
- 14th July 2008, 16:04
For current, see http://www.allegromicro.com/en/Products/Categories/Sensors/currentsensor.asp

The Master
- 14th July 2008, 16:39
dhouston, that looks like what i want except that they dont seem to measure below 5A. I do like the fact that they support both AC and DC though. I have 8 outputs that i want to monitor. The max output current ranges from 600mA to 1A and some are AC, some are DC. I want to measure how much current is actually being used even if its less than the output's max rating.

mikeh, ive had a look and it looks like that chip would simply replace a potential divider circuit.

skimask, i take it "voltage divider" is the same as a "potential divider". I remember learning about them in school but so far i dont think ive ever put one together. I think i can see how it would work though. It looks like it would simply lower the voltage to a level suitable for the ADC pin on the pic.

Ive read a wikipedia page about ammeters and it said that you put a resistor in series and measure the voltage accross that resistor and that will tell you how many amps are being drawn through it. This way sounds simple but you said its used *mainly* for DC. Does that mean i can use it on AC? Half of the outputs are AC. What resistor would i use? For the 50V 1A output i assume i need a 50W resistor with the smallest resistance i can find. Rapid sells an OR05 50W Aluminium clad power resistor (http://www.rapidonline.com/Electronic-Components/Resistors-Potentiometer/Power-Resistors/Aluminium-clad-wirewound-resistors/65217). It seems a little big but i guess 1A at 50V is a lot for small components.

skimask
- 14th July 2008, 17:52
Voltage divider - Potential divider - it's all got potential to divide :)
Easy enough, example: 2 same value resistors, call them 1K, both in series, top of the stack to your input voltage which never goes above 10V, bottom of the stack to ground (which is also your PIC Vref-), middle of the stack goes to your A/D input on the PIC. If the input volts is 10V, the A/D input sees 5v (Kirchoff's Law simplified - the sum of the voltage drops in a circuit is equal to the applied voltage, you're splitting the voltage across 2 equal resistances. If the resistors were different, the voltage you would read at the A/D input would be a ratio of those 2 resistances).

Current sense resistor - yes, voltage 'developed' across the low value resistor would tell you how much current is going thru it, with just a little bit of math.
Would it work on A/C also? Sure...You could rectify, filter, and sample/smooth the input voltage and get the same thing as a DC input...or just do it all in software :).

50W resistor - You're thinking about it backwards, go the other route with the number figuring. Yes, 50V @ 1A = 50W...but your sense resistor is usually on the order of .1ohm or less.
E = IR, P = EI, therefore P = IIR.
If you've got one amp, one squared = 1, .1ohm x 1 = .1W.
But throw in a bunch of fudge factor!

dhouston
- 14th July 2008, 18:55
dhouston, that looks like what i want except that they dont seem to measure below 5A.
I think you are misreading it. That's +/-5A full scale with 185mV per Amp which means each mV represents 1/185A or ~5.4mA.

Assuming 5V and a 10-bit ADC, each bit will equal ~4.88mV meaning the minimum reading is about 26mA.

The Master
- 14th July 2008, 19:15
Ok then, the potential divider sounds good. It allows for a variable resistor for calibrating too although i would like to do most of that on the PC.

The outputs im using will output AC and DC Ripple. There will be times when a capacitor is connected to the DC side but not always. I read somewhere that the V and A should be sampled at a higher frequency than what they are measuring. It suggested 400 samples per second. Here in the UK the AC is 50Hz so if i take the highest reading from each set of 400 samples and ignore the rest then i should get the values i need.

About rectifying the AC. Correct me if im wrong but im pretty sure i should rectify it *after* the potential divider then deal with it in the same way as the DC Ripple.

Im not sure i understand the resistor part. I see how you got the 3rd formula from the first 2 but i dont know about the rest. For a start, what is E? A search on google said "E is the e.m.f. of the power supply (the theoretical maximum voltage across the terminals when no current is flowing)". That doesnt really make any sense to me.

0.1W seems a little small for something thats dealing with 1A at 50V but i see that if theres hardly any resistance then it shouldnt matter so much. I might understand this better when i understand what E is

What "bunch of fudge factor" would you recommend for that example?

skimask
- 14th July 2008, 19:30
It allows for a variable resistor for calibrating too although i would like to do most of that on the PC.
Yes, you could switch in a voltage reference chip (can't remember the part number for them, but the ones I've used are 4.096v types)...


The outputs im using will output AC and DC Ripple.....
About rectifying the AC. Correct me if im wrong but im pretty sure i should rectify it *after* the potential divider then deal with it in the same way as the DC Ripple.
Yes, otherwise you'll be fighting highs against lows and totally screwing up your readings.


Im not sure i understand the resistor part. I see how you got the 3rd formula from the first 2 but i dont know about the rest. For a start, what is E? A search on google said "E is the e.m.f. of the power supply (the theoretical maximum voltage across the terminals when no current is flowing)". That doesnt really make any sense to me.[/QUOTE}
E = voltage, electromotive force, as in E=IR. Rarely do I see V=IR although it is used sometimes.

[QUOTE]0.1W seems a little small for something thats dealing with 1A at 50V but i see that if theres hardly any resistance then it shouldnt matter so much. I might understand this better when i understand what E is
Exactly, that's why those little bitty MOSFETs can pass such huge currents...because there's no resistance across them.

Fudge factor? I couldn't tell you. I suppose as much fudge factor as your wallet and the circuit board can support...

The Master
- 14th July 2008, 19:33
dhouston, most likely :)

On the main page it says Measurement Range (A) +/- 5 to 30. When you click on it it does say "66 to 185 mV/A output sensitivity" but i thought "Measurement Range" was the range that it could measure. I divided 5V by 4.88mV and got roughly 1024. So that must be the 10-bit thing. A digital value of 0-1024 is equivelent to 0-5V (i think)

Im still confused though. How does that relate to amps? Or is it that 0-1024 is equivelent to 0-5A?

I think im gonna go with the resistor and potential divider circuit but i would still like to understand this

The Master
- 14th July 2008, 19:58
I dont know about a voltage reference chip. I was thinking to have a variable resistor to get it more or less calibrated properly then have an offset value that can be set by the PC so i can fine tune it without opening everything up to get to the PCB. If a voltage reference chip does what i think it does then it sounds like a good idea and i might use one of those instead.

Ahh, ive always know V=IR as ohms law. Ive never seen E=IR before. Could that be a new / old or english / american thing?

I think if i calculate the wattage of resistor i need then double it i should be alright. Im going to put a safety cut out on too so if either AC or DC tries to draw too much current it will warn you on the PC screen and if it goes over a certain value it will cut the power to that transformer. A PIC chip will control cutting it off (the PC just sets the values) so it should be pretty quick to cut the power incase of a short etc.

I think i understand that equation now.
P = IIR
ResistorWattage = Amps X Amps X ResistorOhms

Rapid sells some really low value resistors but they are a bit expensive. The only ones i see that are 0.1ohms or less are 50p each! I need 8 so thats £4.00 already (plus a bit for accidents). They are 4W though. Ill have to keep looking for some cheaper ones.

Thanx for that formula. I think it will help with other circuits too. I always use 0.5W resistors but now i could use smaller ones in certain places depending on the amps and ohms. I should start making a list of usefull formulas.

What is the voltage range of a PIC chips ADC input pins? Im sure i could find the lowest value out by trying it but i want to find out the highest value too without releasing the mysterious blue smoke

skimask
- 14th July 2008, 20:20
If a voltage reference chip does what i think it does then it sounds like a good idea and i might use one of those instead.
It probably does. But if you use high tolerance resistors, you should only need to calibrate once.


Ahh, ive always know V=IR as ohms law. Ive never seen E=IR before. Could that be a new / old or english / american thing?
2 peoples separated by a common language! :D


I think i understand that equation now.
P = IIR
ResistorWattage = Amps X Amps X ResistorOhms
Rapid sells some really low value resistors but they are a bit expensive. The only ones i see that are 0.1ohms or less are 50p each! I need 8 so thats £4.00 already (plus a bit for accidents). They are 4W though. Ill have to keep looking for some cheaper ones.

I think they're expensive because it takes soo much 'energy' (manufacturing energy, R&D, etc) to get them to those low low values and keep decent tolerance over a wide voltage/current/temperature range.


I always use 0.5W resistors but now i could use smaller ones in certain places depending on the amps and ohms.
1/4w are generally the cheapest, whether SMT or thru-hole.


I should start making a list of usefull formulas.
wikipedia...for instance
http://en.wikipedia.org/wiki/Ohm_law
http://en.wikipedia.org/wiki/Voltage
http://en.wikipedia.org/wiki/Electric_current
or my personal favorite...
http://en.wikibooks.org/wiki/Circuit_Idea/Walking_along_the_Resistive_Film
and so on and so on...

What is the voltage range of a PIC chips ADC input pins?
Vdd to Vss... It's all in the A/D section of the datasheets

dhouston
- 14th July 2008, 21:20
Im still confused though. How does that relate to amps? Or is it that 0-1024 is equivelent to 0-5A?
The PIC's ADC channels can be configured as 10-bit or 8-bit and there are different reference voltages that you can use. I was assuming you would use 10-bits and Vref=5.

5/1024=0.004882812 or ~4.88mV per bit.

The datasheet for the Allegromicro ACS712 chip says it's range is +/-5A and its sensitivity is 185mV per amp. At 0A, its voltage output is Vcc/2 (it is bidirectional, after all). For AC measurements using Vcc=5V, at 600mA, it would output 2.389-2.611V and at 1A, it would output 2.315-2.685V.

What else do you need to know?

The Master
- 14th July 2008, 21:49
Thanx for the links skimask. Lol, "datasheets", should have thought of that 1 first.

dhouston, i get half of that. Yes i would use 10 bit rather than 8 for more accuracy. I understand "5/1024=0.004882812 or ~4.88mV per bit." but i just want to be clear about the 5. 5 is Vref but what is Vref? I think Vref is the maximum voltage that the PIC will accept on the ADC pin.

In this example the PIC chip's ADC input should range from 0 to 5 in steps of 0.004882812. I think so far this is exactly the same as what i would do if i was using a resistor instead.

Now for the Allegromicro ACS712 chip. +/- i take it means it can accept the current in either way or as AC. Does that make 5A the maximum current rating for this chip?

Vcc/2 makes sense because as far as i know the PIC chip's ADC can only accept a positive number. So a value below Vcc/2 means negative current and a value above Vcc/2 is positive current.

What is the sensitivity? I dont really understand that part

dhouston
- 14th July 2008, 22:44
5 is Vref but what is Vref?
Read the ADC section of your PIC's datasheet.

Does that make 5A the maximum current rating for this chip?
That's what +/-5A means.

What is the sensitivity?
That means the output voltage will increase/decrease 185mV for a 1A current.

The Master
- 15th July 2008, 09:34
I think i understand it now. If 5A is the maximum and the output increases by 185mV for each amp then the output range should be 0-925mV. If vcc is 5 then you add 2.5 giving 2.5-3.425V for positive so the entire range must be 1.575-3.425V.

Ive read a datasheet for a PIC that has ADC but i didnt see anything about the lowest input voltage (unless i missed it or didnt understand it). Would i be right in saying that you take the output from the other chip and lower it so the range becomes 0-1.85V and set the PICs Vref to 1.85V? I think this is what the amplifier thing was about that i read somewhere. I think the idea is to stretch the 1.85V so the range goes from 0V all the way up to 5V so the PIC can read it easier

I dont think i should have this problem using the resistor method because i can set the PICs Vref to the vdd pin (5V) then use the potential divider circuit to make sure its output is 5V when a little over the maximum amount of amps are being drawn (im making it a little over so i can add overload warning and safety cutoff)

Where does 30 come into it? On the main page it said +/- 5A to 30A

Ioannis
- 15th July 2008, 09:54
Where does 30 come into it? On the main page it said +/- 5A to 30A

Different chip versions....

Ioannis

The Master
- 15th July 2008, 10:00
Ahh, I see. I was getting confused before because it looked like the range of the chip was 5-30. I see now at the bottom of the other page there are 3 versions of that chip with different ratings

dhouston
- 15th July 2008, 11:46
You have some options:
1. Use +5V Vdd as Vref and use it as is with reduced sensitivity
2. Use a lower external VRef (which could be as simple as a voltage divider from Vdd)
3. Use Vdd as Vref and an opamp setup for DC gain to amplify the signal

However, all this is the easy part. When measuring AC voltage/current you will need to sample both many times per half-cycle (what frequencies are you dealing with?) and average the readings over each half-cycle. This also means you'll need to detect zero crossing.

The Master
- 15th July 2008, 13:26
I think for the actual project im going to use vdd because the potential divide part can change its value to make use of the full 5V (i dont have any outputs 5V or less).

The frequency is 50Hz (UK AC) but because its DC ripple i guess that makes it 100Hz. As i said before im going to only take the highest value. If i sample it at about 400 times a second then at least one sample will be extremely close to the absolute max. Because of DC ripple it also has 2 chances per second to get as close as possible. I can then discard all the lower readings. The highest value will be reset after each 400 samples so it can detect a drop in current.

Im not sure if a PIC chip can check the ADC chanels that fast though. I might need a higher resonator. If using 10-bit then the chip can detect 1024 different voltage levels. At 5V max each level is 4.8828125mV. As long as the input value is within 4.8828125mV of the highest point in the DC ripple i should get an accurate reading. The good thing about DC ripple (or any kind of sinewave based line) is that it stays near the top for a longer period of time than any other point in the wave but still i might need more than 4 sample points on each bump. To make it even worse the pic chip will have to deal with 8 ADC pins. It might be an idea to split the work between multiple PICs

skimask
- 15th July 2008, 13:32
The frequency is 50Hz (UK AC) but because its DC ripple i guess that makes it 100Hz......................
To make it even worse the pic chip will have to deal with 8 ADC pins. It might be an idea to split the work between multiple PICs
If you run that 100hz DC ripple across a capacitor with a very small value bleed resistor, said capacitor will quickly charge up to the peak value of that ripple, thereby negating your need to quickly sample the output, maybe even isolate it with a diode so it (the cap) can't bleed back into your supply. Basically, you end up with a full wave filter without much of a load.

The Master
- 15th July 2008, 14:14
I thought about that but decided not to because i was unsure about it leaking back into the output. If a simple diode takes care of it then i guess the rectifier would do the same thing.

I worked out that witout a capacitor or anything that the PIC could get up to 0.38V less than what it should do. That equates to about 78 levels difference out of 1024 or a 7.6171875% error. All that is based on my maths being correct but 7.6% sounds about right.

I just had an idea. dhouston mentioned zero-crossing. I already know how to detect that thanks to the PWM circuits ive made before. What i could do is wait for a zero crossing then wait a certain amount of time then run a few samples. That should put all the samples closer to the peak.

The capacitor idea sounds really simple though. If the capacitor can keep the level high enough between peaks then in theory i could sample each one once every second. I would like a single chip to sample all 8 if possible and send the data to the PC through serial so i think i do really need the capacitor.

What is the purpose of a "bleed" resistor? Is that to go in series or parallel with the capacitor? I would need the capacitor to empty pretty quick but not as quick as the frequency of the input. I dont want to have to wait 10 mins while it realises the output isnt drawing as much current anymore.

Edit: I plan to buy an oscilloscope with these components so it will be easier to test and see the sinewave

skimask
- 15th July 2008, 15:52
If a simple diode takes care of it then i guess the rectifier would do the same thing.
Pretty much does, but you have to calculate the offset caused by the diode's forward voltage drop (either ~.25v or ~.6v depending on the type)


What is the purpose of a "bleed" resistor? Is that to go in series or parallel with the capacitor?
Series to ground, parallel across itself, whatever, you'll have to figure that out yourself (think R/C time constant). The bleed resistor will let the cap falls off if/when the input voltage average drops. I think you've got the idea, just need to plug some numbers into a couple formulas.

The Master
- 15th July 2008, 16:21
I think the diode part can be compensated by calibrating the circuit. Im going to have a variable resistor that can move the output in the range of 3-7V, then i will use the computer calibrating part (either the chip of a furmula on the final result) as a kind of fine tuning.

Just thinking about calibration. Whats the best way? I was thinking to connect up my multimeter, apply different loads and match the output to the multimeters output. Would that work well enough?

How do you choose a capacitor and bleed resistor? I know you sort of told me but im not sure. Which do you pick first? The capacitor or the resistor?