Mains Frequency Display

[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!

45 thoughts on “Mains Frequency Display

  1. 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.

      1. Beg to differ, frequency events are common. The grid response is generally within 0.1 HZ, but shifts in load can not be compensated for instantly. It takes time to increase or decrease generation.

    1. 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.

    2. 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).

      1. 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.

      2. 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.

    1. 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.

      1. I’ve heard that in Italy, modern fridges are designed to help with load/frequency problems. When the fridges detect that the mains frequency is lower than usual, and if their internal temperature allows, they will turn their compressors off.

      2. I have read that the electric companies compensate for the under-frequency and raise the frequency so that in any 24hr period there are the appropriate number of cycles. Can’t quote my source, but it was probably here where I read that so take it with a grain of salt :-)

    2. 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.

  2. 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…

    1. I did think about using a GPS-derived source, but I wanted to have the PCB small and simple, the project quick and cheap. I went with the DS3231 as I’d already used it, and I knew that the accuracy was good enough, at least for this.

    1. 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.

      1. 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? :-)

        1. 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.

      2. 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.

      1. I measure actual voltage from a step-down transformer, and current from a clamp – and do this as concurently as possibl (although actually one ADC sample apart)

        After doing multiple readings, I can calculate real power and apparent power, and from how much they differ, the PF

  3. 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.

  4. 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?

    1. 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.

      1. 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.

        1. 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.

  5. 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.

    1. >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

  6. 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.

  7. A easier method. I bought a autoranging multi-meter with a frequency function. It may be possible to wire straight into the mains but for safety I obtained a small plug pack delivering 6 volts AC and wired that in. Set the meter to frequency function and then turn on the power. Normal range seems to be (in New Zealand) 49.90 to 50.10 cycles a second but it is usually much less than that. Constantly changing all the time by a few hundredths of a cycle. The meter reads to 2 decimal places.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.