# Accurate powerline frequency meter.

#### fernando_g

##### Senior Member
My problem: measure powerline frequency accurate to 2 decimals. If the frequency is 59.99 Hz, I want to know that much, and not round it off to 60 Hz.

What I know: I will require an accurate and stable master timebase. No worries, mate. I have a +/- 1 ppm TCXO

Straightforward but not very practical solution: Measure for 100 secs to obtain the required resolution.

Alternate solution: Count the number of master clock cycles from a powerline leading edge to the next leading edge. For instance, if the master clock is 1 Mhz, there will be 16,666 cycles at 60.00 Hz, and only 16,669 at 59.99 Hz.
I know the Picaxe is too slow to count 1 Mhz. What I was planning to do, is to employ an external 16 bit counter 74LV8154, which will be gated, read and reset by a Picaxe 20X2 or 18 M2.

So, if you have the hardware figured out, what is the question?: How do I actually perform the cycle count to Hertz conversion. I was originally thinking of using a lookup table, but the number of entries is humongous!! Between 59 and 61 Hz there are 200 entries.

#### techElder

##### Well-known member
Tell me that you do know that the power line frequency is produced by a mechanical generator, and that the frequency is adjusted by the source to maintain an average frequency of 60 Hz. over some time period so that mechanical clocks will maintain the correct time.

PS. Not trying to be a smarta**. Just establishing baseline knowledge because you didn't state your purpose for this accurate frequency reading.

#### AllyCat

##### Senior Member
Hi,

My main concern would be the purity of (or lack of noise on) a single cycle of the powerline frequency. I think you probably need either to measure over more cycles and/or phase lock another oscillator to the powerline and measure a cycle of that.

I know the Picaxe is too slow to count 1 Mhz.
Not necessarily. Even a humble 08M2 has A "Timer 1 Gate" input and that has a default clock frequency of 1 MHz (so actually could be 8 times higher). The gate can even be driven by the on-chip comparator (not directly supported by the M2 OS) to level-detect the sine wave. But you probably would need to use an X2 for its external crystal resonator capability.

How do I actually perform the cycle count to Hertz conversion.
Divide (6000 * 16667) by the value from your counter, which is a simple 32 bit by 16 bit division.

The high word w2 = 6000 ** 16667 and the low word w1 = 6000 * 16667 , but these constants could be pre-calculated if desired.

Put the divisor into w3 and use this code snippett. Scroll down to #10 for the slightly improved version, or follow the link to a more complicated true 32 bit version. But even the simple 31 bit version would allow you to calculate (but not necessarily measure accurately) to 3 decimal places.

Cheers, Alan.

#### fernando_g

##### Senior Member
Tell me that you do know that the power line frequency is produced by a mechanical generator, and that the frequency is adjusted by the source to maintain an average frequency of 60 Hz. over some time period so that mechanical clocks will maintain the correct time.

PS. Not trying to be a smarta**. Just establishing baseline knowledge because you didn't state your purpose for this accurate frequency reading.
Yes, I do know about the average over a long period of time is or should be exactly 60 Hz, although there may be "spot" frequency changes.

The project is as follows:
I've been asked to perform a mains frequency audit on a large synthetic fiber factory.
I am NO EXPERT on synthetic fibers, but the following is what has been explained to me. Sorry if there are holes in the explanation.

Apparently in the process of extruding the fiber and thinning it to proper thickness there are hundreds of pulleys which progressively apply tension to it. These pulleys are driven by synchronous motors.

Long story short: There has been an increase in defects which has been attributed to improper motor speed, and thus powerline frequency.
The machine's manufacturer's proposed solution is a very expensive VFD drive. The company director wants to make sure that frequency variations are indeed the cause, before plunking down many dozens of kilo-dollars.

I've already done a frequency logger, and I do see frequency variations for instance, when peak loads occur in the early evening.
But I require better and faster resolution.

Last edited:

#### fernando_g

##### Senior Member
Alan;
indeed the purity of zero crossings is paramount. So yes I had planned to do a 16 cycle period average, plus some old-fashioned analog filtering.
Analog filtering is not usually recommended for power line meters as introduces a phase shift which could mess up -for instance- power factor measurements.
But in this instance it is not relevant.

Your code snippet looks tantalizing. I don't claim to fully understand it, but like everything else in this life, one has to take a plunge into the water and learn to swim....

#### srnet

##### Senior Member
I've been asked to perform a mains frequency audit on a large synthetic fiber factory.
And there are no pieces of 'professional' equipment that you can hire (and pass on the cost) that will do exactly this ?

Just because it may be possible to do what you want using a DIY method, how would you intend to do it in such a way that the 'audit' is accurate and can be back referanced to known and calibrated standards ?

