PDA

View Full Version : AC voltage measurement with 16F77



MARWEN
- 15th May 2011, 03:19
hello, I want something conprendre conserne measuring an AC voltage based on a 16F877 and I'll post it on an LCD, a voltage is 400V MAX

http://www.techniques-ingenieur.fr/res/media/docbase/image/sl4218248-web/4226290-web.gif

N : nombre d’échantillons
Ui : valeur de l’échantillon i.
What are the basic conditions to calculate the RMS value ???
good I want someone to explain a bit with knowledge in electronics
This formula is used to measure the effective value of a variable voltage or not??
whether the value measured by this formula is not the real value of tension is what I will multiply rapprort division transformer bridge and go to the pure real value?
give me the basic points to measure tension via a 16F877 and found an acceptable image
Please can someone explain to me one!

Demon
- 15th May 2011, 03:51
Translation if it helps anyone:

comprendre = understand
nombre d’échantillons = number of samples
valeur de l’échantillon = value of sample

amgen
- 15th May 2011, 12:37
Rms voltage is just equal to .707 of the peak, filter ac long enough to get peak voltage on a cap, (with resistance voltage divider), read and mult by .707. Good for a standard sine wave.

don
amgen

HankMcSpank
- 15th May 2011, 12:48
You need a two resistor potential divider to drop that 400V down to 5V, so for 400V (lets call them units)...

top resistor needs to drop 395 units
bottom resistor needs to drop 5 units

therefore,

3.95K R1 (top resistor)
.5k R2

or

7.9k R1
1k R2

etc, & so on (use 1% tolerance resistors or better)

Ok, now you've got 5V AC peak to peak...you need to get that to RMS.

