Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:43 03 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Mains frequency monitoring

     Page 1 of 4    
Author Message
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 07:50pm 28 Dec 2016
Copy link to clipboard 
Print this post

Has anyone put the Mmite to this task?
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
crez

Senior Member

Joined: 24/10/2012
Location: Australia
Posts: 152
Posted: 01:05am 29 Dec 2016
Copy link to clipboard 
Print this post

On a related matter I did use a maximite to measure mains power by sampling the mains voltage and current and then multiplying the two numbers and summing over a 20 millisecond period.
 
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 02:24pm 29 Dec 2016
Copy link to clipboard 
Print this post

OK. Zeroing in (I hope)! I will build a zero crossing counter fed from a plugpack and a bridge rectifier. There are three zero crossings each cycle. I will use this and eg SETPIN 15, CIN to measure number of milliseconds between pulses.

I note that the accuracy can be as good as .1% although specified as .9% but I suspect that it is temperature sensitive, and with temperatures here varying by as much as 20 degrees C in a day (!) I would like to be more accurate (I believe by law the mains frequency may not be beyond 1% of spec). Any thoughts on using a crystal?
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 03:20pm 29 Dec 2016
Copy link to clipboard 
Print this post

Assuming you have a DS3231 RTC then you could use the 1Hz output to count the number of zero crossings in one second (or more). It's crystal controlled and you can make the RTC slightly more accurate by loading the Aging Offset reg (at address &H10) with correction values.
 
VK2MCT
Senior Member

Joined: 30/03/2012
Location: Australia
Posts: 120
Posted: 03:31pm 29 Dec 2016
Copy link to clipboard 
Print this post

Another plan may be to half wave rectify teh AC from the plugpack to give a 50Hz rectangular wave. (clip it at 3.3V)
send MM Counting during positive half of square wave.

John B
VK2MCT
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 04:18pm 29 Dec 2016
Copy link to clipboard 
Print this post

@Herry - I don't know where you are or how interconnected the power company generators are there, but where I grew up, in Queens County NY (part of NYC), back in the 1950s we had an hysteresis synchronous mechanical clock on the kitchen wall. I carefully hacked it to a time signal from WCBS-AM and it stayed with 1 second of the time signals for years.

Here, the power companies have to keep the generators exactly synchronized, both in frequency and phase angle, or one generator would try to drive another lagging generator as a motor. That doesn't work too well when the generators produce a GigaWatt from a single shaft!

What I'm saying is that you could very possibly use the power line frequency to calibrate the oscillator on a uM board, not the other way around.

Paul in NY
 
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 06:59pm 29 Dec 2016
Copy link to clipboard 
Print this post

Paul said "...you could very possibly use the power line frequency to calibrate the oscillator on a uM board, not the other way around..."

Hi Paul, I'm afraid you have missed my point. Probably because I'm not very good at outlining it!

Here in Australia, and in most countries AFAIK if not all, the grid system is universally interconnected and the shafts of alternators are rotated at a closely fixed speed. By law here this must be within 1% of nominal. What drags down shaft speeds is excess load whereas excess capacity increases them. Hence grid control rooms are constantly seeking to match demand and supply.

What I want to do is monitor grid frequency very closely, to get a feel of the dragdown and the following corrective upspeeds deliberately introduced. So I want to very accurately measure grid frequency variations. Obviously I need to reference that to something else than the grid speed itself, because by definition that would always equal zero deviance!Edited by Herry 2016-12-31
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 07:50pm 29 Dec 2016
Copy link to clipboard 
Print this post

  Paul_L said   @Herry - I don't know where you are or how interconnected the power company generators are there, but where I grew up, in Queens County NY (part of NYC), back in the 1950s we had an hysteresis synchronous mechanical clock on the kitchen wall. I carefully hacked it to a time signal from WCBS-AM and it stayed with 1 second of the time signals for years.

Here, the power companies have to keep the generators exactly synchronized, both in frequency and phase angle, or one generator would try to drive another lagging generator as a motor. That doesn't work too well when the generators produce a GigaWatt from a single shaft!

What I'm saying is that you could very possibly use the power line frequency to calibrate the oscillator on a uM board, not the other way around.

Paul in NY


Agreed .... Maybe in Australia the mains is not as well maintained.
I, in fact, put my oscilloscope on 'line' trigger, and using a
60Hz PWM out of controller into the vertical input, adjust the clock
(for a stationary display) .
 
crez

Senior Member

Joined: 24/10/2012
Location: Australia
Posts: 152
Posted: 08:32pm 29 Dec 2016
Copy link to clipboard 
Print this post

A gps module, as long as it has acquired a signal, can serve as a very precise time reference. You can find them with a 10MHz or 1pps output. You are probably best counting the time for N mains cycles. If N=25 you would have 2 frequency samples per second ( in Australia )
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 08:46pm 29 Dec 2016
Copy link to clipboard 
Print this post

Hi Herry.

