MainsFrequency: Difference between revisions
m (→Status) |
No edit summary |
||
Line 30: | Line 30: | ||
== Hardware == | == Hardware == | ||
[[File:ali_230v_schema.png|thumb|right|reverse engineered schematic of mains sensing module]] | |||
The microcontroller is an ESP8266 because it can easily publish the measured value over wifi/MQTT. | The microcontroller is an ESP8266 because it can easily publish the measured value over wifi/MQTT. | ||
Line 35: | Line 36: | ||
The modification is that the smoothing capacitor has been removed, resulting in a 100 Hz signal going into the optocoupler (a pulse during each zero crossing). | The modification is that the smoothing capacitor has been removed, resulting in a 100 Hz signal going into the optocoupler (a pulse during each zero crossing). | ||
How | How things are wired: | ||
* Used the modified Aliexpress circuit. | * Used the modified Aliexpress circuit. | ||
* Used a nodemcu v3 for the ESP8266 (this was what was available at the hacker space) | * Used a nodemcu v3 for the ESP8266 (this was what was available at the hacker space) | ||
* pin | * Mains power going into the mains detection module (left part of the schematic) | ||
* pin D5: connected to the optocoupler output on the mains module | * ESP8266 pin 3.3V: connected to the pull-up on the mains module output (top in schematic) | ||
* pin | * ESP8266 pin D5: connected to the optocoupler output on the mains module output (middle in schematic) | ||
* ESP8266 pin GND: connected to the GND pin on the mains module output (bottom in schematic) | |||
* put in a plastic enclosure with warning labels | * put in a plastic enclosure with warning labels | ||
Line 47: | Line 49: | ||
The working principle is that we count the number of interrupts in a 100 second period, this should nominally be 10000. | The working principle is that we count the number of interrupts in a 100 second period, this should nominally be 10000. | ||
An interrupt count is done every second and the result is put in a circular buffer of 100 bins. | |||
The average of these 100 bins then provides the frequency over the past 100 seconds. | The average of these 100 bins then provides the frequency over the past 100 seconds. | ||
The circular buffer is initialized with a value of 100 for each bin. | The circular buffer is initialized with a value of 100 for each bin. | ||
Line 53: | Line 55: | ||
The accuracy of the frequency count depends on the accuracy of the crystal (among other things). | The accuracy of the frequency count depends on the accuracy of the crystal (among other things). | ||
To get 0.01 Hz error at 50 Hz, we need a time reference with at most 0.01 / 50 = 200 ppm frequency deviation. | To get 0.01 Hz error at 50 Hz, we need a time reference with at most 0.01 / 50 = 200 ppm frequency deviation. | ||
This is doable with the built-in crystal on a typical ESP8266 board. | This is doable with the built-in crystal on a typical ESP8266 board (which is 25 ppm or so). | ||
You can build the software with platformio ('pio run'), it uses libraries WifiManager and PubSubClient. | You can build the software with platformio ('pio run'), it uses libraries WifiManager and PubSubClient. |
Revision as of 11:17, 22 May 2018
Project MainsFrequency | |
---|---|
A simple mains frequency counter | |
Status | Completed |
Contact | bertrik, Peetz0r |
Last Update | 2018-05-22 |
Introduction
This page is about a simple frequency counter for mains power publishing the frequency over MQTT.
It's based on the Arduino platform, using an ESP8266 to do the wifi/network/MQTT stuff.
The frequency measurement principle is to count the number of mains cycles in a fixed period. To get a resolution of 0.01 Hz, the period is 100 seconds.
To keep the measurement circuit relatively safe, only a part of the electronics is actually connected to mains and the low-voltage side is isolated with an optocoupler.
Status
It works!
See Graph of the AC main frequency as measured at RevSpace
Compare it with:
- Swiss grid frequency graph
- mains frequency. NOTE: don't leave this site open for too long, it'll ban your IP for 'traffic exceeded' reasons!
Hardware
The microcontroller is an ESP8266 because it can easily publish the measured value over wifi/MQTT.
The circuit to sense the 50 Hz is this mains module sold on Aliexpress, with a small modification. The modification is that the smoothing capacitor has been removed, resulting in a 100 Hz signal going into the optocoupler (a pulse during each zero crossing).
How things are wired:
- Used the modified Aliexpress circuit.
- Used a nodemcu v3 for the ESP8266 (this was what was available at the hacker space)
- Mains power going into the mains detection module (left part of the schematic)
- ESP8266 pin 3.3V: connected to the pull-up on the mains module output (top in schematic)
- ESP8266 pin D5: connected to the optocoupler output on the mains module output (middle in schematic)
- ESP8266 pin GND: connected to the GND pin on the mains module output (bottom in schematic)
- put in a plastic enclosure with warning labels
Software
The Arduino source is available on the github page.
The working principle is that we count the number of interrupts in a 100 second period, this should nominally be 10000. An interrupt count is done every second and the result is put in a circular buffer of 100 bins. The average of these 100 bins then provides the frequency over the past 100 seconds. The circular buffer is initialized with a value of 100 for each bin.
The accuracy of the frequency count depends on the accuracy of the crystal (among other things). To get 0.01 Hz error at 50 Hz, we need a time reference with at most 0.01 / 50 = 200 ppm frequency deviation. This is doable with the built-in crystal on a typical ESP8266 board (which is 25 ppm or so).
You can build the software with platformio ('pio run'), it uses libraries WifiManager and PubSubClient.
References
Other interesting projects/documents:
- http://www.palebluedot.nl/jml/projects/arduino/43-measure-mains-power-frequency
- https://engmousaalkaabi.blogspot.nl/2016/11/ac-220v-frequency-counter-using-arduino.html
- Interesting App Note by Microchip about capacitive droppers
- https://a01.veron.nl/download/hamnieuws/2016/Ham-06-2016.pdf (see page 20, 220nf, 2M Ohm bleeder)