Computing stuff tied to the physical world

Measuring the AC line frequency

In AVR, Hardware on May 28, 2009 at 00:01

There is an interesting site in the UK called Dynamic Demand. The idea is to let the 50 Hz power-line frequency vary slightly to indicate the current load of the entire grid. Simple line-monitors can then track this locally and respond by voluntarily shutting down some power consumers (i.e. turning off freezers, A/C units, or electric heaters for a little while). With a bit of collaboration, the grid would then presumably recover as the load eases off – and overcome these demand peaks. I love the idea, it’s so beautifully simple.

The Dynamic Demand site also has a page showing the current frequency online, here’s a snapshot:

Picture 2.png

I don’t think this mechanism is being used – or even considered? – in the Netherlands but I couldn’t resist setting up a JeeNode to monitor the frequency myself. The sketch:

Picture 3.png

What it does is measure elapsed microseconds between 100 transitions of its input signal against the 1.1V bandgap reference voltage. That’s 50 ups and 50 downs, which should take 1 second.

The AIO pin of port 1 is connected to a rectified but unregulated AC voltage, coming from a 17 VAC power brick through a diode plus 1:10 voltage divider. The signal looks as follows:


And here’s some sample output:

Picture 1.png

Note that for stable and repeatable results, the JeeNode will need to be fitted with a crystal as clock.

The accumulation over 100 transitions is a simple way to average all the pulse durations. Most of the code then tries to present a nice result, with sufficient accuracy to display minor variations.

Nice and tidy.

  1. I seem to remember that there are electric clocks which derive their time normal from the power line frequency. Such clocks would start to run faster or slower when connected to a net modulating the power-frequency to transmit information.

  2. Off-topic question: I see you’re using DSO-2090 USB oscilloscope.

    What’s your experience with it? Is it any good? I am looking to get some DSO for myself, however there seem to be not so many USB DSOs available on the market with Mac OS X support. Any advice, thanks?

  3. Atmel has an application note that shows a zero cross detector where the AVR connects to the mains line over two 1M resistors without a transformer or opto coupler: . This of course requires sufficient electrical insulation of the device for safety reasons.

Comments are closed.