This is a subject close to my heart - been tinkering with mains frequency measurement etc on and off over the last few years.

Here in the UK, you are right there is a licensing agreement that the freq must stay within a tiny percentage of tolerance and the national grid provides this nice tool so you can see how they are doing. http://www2.nationalgrid.com/uk/services/balancing-services/frequency-response/ Years ago, the Post Office used to have clocks that worked using the mains frequency - which probably determined the legal aspect of mains control.

I have a nice ZCD circuit which I was playing with earlier this month purely as an exercise to see how small I could make it and you get a pulse reliably around 2V either side of zero. It could stand a lot of improvements (Schmitt triggering etc... - or feed it in a Schmitt input of your PIC even better). Maybe it will give you some ideas. http://www.fruitoftheshed.com/Circuit%20Ideas.Really-Simple-Zero-Crossing-Detect.ashx

On the subject of really accurate frequency measurement, have a look at Roman Black's site - he has done a lot with some really novel code to produce very accurate measurement/frequencies from any crystal... he even shows how to make a cystal oven for less that a buck(!) for hyper-stable crystal frequencies (I suspect this will figure in your design).

HTH

h

Edited by CaptainBoing 2016-12-31
 
HankR
Senior Member

Joined: 02/01/2015
Location: United States
Posts: 209
Posted: 09:24pm 29 Dec 2016
Copy link to clipboard 
Print this post

  Paul_L said   @Herry - I don't know where you are or how interconnected the power company generators are there, but where I grew up, in Queens County NY (part of NYC), back in the 1950s we had an hysteresis synchronous mechanical clock on the kitchen wall. I carefully hacked it to a time signal from WCBS-AM and it stayed with 1 second of the time signals for years.

Here, the power companies have to keep the generators exactly synchronized ...
[snip]

What I'm saying is that you could very possibly use the power line frequency to calibrate the oscillator on a uM board, not the other way around.

Paul in NY


Because of daily time correction measures done by all the civilized world's power grids, this long term 1 second accuracy you noted is entirely irrelevant to the short term accuracy of the power frequency. Short term being periods less than several hours.

The short term accuracy of the power grid is terrible. See this website for a realtime presentation of the UK's National Grid (company name) system's accuracy for the last 60 minutes revealing departures of approximately .2 Hz over that time span (at the time of this writing).

http://www2.nationalgrid.com/uk/Industry-information/electricity-transmission-operational-data/

So, the Micromite's crystal oscillator is certainly easily stable enough to show deviations of that magnitude. There is no way in the short term to calibrate the MM frequency by the power line with any certainty!

For more fascinating information about power generation systems see the Wikipedia entry "Utility Frequency," especially the Stability section:

http://en.wikipedia.org/wiki/Utility_frequency

The University of Tennessee Power Information Technology Laboratory also has real time maps updated every few seconds; one for the US grids and one for the entire world:

http://fnetpublic.utk.edu/
 
HankR
Senior Member

Joined: 02/01/2015
Location: United States
Posts: 209
Posted: 09:40pm 29 Dec 2016
Copy link to clipboard 
Print this post

I just fired up a frequency counter to measure the power line frequency and found not one, but my two best counters not running.

Could be from a nearby lightning strike quite a while ago that took out a microwave oven and a weather station.

More likely normal equipment aging and a coincidence. They're not toast and show good signs of basic life, just not gating properly, so I hope to be able to repair them without great difficulty.

Hank
 
HankR
Senior Member

Joined: 02/01/2015
Location: United States
Posts: 209
Posted: 09:55pm 29 Dec 2016
Copy link to clipboard 
Print this post

  Herry said   Paul said "...you could very possibly use the power line frequency to calibrate the oscillator on a uM board, not the other way around..."

Hi Paul, I'm afraid you have missed my point. Probably because I'm not very good at outlining it!



Herry,

What Paul meant was that the power line frequency might be more accurate/stable than that of the MM crystal osc., hence you would effectively be measuring the MM freq. variations rather than the powerline frequency variations if you built a powerline frequency meter that was based on the MM oscillator as a time base.

A case of the device under test (DUT) being more accurate than the testing system, but it isn't in this case. The MM is more stable than the power line frequency by many orders of magnitude as you know.

Hope that this wording makes it more clear what his thinking was.

HankEdited by HankR 2016-12-31
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 11:07pm 29 Dec 2016
Copy link to clipboard 
Print this post

Ah. I thought he meant that the power grid would be suitable over a long period for checking/correcting the 'mite over that long period.

I understand (or understood) that the mains if lower in frequency at a particular period of heavy load was then sped up in freq later to correct overall on the average.

It's something I was told years ago but never had reason to test or use.

JohnEdited by JohnS 2016-12-31
 
VK2MCT
Senior Member

Joined: 30/03/2012
Location: Australia
Posts: 120
Posted: 11:11pm 29 Dec 2016
Copy link to clipboard 
Print this post

You could use TV sig as a reference.

Take composite video or luminance from a Set top box (these signals are increasingly rare I know).
And feed signal into a cro locked to the vertical 'group' (50Hz) in the signal.
Other cro channel could be fed with a signal from MM or mains. If the second trace doesn't drift then it's on frequency.

TV sync could also be derived using a LDR taped to a screen. LDR would need low voltage supply and a series resistor. (I haven't tried this with LCD, but works a treat with Cathode Ray Tube)

TV stations used to use bloody expensive rubidium oscillators as ref but now use satellites)

My 2c,

John B
VK2MCTEdited by VK2MCT 2016-12-31
 
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 11:46pm 29 Dec 2016
Copy link to clipboard 
Print this post

  HankR said  
  Paul_L said  
The short term accuracy of the power grid is terrible.


Absolutely! It must be. because exactly matching demand and supply is impossible. And as was alluded to by another poster, the aim medium term is to 'get back' inaccuracies so that overall clocks are OK. The magnitude of short term deviations is a good illustration of the grid's ability to more or less manage demand. If exceptional conditions exist (like the heat wave we are currently having in NSW) it will doubtless be straining to cope.
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 06:58am 30 Dec 2016
Copy link to clipboard 
Print this post

Hi All;
I would have thought the uMite could do this rather well.
However, I'm having trouble making it work.

I'm using a 200K resistor from my 120VAC 60Hz main to pin 15.
I added a pair of protection diodes to +3.3v and gnd
plus a 0.1uF filter cap to remove noise.

My frequency counter, highly calibrated using a GPS reference,
and it reads very close to 60Hz.

Here is my test code snippet.
Micromite MKII MMBasic Ver 5.3 Beta 4
SUB MAIN
N = 0
HzAcu = 0
Pz = 10000 ' 10 SECONDS
SETPIN 15,FIN,Pz
PAUSE 500
DO
PAUSE Pz
Hz = PIN(15)
HzAcu = HzAcu + Hz
N = N + 1
PRINT CHR$(27)+"[1A";N;"N";STR$(Hz,3,2);"Hz";STR$(HzAcu / N,3,5);"Hz"
LOOP
END SUB
This consistently reads high, about 60.8Hz.

Is there a better way of doing this because my code is clearly not working?

Yes, I have done this using period but with similar results.

redrok
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 07:26am 30 Dec 2016
Copy link to clipboard 
Print this post

  Quote  Is there a better way of doing this because my code is clearly not working?


Remember your frequency reference in the Micromite is just its internal RC oscillator. If you have a MM+ handy try the same code with that at it uses an external crystal
 
HankR
Senior Member

Joined: 02/01/2015
Location: United States
Posts: 209
Posted: 08:19am 30 Dec 2016
Copy link to clipboard 
Print this post

My comments before regarding the MM crystal need to be corrected. Due to the fact that I currently have no Micromite of any flavor, I totally forgot that the plain MM
has no allowance to operate its clock from a crystal. I'm so used to even simpler micros (8 and 16 bit Pics, Arduinos) having crystals. I thought Herry's question was about using a crystal as the MM timebase, but now I read it correctly.

So, what I said only holds for the MM+. (I realized this before Peter's post came through.)

Too bad there is not an option (at present) to run the MM from a crystal. Could that be made an option for the MM without upsetting things too much?

Cheap microcontroller crystals are in the +- 10, +- 20, and at worst +- 30 ppm frequency accuracy and stability range, so plenty of excess accuracy there for this
purpose.

I think to shoehorn this in to MM basic without the MM+, I'd use a small PIC (crystal driven) to deliver a reference frequency of around 100 KHz to the COUNT pin, and use that to correct the reading of the line frequency done from another COUNT pin either using the frequency method and a gate time of 100 seconds. The reference frequency should be under 300KHz according to the manual for reliable counting by the MM.

The 100 second gate time is long but it will give a resolution to .01 Hz. There is +- .01 Hz for the systematic count error.

For a 50 or 60 Hz the interval method on the MM, being limited to millisecond increments, provides very low frequency resolution not adequate for this line frequency measurement. The ideal method of accumulating multiple period measurements should be done with a continuous measurement of the signal under test. I could not guess what a bunch of "separate" period measurements done by the MM and then averaged would yield for accuracy. I'll have to finally get a MM to check that out.
 
HankR
Senior Member

Joined: 02/01/2015
Location: United States
Posts: 209
Posted: 08:27am 30 Dec 2016
Copy link to clipboard 
Print this post

  matherp said  
  Quote  Is there a better way of doing this because my code is clearly not working?


Remember your frequency reference in the Micromite is just its internal RC oscillator. If you have a MM+ handy try the same code with that at it uses an external crystal


And if you can feed in a 300 KHz or lower frequency calibrated signal into the MM, that should reveal whether the MM internal clock inaccuracy is the source of your inaccurate measurement results. It would only have to be known to about 1 in 10,000 parts which is pretty coarse.

If you are able to do that please let us know what the result is.
 
     Page 1 of 4    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025