AC voltage measurement with 16F77


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: AC voltage measurement with 16F77

    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.
    Last edited by HankMcSpank; - 16th May 2011 at 13:53.

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: AC voltage measurement with 16F77

    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.
    Charles Linquist

  3. #3
    Join Date
    May 2011
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: AC voltage measurement with 16F77

    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?

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: AC voltage measurement with 16F77

    for sampling cobien I must take samples at least?

    more translation for those that can help this thread:

    combien = how many

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: AC voltage measurement with 16F77

    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.
    Charles Linquist

  6. #6
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: AC voltage measurement with 16F77

    Quote Originally Posted by Charles Linquis View Post
    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...mpling_theorem

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: AC voltage measurement with 16F77

    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 Linquist

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts