Mains Frequency Display

mains frequency

[James] lives in the UK where the frequency of electricity is suppose to be 50Hz, but it tends to fluctuate based on supply and demand. He decided he wanted a display to track this.

Now, the National Grid Website shows a real-time graph of the last 60 minutes. But that’s way too easy. Time to bust out the soldering iron!

Armed with pencil and paper [James] scribbled down some ideas on how to count the frequency — he settled on counting 200 cycles, which means that at 50.000Hz, it would take exactly 4 seconds. The next problem was getting a timing source that was accurate enough for the job. An ATtiny84 wouldn’t do the trick (too inaccurate), nor would an external crystal (too expensive) — But a real-time clock? That’s the ticket! He’s using a DS3231 RTC chip, which at +/- 2ppm 32.768kHz is more than precise enough.

Some math, programming, and soldering later and the display is complete! He’s even added an up/down arrow to show the most recent trend of the electricity.

Nice one [James]! Last year [Ch00f] did a similar project, where he tore down a 194 discrete transistor clock kit to see how it worked — as an aside, he needed to know how accurate the 60Hz coming out of his wall was!


  1. John says:

    The national grid also shows real time.
    Interesting to note that real time on that web meter is different from my real time frequency at home (North England). I suppose that meter is down South somewhere and I am in the North but the difference sometimes does make you wonder where the power is going, there must be some seriously glowing cables somewhere for it to happen. I have emailed the guy that wrote it but he has failed to tell me where in the country the sensor is. I monitor the frequency realtime using a PIC to make a serial datastream over radio to a Raspi. It has been running for about 6 months and the state of the supply is generally disturbing with serious harmonics such that my supply is sometimes more like a square wave than a sine wave and the supply voltage is all over the place. You can see my PICs running here. if they are connected.

    • Peter says:

      A high load somewhere will change the amplitude and phase of what you see at your utility plug but not the frequency. Will not happen.

    • t-bone says:

      the state of the supply is generally disturbing with serious harmonics such that my supply is sometimes more like a square wave than a sine wave and the supply voltage is all over the place.

      This is probably a problem with your nation’s entire energy infrastructure. You should tell them.

    • Infidellic says:

      You don’t make it clear if your “Voltage” is RMS or peak. Presumably the latter otherwise there are other problems to worry about given that it should be 230VAC (albeit with the large allowable margin for error).

      • John says:

        The problem is one of a big third harmonic at the moment. It is RMS but defining an accurate value is difficult because though I do have the equipment to measure the harmonics I have not set it up, there is no point really as it varies all the time. A normal multimeter will only give the RMS (or average if it’s a cheap one) value of a sine wave so a reading taken on a non sine wave is meaningless, therefore I have no reference. I can report the value of the fundamental or I can report an RMS value that is based on the area, either way up it is not correct and hard to define what is correct. You should only pay for the 50Hz component that you use but actually you pay for all of it. It’s a proper can of worms to try to define absolutes on.

      • John says:

        Just to add, I do have problems with my supply, I use more bulbs than Blackpool in the Autumn. Measured on an RMS meter it is never below 245 and often up to 270 ish. I choose not to do anything about it because most devices now use clever power supplies and I pay for electricity by current, not by power. I am slowly replacing all my incandescents, once that is done they can stick the voltage as high as they like and I will gladly use it.

  2. BiOzZ says:

    I never fully understood why they would flux based on load … more load slowing down the generator?

    • Garbz says:

      That’s exactly what happens. If there’s a sudden spike in demand it creates back EMF that puts an incredible load on the generator. Small gas turbines are good at quickly recovering but large thermal plants like coal are absolutely horrendous at coping with changes in load.

      This has become worse since the rise of green power as sudden changes in wind speed and cloud cover will not change the load, but the available grid supply. In my country a lot of large plants are being augmented with small gas turbines to smooth the load.

      Also of interest is where I work when the main grid went out our small 20MW generators started back-feeding a few suburbs and the local airport. The islanding systems didn’t work and after a couple of seconds and a LOT of noise and mechanical stress the machines tripped on … under-frequency.

    • Zac says:

      When there is more resistance in the external circuit (i.e. less load on the power lines), the resistance of the windings in the generator becomes less significant and the generator speeds up without any outside influence. The opposite happens when there is higher load on the generator, its internal resistance becomes more significant. Somewhere in there there’s some sort of electromagnetic principles which are responsible for this.

      Much in the same way that having your foot on the gas pedal of a car at a constant angle, going up a hill the car will slow down and going down it will speed up.

  3. Mike Field says:

    I’m surprised that nobody yet has mentioned that most GPS modules have a pulse-per-second (PPS) output that is pretty darn accurate in period, with only a microsecond or so in relative phase difference between different models.

    With a mains frequency cycle being about 20,000 microseconds any GPS PPS output will make an excellent timebase for measuring mains frequency.

    I was using one recently to determine the temperature coefficient of some 50MHz crystals…

  4. ftkalcevic says:

    I’m too lazy to look this up, but a crystal is more expensive than a DS3231 RTC chip?

    • fowkc says:

      They’re about the same price, maybe a little more for the RTC.
      But another consideration was getting the right frequency range. Most TXCO crystals seem to be in the MHz range. To avoid swamping the microcontroller with interrupts, I’d have to run the crystal output through a divider anyway.
      I also only needed to buy one of these things. I didn’t want to buy a reel or tube of 10 crystals I’d never use. That limits my options on what I can get.
      The DS3231 was the sensible choice given those limits.

      • Now I’m confused… Why would you use the external crystal as an interrupt source? To me it makes more sense to run the mcu with a high frequency TXCO and have the 50Hz mains as the interrupt source, then use a timer to count down and read it at the interrupt.

        But your method works as well so why not? :-)

        • fowkc says:

          Good point! I have no idea why I didn’t do that.

          Either it didn’t occur to me, or I rejected it for a reason I can’t remember.

          Honestly, the main reason I used the DS3231 because I’d just finished off another project using one, so it was fresh in my brain.

          Lazy engineer is lazy.

      • tekkieneet says:

        The easy way to measure frequency down to sub-Hz quick is to measure the
        AC period with timer capture (e.g. on falling edge of zero crossing).
        Since AC is only 50 (/60) cycles, there isn’t going to be much of an
        interrupt load. Run the CPU & timers from a high frequency TCXO (with
        known measured frequency). Use math to calculate frequency from period
        apply calibrated value to get real frequency.

  5. juno says:

    Real time website for Continental Europe

    Yep, a synchronous grid.

  6. Ben says:

    I’ve been monitoring frequency as part of my home energy measuring project for a while now – though I sometimes wonder how much is tolererences in my measurements, and how much is real frequency variation!

  7. mattbed says:

    Going back to the 60hz supply for the clock,
    Here in the UK, the engineers that ballance the supply and demand on the network use two clocks as another way of checking the frequency (a legacy system now but still in use)
    The first clock runs off the mains at 50hz and the second runs off a battery and the time difference between the two is used to assess if we are over or under generating.

  8. hardwerker says:

    I’m a bit puzzled about the 3 digits after the comma.
    You are counting ~200 cycles and I guess you are only counting full cycles, not fractions?
    Then 1 cycle in 4 seconds means 0.250 cycles in 1s.
    How can the display show 49.866?

  9. truthspew says:

    I’ve probed the frequency here in RI and it varies by a few parts per million. But knowing it’s National Grid there too – i like to call them Third World Power.

    • mattbed says:

      The US has a significant advantage over us in the UK but the fact it is a massive country with one big grid so load changes are relatively much smaller compared to the generation so frequency fluctuations are much smaller.

      • Tyler says:

        Three and a half big grids, but yes. We have so much more rotating mass (inertia) in generatio, and…generally tighter control, the US would almost never see anything like 60.2 or 59.8, and that would be the sign of a serious network disturbance.

        The thing that varying frequency also does is change the speed, current draw, and power output of induction motors — something that can create oscillations or further destabilize the grid.

        University of Tennesee runs FNET, a similar frequency display for the US.

      • tekkieneet says:

        Found this “U.S. Frequency Gradient Map” by FNET.

        • matt says:

          Why is the north Texas/Olklahoma area so turbulent compared to the rest of the grid?

        • Richard says:

          You beat me to it. I had found that site when a similar subject came up on another board. I set up my oscilloscope to monitor my own mains frequency, and I could watch the changes in near-real-time. The scope would show a slowdown, and then my area of the country would turn blue on the next refresh of the map. For some reason, that was mesmerizing to watch, at least for several minutes. Like a lava lamp.

          I’ve got one of those cheap popular Rigol DS1052E scopes, and it’s easy to watch the AC frequency with one. You don’t even need to connect a probe or display a trace. Just set it to trigger on the AC line, and turn on the trigger frequency counter.

      • truthspew says:

        Actually the power system in the U.S. dates back to over a hundred years ago. It’s essentially held together with paper clips and tape.

  10. Cool project. However I do not understand why the article states that an external crystal would be to expensive compared to a DS3231. Actually I implemented such a monitor with an Arduino (hence an external crystal) with good results. and Of course the DS3231 will give more precision but I found that I do not really need it.

    • jacques says:

      >an external crystal (too expensive), … uses an RTC with crystal ???
      anyway the precision is the precision of the crystal, i.e. 20ppm at best, not that of the rtc or the cpu or whatever.
      The rest is calibration and temperature regulation

  11. Sean says:

    I did this once in Quebec, I wanted to see if power supply fluctuations corresponded with space weather (as an elaborate joke for Mayan solar doomsday 2012). We have a lot of long spans of transmission wire running North-South, this took down our power system once during a solar flare. Anyway, they must have fixed the problem, because it was solid as heck. At least I can say I’ve actually attempted to build a doomsday (predicting) device.

    I used a free running 16-bit timer on an ATMega16, ASM, and a 20Mhz crystal. On a rising edge, I would simply wait almost the full time until the falling edge… then start the timer. This way I could get really good time resolution without missing data, with known sampling error (if you count clock cycles). The MCU was simply connected to the power supply via a resistor and optoisolator, and emitted serial output for long term datalogging. It worked really well.

    Eventually this was connected to an antique lamp+RGB LED as a very rough display of how much power the grid was using… Because if you can’t get your doomsday device to work, put some LEDs on it and go for an art grant.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s