How to measure AC line frequency from mains

Main Question or Discussion Point

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.

Why do you need such a precise measurement?
A transformer can give you low voltage with the same frequency, add something to digitize the voltage and compare its frequency with clock cycles of your microcontroller.

You seem to be having difficulty with getting pulses from the 6V AC. Look up zero crossing detector on google.

Once you have pulses you can do any of several things, depending on the accuracy you need. You can count pulses for a fixed period and do division, or you can use the TC9400 and an A/D converter as explained in AN795.

The simplest is to count pulses, and just make the period as long as you need for the accuracy you want. But, sometimes you want faster results and there are tricky ways to do that. But, more accuracy always requires more time for any given method.

If you decide to use the TC9400 I think you just need a voltage divider (check the data sheet)

Depending on your country, you may be able to get the mains frequency measurements in real time, more accurately than you can easily measure them yourself. Note that the frequency is adjusted so its long term average is "exactly" 50 or 60 Hz depending on your country, and at any time the cumulative deviation from the average is unlikely to be more than a few seconds either 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.

The 741 is not really a good choice to use as a comparator since the voltage out goes from -V to +V. You will find that digital circuits downstream do not want to see voltages lower than ground. (typically Vss - 0.3).

Use a comparator which, with a pullup usually, will give a voltage between 0 and +V (or whatever is on the pullup).

Accuracy will depend on how long you count. Count for any abitrary 1 second and you get 60 +- 1. Count for 1 minute and you get 3600 +- 1.

The 741 is not really a good choice to use as a comparator since the voltage out goes from -V to +V. You will find that digital circuits downstream do not want to see voltages lower than ground. (typically Vss - 0.3).

Add a resistor and a diode...

Accuracy will depend on how long you count. Count for any abitrary 1 second and you get 60 +- 1. Count for 1 minute and you get 3600 +- 1.

If you measure the time of the edges, you can get a better resolution.

The arduino runs at 16MHz and has an input capture register that can record a timestamp for an external event and notify you to go read it. You can measure for as long as you want and then average, or produce a running average, or whatever.

Timer Input Capture:
When a timer input capture interrupt occurs, the input capture flag bit ICFx will be set in the interrupt flag register TIFRx. When the input capture interrupt enable bit ICIEx in the interrupt mask register TIMSKx is set, the timer input capture interrupt service routine ISR(TIMERx_CAPT_vect) will be called.