Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Measuring AC voltages using MCU

Status
Not open for further replies.

Pagedown

New Member
hi, I am doing a project involving an avr mcu and I'm supposed to measure ac voltage, current. The current is measured using a C.T which should be safe, while my problem is measuring the AC voltage.

1. How should I isolate it? (I stepped down the 240V to around 2.4V)

2. Does AVR mcu adc measure AC voltage/current(stepped down) efficiently? 0-5VAC 0-200mA How accurate is it? or should I use an external ADC?
 
1. To isolate the voltage you can use a small power transformer, such as a 6.3V one. You would need to calibrate the transformer with a digital multimeter.

2. ADCs measure DC voltage. You need to convert the AC to DC. Use a precision rectifier circuit for best accuracy. Depending upon the accuracy (resolution) you need the ADC in the mcu should work fine.
 
If you have a microcontroller you could crunch the numbers in software (rather than use precision external hardware).

1. resistor couple the 2.4v AC waveform to the ADC
2. Measure only the positive half cycle (with no diode drops)
3. just allow the negative half cycle to be clamped by a diode to ground
4. When the positive half cycle is detected;
5. sample the voltage 10 or 20 times over that half cycle
6. do software averaging of the 10 samples, to get an RMS value
 
hi RB,
I think point #6, will result in an Average value of V*0.637 rather than the RMS value of V*.707
 
If the uC ADC speed is >> AC Hz, sample to find peak and multiply by .707. Otherwise rectify & size the filter cap for smoothing vs response time. <<<)))
 
Finding the RMS average in software is well known. I would oversample 100x not 10x but that depends on how good an answer you want.
ADC in AVR verses external ADC: Read the data sheet. If you want 24 bits get an external ADC. If you can live with the AVR's 8/10 bits and can calibrate the reference voltage then use the AVR. Will +/-1% work?
 
If you want the true RMS value, then you oversample the signal, both plus and minus side of the waveform, take the square of each sample, sum these squared samples for one cycle, and then take the square-root of the sum. If it's easier to deal only with positive signals in the A/D then use a precision rectifier to convert the AC to unipolar AC pulses.
 
1% should be okay. Thus is 8 to 16 bits ok?

Another thing I have to calculate is the voltage sag and THD, which I have no idea at all now.
 
1% should be okay. Thus is 8 to 16 bits ok?

Another thing I have to calculate is the voltage sag and THD, which I have no idea at all now.

hi,
I would suggest a RMS full-wave rectifier OPA, then a smoothing circuit OPA.
Calculating the THD is not going to easy using a PIC directly, again external hardware will make the program easier.
 
So the real story is slowly getting out.

Voltage, current, power, RMS, Average, peak, and now THD & voltage sag

1) For a real power meter you should makes reading continuously.
2) For a school project, and maybe for a real meter it is OK to read data in only 20% of the time and then spend the next 80% of the time doing the math and displaying the data. If you analyze 4 cycles of power and miss the next 20 cycles then analyze the next 4, this will not change the voltage or current readings. I think it will not affect power or THD.

I would give up on op-amps ahead of the AVR and make a “oscilloscope” project where you read in the voltages store one cycle (or even ½ cycle), do the math, then read in another cycle. Your different modes are just math!

As a joke I looked at the Tiny AVRs that only have 512 memory max. That is not much data to do the THD on but could work. Get a part with hardware multiply because the math will be much faster. This is not Agilent (HP) quality but, with 500 to 1000 samples over one cycle (or ½ cycle) you could get average, RMS, PK very well. With some clever math THD can be measured.

It looks like this is a power line meter. Your readings will be 100v to 130v so 8 bit ADC will work. A real meter might measure 1000 volts one time and 1mV the next. I see no need for you to use 24 bit ADC.

I have done this where hardware did the average and RMS and I have done this in software. If you choose the later you can add functions later without changing the hardware. I see an AVR, LCD and a handful of Rs and Cs in front of the ADCs. + A big math project.
 
Thanks for all your lightening information.

ya, it is a school project, my final year project which will grade my class, I hope to do it the best I could. I am not good in programming, but okay in maths. I shall worry about the programming later on. At this moment, I try to get the best hardware sensing circuit so that the later part may be much easier.

I look forward for more suggestions on the hardware sensing for voltage and current, keeping in mind that i need to measure
Voltage, current, power, RMS, Average, peak, power factor and THD & voltage sag =)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top