Measuing AC line frequency

Discussion in 'The Projects Forum' started by kriscpm, Oct 5, 2013.

  1. kriscpm

    Thread Starter New Member

    Oct 5, 2013
    7
    0
    Hi all,

    I would like to ask for suggestions on how to measure the frequency from my main supply which is 240V? As i know the frequency varies very little, hence i would like to measure it as accurate as possible.

    The reason for this is because I'm doing a smart meter project with Arduino Mega 2560. I've researched and I saw people using LM2917 or comparator or AN795. However, I am not so sure on how to connect them from the main supply. As i know, I need to step down the voltage from 240V to 6V. I have no ideas after that.

    Suggestion are much appreciated. :)
    Thanks!
     
  2. crutschow

    Expert

    Mar 14, 2008
    12,977
    3,221
    To accurately measure the mains frequency you can count many cycles and then calculate the average. The longer the average, the more precise the measurement. The accuracy of the measurement depends upon the accuracy of the crystal clock of the counter or microprocessor.

    A small filament transformer should work to generate 6Vac from 240Vac. It will also provide safety isolation from the mains.
     
  3. kriscpm

    Thread Starter New Member

    Oct 5, 2013
    7
    0
  4. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    5,769
    1,103
    We don't know the transformer spec there (or if it's stated I can't see it in that horrible image). I would be happier if the circuit had a TVS or zener to protect the Arduino input from overvoltage.
     
    panic mode likes this.
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Is not the Arduino equipped with a voltage regulator?
     
  6. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    5,769
    1,103
    Even if the power supply of the Arduino has a regulator the analogue input pins can be over-driven if care is not taken.
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    The provided schematic is missing several important elements, such as the LCD connections, where the 5V supply comes from, power bypass... and so on.

    I don't know why all those parts around the comparator are there; you could just conect the transformer to a digital input thru a suitable resistor. An "analog" version of the input is also presented to the controller possible to measure the peak voltage.

    (The above assumes ESD diodes exist on the inputs and can be used as voltage clamp devices.)

    Bottom line: toss the borrowed schematic and develop one of your own that you fully understand.
     
  8. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
  9. wayneh

    Expert

    Sep 9, 2010
    12,088
    3,027
    True of course, but a long measuring time may obscure what the OP is looking at. The OP may be interested in the mean AND the standard deviation. If you wanted to measure deviation from the mean, I think ideally you'd like to measure every single wave. Wouldn't you use a PLL method for this? Or maybe a microprocessor that can process wave-by-wave against an accurate clock.

    Maybe I'm overestimating the needs of the OP.
     
  10. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    5,769
    1,103
    Is this a power meter? If so, why do you need to know the mains frequency?
     
  11. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Indeed...I really hate those schematics that have black background, and green, and blue as wiring colors. Hopless to read.
     
  12. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    I did a project here;
    http://www.romanblack.com/onesec/High_Acc_Timing.htm
    (about half way down the page) that measured the AC mains frequency against a GPS module, using the GPS module 1 PPS output pulse.

    I was able to chart the mains frequency and change in frequency over time, to quite a high precision.
     
  13. GopherT

    AAC Fanatic!

    Nov 23, 2012
    5,982
    3,718
    If i remember correctly. The Arduino Mega 2560 has an on board 5 volt regulator and TVS.
     
  14. kriscpm

    Thread Starter New Member

    Oct 5, 2013
    7
    0
    May i know if the GPS serves as a reference clock to catch the rising pulse? Why we cannot use the Arduino built in clock?

    And how does the GPS clock interact with the Arduino to obtain the frequency?
     
  15. kriscpm

    Thread Starter New Member

    Oct 5, 2013
    7
    0
    Because I am required to display the frequency in a chart form to see how it fluctuates over time. And how the frequency changes if a home appliance is on.
     
  16. kriscpm

    Thread Starter New Member

    Oct 5, 2013
    7
    0
    In order to capture each rising pulse, i need to convert the signal from sine wave to square wave first right? Is it right if i use a comparator to change it to square wave so that i can capture the rising edge? Plus, i would like to know if the comparator can provide an accurate conversion?

    Please correct me if i'm wrong.
     
  17. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    5,769
    1,103
    Not necessarily. A digital input of the micro (particularly a Schmitt input) will have an inherent logic 0 / logic 1 threshold voltage. The micro can be triggered to do something when that threshold is crossed.
     
  18. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    The method I used was like this;
    1. GPS 1 PPS pulse, measured against the PIC xtal speed using CCP1 capture module. This measured the PIC "10MHz" xtal speed to be 10000142 Hz or whatever, basically this is a "calibration" to know exactly what speed the PIC xtal was running at.

    2. The mains freq (actually the period of 50 AC cycles which should be 1 second) is captured using CCP2 capture module. Let's say the captured period of 50 AC cycles was 10001234 timer counts.

    3. Then the real period of the 50 AC cycles is found by;
    real mains period = (mains period / GPS period)
    real mains period = (10001234 / 10000142)
    real mains period = 1.0001091 seconds

    You can do a shortcut and just capture the AC mains period against the Arduino xtal, that will be less accurate as the measurement will only be as accurate as the xtal freq.

    The method I used eliminated any error in xtal frequency because the real xtal freq was known first, it was measured against the super-accurate GPS 1PPS pulse.
     
    Last edited: Oct 6, 2013
  19. kriscpm

    Thread Starter New Member

    Oct 5, 2013
    7
    0
    Thank you for your explanation. I will try that out :)

    In another way, if i convert the AC signal to a square wave, then i can use Arduino to capture the rising pulse in order to count the frequency. Is this way correct and accurate? I have run the simulation and the result is as attached. Please correct me if I'm wrong.
     
  20. RamaD

    Active Member

    Dec 4, 2009
    254
    33
    If you count the no. of pulses to measure the frequency, then NO. That is the frequency thus measured will be +/1, if counted for 1 sec. that too not taking into account the inaccuracy of the crystal clock (to get 1 sec) which is of the order of a few hundred ppm.

    If you measure the time interval, then it is OK. THE_RB has explained about improving the accuracy by calibrating it with GPS.

    BTW, the circuit gives pulses which are positive and negative, and microcontrollers dont like the negative ones! You need to limit it to the supply rails of the microcontroller!
     
Loading...