AC voltage measurement with 16F77


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    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

  2. #2
    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

  3. #3
    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

  4. #4
    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

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