#### Pongo

##### Senior Member
What he said. There are professional instruments for exactly this purpose, rent one.

#### fernando_g

##### Senior Member
And there are no pieces of 'professional' equipment that you can hire (and pass on the cost) that will do exactly this ?
Of course there are. Dranetz, Hioki, Fluke...I've used them over since the late 70s. I used a Dranetz for the original audit.

Alongside the Dranetz, I installed my piece of equipment. For the single purpose that I made it, it correlated with the Dranetz.
I'm no attempting to measure voltage, current, impulse voltage, lead/lag power factor, display individual harmonics plus THD, active power, reactive power, apparent power, crest factor, demand factor, active or reactive energy, phase unbalance or neutral current.
Nor I'm required to meet a CAT IV safety rating. I'm connecting my device on a 120V office wall plug.

So I'm planning to do a simple, single purpose piece of equipment, and -why not- make a little money in the process. Not very much, just a little.

#### stan74

##### Senior Member
When the mains frequency changed it would affect all the synchronous motors the same being er..synchronous. I thought that was the point. You could mix a crystal 60Hz with the mains (at low voltage)and measure the difference 60-59.99=0.001Hz that a picaxe could measure. If you connect a speaker between the left and right positive speaker terminals of a stereo amp you will hear the difference signal.

Last edited:

#### fernando_g

##### Senior Member
When the mains frequency changed it would affect all the synchronous motors the same being er..synchronous. I thought that was the point. You could mix a crystal 60Hz with the mains (at low voltage)and measure the difference 60-59.99=0.001Hz that a picaxe could measure.
Heterodyning! great idea.

#### stan74

##### Senior Member
Yes,like a BFO. I don't think the problem is to do with the mains frequency,it's probably mechanical. If it was spot on 60Hz or 59Hz,it would affect all the motor equally.

#### premelec

##### Senior Member
Just a guess - it seems likely that mechanical problems in the motors / pulleys more likely than power line freq variations - on the other hand how much power is involved.... you might use a local inverter to drive the motors... doesn't seem likely that VFDs would solve the troubles unless servoed to actual fiber measurement [more complications...]

#### AllyCat

##### Senior Member
Hi,

measure the difference 60-59.99=0.001Hz that a picaxe could measure.
Isn't 0.001 Hz = one cycle in 16 minutes (or 100 seconds for 0.01 Hz) ? I thought a more "instant" readout was required? Also how to discriminate between + or - difference, and what happens at exactly 60 Hz?

As others have said, I rather doubt if it is "purely" a frequency issue (i.e. related to the time between zero-crossings), perhaps more that the sinewave isn't pure. So IMHO a "quick and dirty" (PICaxe) measurement of the frequency would be in order to see if there is any correlation with the defects.

BTW is this a single-phase or 3-phase powerline system?

Chers, Alan.

#### Janne

##### Senior Member
First idea that came to my mind would be to use a PLL to multiply the mains frequnecy to something faster, that could then be digitally sampled to get the desired resolution.

#### fernando_g

##### Senior Member
This is an industrial 3 phase system.

I did a very simple experiment: I purchased an inexpensive digital clock, the ones that derive its time from the power frequency.
I set its time precisely synchronized with my phone. Checked it today, and after 3 days it's already 2 minutes ahead!

#### hippy

##### Technical Support
Staff member
I did a very simple experiment: I purchased an inexpensive digital clock, the ones that derive its time from the power frequency.
I set its time precisely synchronized with my phone. Checked it today, and after 3 days it's already 2 minutes ahead!
Not sure where in the world you are, or how you are getting your mains feed, but most national grids will go to some lengths to avoid that happening, speeding up and slowing down the frequency to give clocks which count mains cycles quite accurate timing over the course of days.

#### fernando_g

##### Senior Member
I know, I know. That is why this issue is really puzzling! I really want to research this one now!

So hippy, as the resident expert what would be, of the many suggestions so far, Which one holds most merit, Picaxe-wise?
I kind of like the internal "count" feature. Of course, I would use an external, accurate crystal, preferably a TCXO. This also means that I should employ at least a 28X2.
Also......Using a PLL based multiplier front end to speed it up and shorten the acquisition time for a given resolution.

#### stan74

##### Senior Member
Do they still make them like that? In the uk they run off a watch crystal. They don't use the mains frequency.

#### fernando_g

##### Senior Member
There will always be some cheap, cheap alarm clocks which use the power frequency as their timebase.

#### Pongo

##### Senior Member
This is an industrial 3 phase system.

