![]() |
Forum Index : Microcontroller and PC projects : Mains frequency monitoring
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
HankR Senior Member ![]() Joined: 02/01/2015 Location: United StatesPosts: 209 |
Using a $2 Arduino clone (driven by a crystal) and using a period measurement with the built-in microsecond resolution, this is a trivial task to measure 50 or 60 Hz to .01 Hz accuracy in one 50 or 60Hz cycle interval. |
||||
Herry![]() Senior Member ![]() Joined: 31/05/2014 Location: AustraliaPosts: 261 |
There is no need to have mains voltage anywhere near the circuit. I will feed mine via a plugpack. I would also count the period (CIN) rather than the frequency. However, I did not realise that there is no provision for using a crystal on the Mite; I have 'grown up' feeling that it can be made to do just about anything! I don't want to use the bigger brother as the price is so much higher. And I don't want to use another device like a PIC if I can avoid it. Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
Herry![]() Senior Member ![]() Joined: 31/05/2014 Location: AustraliaPosts: 261 |
I may have to be dragged away kicking and screaming from my Mite, so can you go into more detail of how you would do this? Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
BobD![]() Guru ![]() Joined: 07/12/2011 Location: AustraliaPosts: 935 |
[quote=Herry] However, I did not realise that there is no provision for using a crystal on the Mite; I have 'grown up' feeling that it can be made to do just about anything! I don't want to use the bigger brother as the price is so much higher. And I don't want to use another device like a PIC if I can avoid it. [/quote] My original suggestion of using the DS3231 as a source of accurate timing, if you have one on the system, is because this RTC includes an on chip, temperature compensated crystal and also includes the capability of trimming the speed if not accurate enough. |
||||
HankR Senior Member ![]() Joined: 02/01/2015 Location: United StatesPosts: 209 |
Here is just one webpage that shows how to do it including a nice little display: http://circuitdigest.com/microcontroller-projects/arduino-frequency-counter-circuit The ingredients missing in the MM provided by the Arduino are a MPU crystal clock (normally 16 MHz; can be 8 Mhz) and a 1 MHz tick. The 1 MHz tick, at 1000x faster than that of the MM, is just about good enough for a 1 part in 5000 measurement, since a half cycle of 50 Hz gives an interval count of 10,000. For that reason, the period method used in this code really starts to run out of resolution sufficient to give accurate measurements to .01 Hz as early as a few hundred Hz. Better, more elaborate code will automatically switch to a gated count method for all but the lowest frequencies. This was just the first webpage that came up from Google. I believe gated pulse counting will require the use of an interrupt on the Arduino, so this is probably the simplest Arduino code possible for frequency measurement. Fortunately, it's good enough for your 50 Hz requirement. In this particular implementation, both halves of the signal cycle are measured and summed because the simple test signal generator is a 555 which has an asymmetric output waveform. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6284 |
It is a long time since I was in charge of a power station but the basics wouldn't have changed too much. Tasmania has a number of power stations and at any given time one station would have 'frequency control' All other station would be on a fixed load and the control station would change its output to match the load on the system. If the system load increased, the frequency would drop slightly and the control station would increase output to bring the frequency back to 50Hz. In the mornings as load increased, you would be consistently having to bring frequency back up and that would result in the average frequency over an hour being a bit low. The system time would end up a couple of seconds behind UTC so you would have to run the system at 50.1Hz to gradually bring the system time back to UTC. The control room had 3 clocks. System time, UTC and an error clock that showed how bad your efforts had been. Usually, we would deliberately set the system time a couple of seconds fast just before the expected load increase so the lagging time would correct itself. The same thing happened in reverse as load peaks dropped off. To measure mains frequency with a umite, I would have two period measurements. One measuring the mains and one measuring the one Hz output of a DS3231 (or similar accurate device) You could then correct the mains measurement to compensate for the umite errors. You would only have to read the reference occasionally as the umite doesn't fluctuate too fast. You might then find that the zero crossing detector has to be fairly precise to get a good precision. I did build a disturbance recorder that continually recorded the mains waveform and when there was a fault (sudden change in voltage), it would show the last second before the disturbance and a second or two after the disturbance. It used two mites, one to continually record the waveform and one to decide when there had been a disturbance. I didn't bother with frequency measurement. I must go back and finish it one day... Jim VK7JH MMedit |
||||
HankR Senior Member ![]() Joined: 02/01/2015 Location: United StatesPosts: 209 |
Yes, this is a nice, simple way to do it, but again the limitations of the MM limit the accuracy obtained to more like .1 Hz, rather than .01 Hz. That's because the total count for the 1 sec external reference will only be 1000, thus resolution-limiting accuracy to 1 in 1000, not even accounting for the +- 1 count systematic uncertainty. Counting the 10 Mhz output is not possible either. For Herry .1 Hz may be good enough. For the US grid it looks like the short term error is most often under +- .01, so .1 Hz would often show no deviation. |
||||
HankR Senior Member ![]() Joined: 02/01/2015 Location: United StatesPosts: 209 |
Jim, Thanks for your power-plant insider operational insights. Hank |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6284 |
True. The uM accuracy is a limiting factor. If you sample the frequency over a number of cycles (~50 or 60) the precision is increased by that factor. The reference one Hz could be measured over 10 or 100 cycles or a calibration chart for CLOCKTRIM Vs temperature used and forget about regular references. I did a chart of clock vs temperature a while ago. Still not as accurate as an arduino or xal controlled mite+. Jim VK7JH MMedit |
||||
Herry![]() Senior Member ![]() Joined: 31/05/2014 Location: AustraliaPosts: 261 |
It's the sort of thing I had in mind. Readers may find that paper by Ibrahim interesting. Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
bigmik![]() Guru ![]() Joined: 20/06/2011 Location: AustraliaPosts: 2950 |
Lads, I was always brought up being told that the AUSTRALIAN Mains frequency was kept to be `exact' over a 24hr period... i.e. If it dropped for an hour they would speed up for an hour. SO I googled it and I find that recently the restrictions were relaxed on the mains frequency range from 49.9-50.1 Hz to a slightly wider 49.85-50.15 Hz range.. Also reading further it `seems' to state that they will not catch up any lost speed, however this is in not very clear wording.. If anyone wishes to look it up they can find the document HERE!!! Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
Not quite right. You can specify the number of cycles to measure the period over and the result will be returned as a floating point number with a fractional part. Eg, if you measure over 10 cycles the result will have a resolution of 0.1mS and the Micromite can be doing something else while this is going on. You should consider getting one. It is fun to play with and does not cost much. Geoff Geoff Graham - http://geoffg.net |
||||
Herry![]() Senior Member ![]() Joined: 31/05/2014 Location: AustraliaPosts: 261 |
Geoff's right (even if a tad biased ![]() Herry Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
HankR Senior Member ![]() Joined: 02/01/2015 Location: United StatesPosts: 209 |
Not quite right. You can specify the number of cycles to measure the period over and the result will be returned as a floating point number with a fractional part. Eg, if you measure over 10 cycles the result will have a resolution of 0.1mS and the Micromite can be doing something else while this is going on. Geoff, Big slipup on my part regarding the MM's ability to do multiple cycle period measurements. Thanks for pointing that out. Not sure how I seemed to have blacked out on that one. I have had the manual open to that section so it's not a case of not RTFM. So, as Jim has already said, multiple cycle interval measurements on both the 50 Hz signal and the 1 Hz reference signal will do it. Hank |
||||
HankR Senior Member ![]() Joined: 02/01/2015 Location: United StatesPosts: 209 |
You should consider getting one. It is fun to play with and does not cost much. Geoff I've really been on the verge of doing just that for at least 18 months. Really. One thing is that I find most of my projects want to consume very low average power. I'm talking under .5 mA low power, preferably around .1 mA or less. They don't ever need high speed and never fancy displays ... yet. Before this thread began I'd decided to get a few. I already have a few bare ICs (28 and 44 pin types), but need to get some Mup boards. |
||||
HankR Senior Member ![]() Joined: 02/01/2015 Location: United StatesPosts: 209 |
Herry, It's been an interesting thread. Hank |
||||
Warpspeed Guru ![]() Joined: 09/08/2007 Location: AustraliaPosts: 4406 |
I was interested in this a while back. Looking at the output of the home made 50Hz inverter powering my house on an oscilloscope, my scope has the facility to trigger the horizontal sweep from incoming mains frequency. So I powered the scope from the grid, and looked at my inverter. The trace was almost stationary, but it sort of wavered back and forth. Now my inverter is clocked by a 3.2768Mhz crystal that is very frequency stable. But the grid frequency does wander around in phase, but the frequency itself would have been well within +/- 0.1Hz at the time. To measure that meaningfully, you would need a frequency counter that could resolve at least .01Hz or even .001Hz. Not to difficult to do, but what is the purpose behind this exactly ? Cheers, Tony. |
||||
Zonker![]() Guru ![]() Joined: 18/08/2012 Location: United StatesPosts: 767 |
These parts might be useful... 2016-12-31_041416_AC-DC_Voltage_Detector_IC_HPCL3700.pdf One more fancy that the other... 2016-12-31_041528_AC_Opto_Coupler_-_S_110_LTV-354T.pdf Hopefully useful... ![]() |
||||
Herry![]() Senior Member ![]() Joined: 31/05/2014 Location: AustraliaPosts: 261 |
It's been an interesting thread. Hank It has drawn much more response than I expected and there's a tonne of stuff for me to get my mind around. It is of interest first purely as a challenge. Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
You should consider getting one. It is fun to play with and does not cost much. Geoff I've really been on the verge of doing just that for at least 18 months. Really. Cheapest pre-built board with suitable chip (MX170) I found was BV502 (under $10). You can use it with any USB serial device (CH340 / CP2102 / ...). John |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |