Measuing AC line frequency

Thread Starter

kriscpm

Joined Oct 5, 2013
7
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!
 

crutschow

Joined Mar 14, 2008
30,098
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.
 

Alec_t

Joined Sep 17, 2013
12,889
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.
 

t06afre

Joined May 11, 2009
5,934
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.
Is not the Arduino equipped with a voltage regulator?
 

Alec_t

Joined Sep 17, 2013
12,889
Even if the power supply of the Arduino has a regulator the analogue input pins can be over-driven if care is not taken.
 

ErnieM

Joined Apr 24, 2011
8,311
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.
 

wayneh

Joined Sep 9, 2010
17,167
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.
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.
 

t06afre

Joined May 11, 2009
5,934
Even if the power supply of the Arduino has a regulator the analogue input pins can be over-driven if care is not taken.
Indeed...I really hate those schematics that have black background, and green, and blue as wiring colors. Hopless to read.
 

GopherT

Joined Nov 23, 2012
8,012
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.
If i remember correctly. The Arduino Mega 2560 has an on board 5 volt regulator and TVS.
 

Thread Starter

kriscpm

Joined Oct 5, 2013
7
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.
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?
 

Thread Starter

kriscpm

Joined Oct 5, 2013
7
Is this a power meter? If so, why do you need to know the mains frequency?
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.
 

Thread Starter

kriscpm

Joined Oct 5, 2013
7
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.
 

Alec_t

Joined Sep 17, 2013
12,889
i need to convert the signal from sine wave to square wave first right?
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.
 

THE_RB

Joined Feb 11, 2008
5,438
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?
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:

Thread Starter

kriscpm

Joined Oct 5, 2013
7
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.
 

Attachments

RamaD

Joined Dec 4, 2009
328
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!
 
Top