If you wnat a reasonable degree of accuracy, then personally, I'd feed the resulting 'to be measured' 5V AC into an ADC pin via an opamp to rebias it at mid point of 2.5V DC ....then use the PIC's special event trigger & 'sample' at a sufficiently high enough rate (presumably you're only thinking of measuring 50Hz/60hz AC)... to extract 'peak' in real(ish) time ...then it's a simple enough conversion, just multiply the result by 0.707 (though you'll need to get creative to work around PICbasics lack of decimals!)

mister_e
- 15th May 2011, 21:31
[.... insert crap here]

PS: Sorry for the forum friends, but really much too difficult to translate that into our beloved Cambridge Pure English.
Les nerfs le béret... pis après ça on me dit que mes post sont inutiles et on les "édite".... pfffff...

Dave
- 16th May 2011, 11:39
HankMcSpank, Wow, With values like that, you sure like to waste power.... 7.9k R1
1k R2 will yield 17.9775 peak watts or 12.71 watts RMS... Better use 50+ watt resistors... Maybe you can heat your house with this voltage divider...

Dave Purola,
N8NTA

HankMcSpank
- 16th May 2011, 13:45
Do you know what... I edited my original post - checked last night ...it/I hadn't posted!! Then I did a short follow up post last night (along the lines of "those resistances aren't recommendations but just to show the thought process...."). just checked in here again...that follow up post never made it either! I've also noticed that my R2 resistance value was out by a factor of 10! (must do better) ....anyone dabbling in 400V AC, must surely beconfident enough of what they're doing & not just roll with one dodgy/casual post!

To be clear...I was outlining the process behind dropping 400V AC down to 5V AC...not the actual resistors to use....(that's why I showed two examples stepping up in magnitude).... in practise I'd go for much higher resistors eg 395k & 5k @ 200V peak (cos the 400V AC anticipated is peak to peak) , that's about 500uA through the two resistors ....and a power dissipation of about 100mW.

Charles Linquis
- 16th May 2011, 16:21
Be careful! Connecting to the AC Mains with only resistors is dangerous. I would strongly recommend some type of isolation.


I built a circuit that may do what you are attempting. It was a voltage detector that output voltage via RS-232 and would also detect and report single-cycle dropouts. I needed a power supply for the circuit, so a small transformer was an obvious choice.

The transformer that I used had two secondaries. One secondary powered the PIC. The other secondary was the "measurement secondary".

The transformer was about 4X the size it needed to be for the current provided. This over-sizing was necesary because the bridge rectifier + cap + LM7805 regulator for the PIC only consumed current near the peaks of the AC waveform, which caused distortion on the peaks. This distortion (almost like "clipping") was easily visible on a scope on the secondary that fed the PIC, but was barely noticeable in the second secondary, which is why I needed the dual-secondary part. I used a Tamura 3FD-316 (dual 8V@150mA). The unloaded secondary (the measurement secondary) needed a small load in order to produce perfectly sinusoidal output (1K ohm) . The PIC A/D input is fed from the wiper of a 10K trimpot also across the measurement secondary (the CAL pot). One end of the measurement secondary is connected to a 499 ohm/499 ohm divider from the PICs supply. This biases it up to 2.5V, so the PICs A/D can read both half-cycles.

The device works perfectly, and is safe due to the transformer isolation.

MARWEN
- 18th May 2011, 00:43
thank you very much for all the Reply before any

ince nothing to fear I will not make a practice just a theoretical study to measure AC voltage through a 16F877.

my point of view eg for a maximum voltage of 400V is equivalent to 5 v or there is a report 8O my principle is:
5Vmax ===> RMS 3.535
ie to determine the max value of real power will be multiplied by K = 80 * √ 2
I want to know what are the constraints to purpose to have a good accuracy as for example by taking 1Vmax image 160V max formula Trap for me was giving good results to small voltages such as 0.5 max I have an rms of 0.7071??
for sampling cobien I must take samples at least? to measure in a period of time knowing that the signal input 50HZ and I will work on adc = 10
I had to commit to measure with good accuracy as the RMS value of voltage between 0 and 5v?

Demon
- 18th May 2011, 04:14
for sampling cobien I must take samples at least?

more translation for those that can help this thread:

combien = how many

Charles Linquis
- 18th May 2011, 06:21
If you are going to measure true RMS, and you need cycle-by-cycle measurements, then you need to take about 17 samples per half cycle for really good accuracy.

But I doubt you need answers that fast. You can probably just sample at your heart's content (fairly slowly), as long as you sampling rate is not a multiple or sub-multiple of the line frequency. If you sample at a 13 Hz rate, for example, and sample for 2 or 3 seconds, then you will "grab" the cycle at various parts of the waveform. Square each reading, sum them up and divide by the number of samples. Since you are using a 16F chip (why do people keep using them?), you can't use PBPL to easily deal with the sum of squares you will accumulate.

If you *are not* after an RMS reading, then you should peak-detect the AC with a bridge rectifier, store those peaks in a capacitor, take one reading, divide by two or three and be done with it.

The AC mains have a very low impedance, so true RMS probably isn't necessary to measure line voltage accurately. Current, however, is another matter.

Charlie
- 22nd May 2011, 11:49
If you are going to measure true RMS, and you need cycle-by-cycle measurements, then you need to take about 17 samples per half cycle for really good accuracy.

But I doubt you need answers that fast. You can probably just sample at your heart's content (fairly slowly), as long as you sampling rate is not a multiple or sub-multiple of the line frequency. If you sample at a 13 Hz rate, for example, and sample for 2 or 3 seconds, then you will "grab" the cycle at various parts of the waveform. Square each reading, sum them up and divide by the number of samples. Since you are using a 16F chip (why do people keep using them?), you can't use PBPL to easily deal with the sum of squares you will accumulate.

If you *are not* after an RMS reading, then you should peak-detect the AC with a bridge rectifier, store those peaks in a capacitor, take one reading, divide by two or three and be done with it.

The AC mains have a very low impedance, so true RMS probably isn't necessary to measure line voltage accurately. Current, however, is another matter.

I'm curious - what's the source of these numbers? (17 samples, 13 Hz)

My understanding is that you need to take instantaneous samples at the Nyquist rate (or beyond). You then collect a reasonable number of samples and calculate RMS value from them.

For example, say you want to measure 50Hz true RMS. Then you must sample at at least 100 Hz. (minimum Nyquist rate) At this rate, a reasonably large number of samples can be collected in a sample period of say 1 second (reasonable refresh rate for an LCD display). Stuff 100 samples in memory, square the value measured for each sample, add them all up, divide by 100, take the square root, display the answer. This might be a bit intense for a PIC, but with careful code execution planning should be doable.

Personally, I'd shoot for 1 KHz sample rate and 1,000 samples, on one of the more powerful devices. Here's a good reference for my numbers: http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem

Charles Linquis
- 22nd May 2011, 14:40
The numbers are simply derived.

First, if you are going to do a cycle by cycle RMS (virtually no one needs this, by the way), then you need to decide how much accuracy, at what crest factor you want.
If you assume a crest factor not too far from 1, then to get an accuracy of 2%, then you would need to make certain that you always get a sample within 2% of the peak.
The peak is far more important than the zero crossing when calculating RMS. The zero crossing is of low amplitude, and as such, contributes little to the final result.

The sine of 78 and 102 degrees are both about .98 - within 2% of the peak value. 90-78 = 12 degrees. So you have to sample at least every 12 degrees of the waveform to make certain that you will sample at a time that is within 2% of a peak. That means 180/12 = 15 samples (my memory was a little off).

If you don't need answers quickly, then you can simply take a large number of samples, square them, average them and take the square root. As long as you sample at a random interval (at least compared to the mains frequency), and take enough samples that you are guaranteed to get several very near the peaks, then your results will be accurate as long as the voltage wavform isn't changing very rapidly. Think about it. You can either take 100 samples on one cycle, or 100 samples at random on 100 cycles. Both will yield the same result. The only downside in doing it the second way is that you have to wait 100 cycles for the answer.

Nyquist is operative only when you are trying to re-create a waveform, not when you are trying to measure it. We certainly don't care about aliasing when doing something so mundane as RMS.

If the OP was building an MP3 player, my answer would be different.

Charles Linquis
- 22nd May 2011, 20:54
Now that I have had some coffee, I would like to add a few comments and corrections to my earlier post.

First, I realize that RMS isn't peak, and that the translation isn't 100%, since the RMS values are proportional to the sample values squared. An error of 1% at the peak translates to a larger error, since the error term is squared. Of course there are also errors on the rising and falling parts of the waveform as well, and they can be large (since the rate of change is higher than on the peaks), nonetheless, they contribute less to the overall value, since they are of lower amplitude.

Also, I mentioned that the sine of the sine of both 78 and 102 degrees are within 2% of the peak (> .98). It is actually 79 and 101. But to get a sample in that range, you only have to sample every 101-79 = 22 degrees. That amounts to a little over 8 samples per half-cycle.

Revisiting this issue has piqued my curiosity enough that I'm going to dig into it a bit more.