I did a very simple experiment: I purchased an inexpensive digital clock, the ones that derive its time from the power frequency.
I set its time precisely synchronized with my phone. Checked it today, and after 3 days it's already 2 minutes ahead!
That's amazing! Where are you that has AC power that poorly controlled?

#### eggdweather

##### Senior Member
Observations: I understand suppliers have to maintain their average frequency to +/-0.5Hz of nominal, so making a measurement should be feasible to the required resolution and cycle to cycle differences minimal = low jitter. Grids can be considered to be infinite in their operation, meaning grid impedance tends to zero and voltage and frequency remain constant and localised perturbations (transmission line characteristics aside) are driven by the grid not local generators. You should not see any wild changes in frequency as a result, unless it's an autonomous supply, in which case anything's possible and 2-mins of gain or 120/259200 over 3-days or 462ppm does not sound that bad!

#### rossko57

##### Senior Member
Going back to post #10, "the problem" was shown to a professional line monitor. Presumably that showed the slow main freq or missing cycles or whatever the underlying symptom is??
I can understand the concern that buying expensive "clean motor drive" isn't going to actually fix the production issue, but I can't follow how demonstrating the (possibly unconnected) symptom with cheap equipment will help any decision making.

#### fernando_g

##### Senior Member
That's amazing! Where are you that has AC power that poorly controlled?
South Texas
But as I have mentioned, I have never seen it before. Ever.
This is puzzling indeed, and I am not ruling out that there is a straightforward explanation or that a measurement mistake has been made. A cheap clock is not a precise instrument, but on the other hand, what could be wrong?

My curiosity is really piqued. I really would like to research it. To satisfy my own curiosity. If nothing else.

Unfortunately I am leaving for vacation returning first week of January.

#### Pongo

##### Senior Member
Hmmm, Texas, I wasn't expecting that. In the U.S. the cumulative error is supposed to be corrected within each 24 hour period. The allowable error during the period before the correction must be applied depends on the grid, east, west, or Texas.

#### fernando_g

##### Senior Member
There is currently a project to build a super station at Clovis, NM which will tie all three interconnections.
But like most modern interconnections, it will employ HVDC.

#### inglewoodpete

##### Senior Member
Maybe running on an inverter like Presidio TX ? ;-0 http://www.ettexas.com/projects/docs/NaS_Battery_Overview.pdf
I hope they know what they are doing. A "sodium-sulfur 4-megawatt NAS® battery system". Isn't battery storage measured in (mega/kilo)watt/hours? Certainly interesting technology, though. The document is dated 2010. Did battery storage on such a scale get to 'fly'?

#### techElder

##### Well-known member
Hey! Wasn't that a movie? Tres Amigos?

#### Pongo

##### Senior Member
There is currently a project to build a super station at Clovis, NM which will tie all three interconnections.
But like most modern interconnections, it will employ HVDC.

Thanks I wasn't aware of that, very ambitious but I see it may be in trouble

#### hippy

##### Technical Support
Staff member
cheap clock is not a precise instrument, but on the other hand, what could be wrong?
Brownout ?

If there's a drop in the mains that might turn one cycle into two parts, which could explain the clock running fast; getting more pulses than cycles.

That might also explain the speed variance which is the underlying issue.

Will come back to you on how best to measure mains frequencies with a PICAXE as I have been thinking about that.

#### geezer88

##### Senior Member
Are you sure your cell phone clock is correct? Standing in front of a business, waiting for it to open, half a dozen folks pulled out their phones and compared times. There was at least a three minute variation, depending on who knows what. Some had the same carrier and still had minute or two differences.

tom

#### AllyCat

##### Senior Member
Hi,

You could always use the PICaxe Forum clock.

But to stay OnTopic, I think you should measure (or Phase-Lock, or whatever) with an interval or time constant at least as long as the rotational intertia of the motors that are being used.

Cheers, Alan.

#### stan74

##### Senior Member
Will come back to you on how best to measure mains frequencies with a PICAXE as I have been thinking about that.
How's the clock do it and why didn't someone take mains freq for granted? Wouldn't a scope show it somehow if there's a stable 60Hz time base? 2 frequencies,one would move. I'll try and get back.
Soz,gens duff..old,dried caps

Last edited:

#### tmfkam

##### Senior Member
There is a project on the Elektor forum that does just this, using a PicAxe. As it uses only the internal resonator of the PicAxe, the accuracy is limited to the accuracy and stability of the resonator as the author highlights in the circuit description. The claim is that it has the capacity to self adjust for either 50Hz or 60Hz nominal frequencies. If you ported the code to a PicAxe with a crystal oscillator more accurate results could be obtained perhaps?

Datalogging might be relatively simple to add?

Link to the project on the Elektor forum: Electricity-grid-frequency-meter