mehmet88
Posts: 4
Joined: Thu May 18, 2023 1:09 pm

Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Thu Jun 01, 2023 8:51 pm

Hello, I am developing a project related to measuring real-time deviations in grid frequency in the UK. I want to measure grid frequency with a resolution of 0.01 Hertz. I have found that the most practical way to achieve this is by using Zero Crossing. However, instead of designing my own circuit, I would like to use a HAT that can be directly connected to Raspberry Pi 4 GPIO. Does anyone have any suggestions? Has anyone done a similar project?

ghp
Posts: 3414
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Sat Jun 03, 2023 7:48 am

https://gridwatch.co.uk/frequency

One possible solution is to look for an isolated oscilloscope like https://cleverscope.com/products/CS448

Building an own solution is a safety problem: connecting electronics to mains can cause serious health problems and other accidents. Always observe safety rules and only perform experiments if you have appropriate certification.

If you look for a cheap solution then use a low power AC wall adapter (which provides AC voltage of some volts AND isolates from mains) and measure the low voltage AC using an ADC.

User avatar
bensimmo
Posts: 6290
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Sat Jun 03, 2023 7:56 am

Do a search, like Hackaday Zerocrosser, not a hat but you can build the circuit yourself.
Use that as a basis.

pidd
Posts: 4920
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Sat Jun 03, 2023 4:08 pm

If there is any HAT with a LDR, photodiode or phototransistor then its only a lightsource away from measuring the frequency.

Assuming UK If you only need the data once a minute then you can screen scrape the NationalGridESO website, or attempt to use its API which appears to be 0.01Hz resolution. In the last few minutes its been 50.04, 50.09 and 50.01

https://data.nationalgrideso.com/system ... tion#SysOv

If measuring live you will find there is a lot of jitter, this isn't frequency jitter its more like phase jitter due to load switching.

mehmet88
Posts: 4
Joined: Thu May 18, 2023 1:09 pm

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Mon Jun 05, 2023 4:44 pm

Many thanks for all your responses.

bensimmo wrote:
Sat Jun 03, 2023 7:56 am
Do a search, like Hackaday Zerocrosser, not a hat but you can build the circuit yourself.
Use that as a basis.
Actually, my first purpose is to find a ready circuit instead of building it by myself. That's why I'm looking for a separate device or hat which can work with Raspberry pi directly.
pidd wrote: If there is any HAT with a LDR, photodiode or phototransistor then its only a lightsource away from measuring the frequency.

Assuming UK If you only need the data once a minute then you can screen scrape the NationalGridESO website, or attempt to use its API which appears to be 0.01Hz resolution. In the last few minutes its been 50.04, 50.09 and 50.01

https://data.nationalgrideso.com/system ... tion#SysOv

If measuring live you will find there is a lot of jitter, this isn't frequency jitter its more like phase jitter due to load switching.
Actually, I need to measure frequency myself instead of receiving it from the website because I'm developing a frequency controller which detects frequency deviations and takes actions to correct the frequency.

So, I still need an alternative method or device to do that. The worse scenario is I will build a circuit which will use cross detection method but I prefer if someone suggests another method or device, hat etc to measure frequency from the grid, I would be grateful.

pidd
Posts: 4920
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Mon Jun 05, 2023 5:59 pm

mehmet88 wrote:
Mon Jun 05, 2023 4:44 pm
Actually, I need to measure frequency myself instead of receiving it from the website because I'm developing a frequency controller which detects frequency deviations and takes actions to correct the frequency.

So, I still need an alternative method or device to do that. The worse scenario is I will build a circuit which will use cross detection method but I prefer if someone suggests another method or device, hat etc to measure frequency from the grid, I would be grateful.
Its not so much frequency you need to track as phase, you put energy into the grid by trying to advance the phase by a very small amount.. There's no energy at the zero crossing point and assuming a perfect sinewave between them is fraught.

Advancing phase can be thought of as attempting to increase frequency but of course the frequency cannot increase significantly.

I presume grid-tie-in boxes map a sinewave of the desired current and advance or retard the phase to match the measured current against the modelled current. Initially you will have to sink in with the grid frequency but this can be done with a series resistor heavily limiting the current and drifting the phase until the measured current syncs up.

emma1997
Posts: 1794
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Fri Jun 09, 2023 4:58 pm

pidd wrote:
Sat Jun 03, 2023 4:08 pm
LDR, photodiode or phototransistor then its only a lightsource away from measuring the frequency.
Phototransistor is a good choice because it's fast and full swing output. Simply interface directly to Pi. Photodiode is fast but very low output so needs op amp or comparator and several other components. LDR is too slow. Rise/fall time can be seconds or even minutes. IE after exposure can take as much as 90 minutes to recover.

IMO a cheap/common optoisolator is perfect for this with phototransistor and LED all-in-one. Strangely can be cheaper than phototransistor alone. For example:
opto_110vac.JPG
opto_110vac.JPG (99.29 KiB) Viewed 1888 times


Simply a 4n37 opto w/100k and 1n4007 diode plugged directly into GPIO. Less than 25 cents to build.

Not a hat so not exactly what OP requested. However there are several different hats that do have an opto on board that can be modified similar to above ckt. However IMO well worth it to pick up some DIY skills. Specially if you are interested in saving hundreds or, in some cases, even thousands of dollars. IE replacing industrial PLC/Opto22 type setups. Maybe a lurker or two can benefit or OP may change his mind about rolling up sleeves.

As mentioned if you are not experienced working w/mains best find a friend who is.

User avatar
GTR2Fan
Posts: 1968
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Fri Jun 09, 2023 5:14 pm

Have you measured to check that the reverse leakage current of a 1N4007 is low enough to keep the reverse voltage across the LED below the specified 6V limit for a 4N37?

Even if it does, I'd want to at least double that resistor value when running from 240V AC mains.

As you suggest, that's not something anyone who's less than 100% confident of what they're doing should even contemplate.

I know that even the 110V mains you're dealing with can be fatal, but you really don't want to be accidentally grabbing hold of 240V mains.
Pi4B 2GB Rev1.4 Mini-PC/Media Centre: ARM=2.25GHz @1.1v, Core=600MHz, GPU=850MHz. Raspberry Pi OS with KODI on 128GB Sandisk Extreme Pro A2 microSD card in Integral card reader in USB3.0 port (138MB/s read). Geekworm P173 case with copper shim on SOC.

emma1997
Posts: 1794
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Fri Jun 09, 2023 5:58 pm

Good point but probably not a concern with Ir in the femtoamp range. Even datasheet values and over full temperature range no problem. Specially with real world measurements a thousand times better than stated.

Interestingly friends on another site determined that many different part numbers are actually the same die (1n4001, 1n4002, 1n4003, etc) because they are at least as good. Not even bin tested these days. High current versions too. Only real difference is cheapo chinese fakes use much less metal in the leads which can be a rare dissipation concern.

It's more common to put the diode in parallel instead of series. I prefer the latter for physical wiring and safety reasons.

Since you mention the r value I do actually double for 220vac as seen in this recent pic:

Image

200k instead of 100k. It does work for 110vac too because of opto's wide operating range. Of course a lot depends on the watt rating for the resistor and the LED but my tests show even as low as 33k works fine. It does get a bit warm though which can take a few minutes to settle so backing off to a higher value is good.

Note that as mentioned the LDR can be considerably slower so the optocoupler or phototransistor is preferred.
Last edited by emma1997 on Fri Jun 09, 2023 6:16 pm, edited 1 time in total.

User avatar
GTR2Fan
Posts: 1968
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Fri Jun 09, 2023 6:14 pm

emma1997 wrote:
Fri Jun 09, 2023 5:58 pm
Good point but probably not a concern with Ir in the femtoamp range.

As it seems you haven't actually measured it, I'll take the datasheets verbatim unless someone can prove otherwise.
Interestingly friends on another site determined that many different part numbers are actually the same die (1n4001, 1n4002, 1n4003, etc) because they are at least as good. Not even bin tested these days. High current versions too. Only real difference is cheapo chinese fakes use much less metal in the leads which can be a rare dissipation concern.

Once again, I'll take the official datasheets words over yours if that's OK.

Guessing or working on heresay is no way for a person to conduct themselves when dealing with potentially lethal circuits and voltages.
Pi4B 2GB Rev1.4 Mini-PC/Media Centre: ARM=2.25GHz @1.1v, Core=600MHz, GPU=850MHz. Raspberry Pi OS with KODI on 128GB Sandisk Extreme Pro A2 microSD card in Integral card reader in USB3.0 port (138MB/s read). Geekworm P173 case with copper shim on SOC.

emma1997
Posts: 1794
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Fri Jun 09, 2023 6:27 pm

Of course that's fine. Opinions are like... everybody's got one.

As a 50+ year EE professional I agree there are cases where it's important to stick to datasheets. To the letter. Mostly for CYA reasons in case of accident and liability for a commercial product. If insurance company can prove during discovery that you cut corners you're screwed. Or if even a small fraction field returns as a result can end your career.

Anyway specs for the 1n4007 are fine by a wide margin.

IMO for hobby or non-critical cost sensitive market (did somebody say CHINA!!!) it's ok to bend the rules a bit. Specially considering how bad the actual spec sheets are these days I personally prefer testing to theory.

Famous saying in EE world: "There's lies, damned lies, and then there's datasheets." lol

ame
Posts: 7814
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Fri Jun 09, 2023 6:38 pm

emma1997 wrote:
Fri Jun 09, 2023 6:27 pm
Famous saying in EE world: "There's lies, damned lies, and then there's datasheets." lol
Literally nobody says that in the EE world. Or anywhere else for that matter.
Oh no, not again.

User avatar
GTR2Fan
Posts: 1968
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Fri Jun 09, 2023 6:44 pm

ame wrote:
Fri Jun 09, 2023 6:38 pm
Literally nobody says that in the EE world. Or anywhere else for that matter.

Emma is now on my block list as I have no interest in conversing with them any further, and you're right. I've been a qualified EE for the past 40+ years and I've never heard that either. Utter nonsense!
Pi4B 2GB Rev1.4 Mini-PC/Media Centre: ARM=2.25GHz @1.1v, Core=600MHz, GPU=850MHz. Raspberry Pi OS with KODI on 128GB Sandisk Extreme Pro A2 microSD card in Integral card reader in USB3.0 port (138MB/s read). Geekworm P173 case with copper shim on SOC.

emma1997
Posts: 1794
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Fri Jun 09, 2023 7:00 pm

ame wrote:
Fri Jun 09, 2023 6:38 pm
Literally nobody says that in the EE world. Or anywhere else for that matter.


https://www.eevblog.com/forum/projects/ ... e-to-you!/

https://www.radiometrix.com/lies-damned ... atasheets/

Less than 10sec spent on this and few thousand more according to Googlue.. Anyway it's starting to get a little sticky in here so I'm out. TGIF.

ame
Posts: 7814
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Fri Jun 09, 2023 7:12 pm

emma1997 wrote:
Fri Jun 09, 2023 7:00 pm
ame wrote:
Fri Jun 09, 2023 6:38 pm
Literally nobody says that in the EE world. Or anywhere else for that matter.


https://www.eevblog.com/forum/projects/ ... e-to-you!/

https://www.radiometrix.com/lies-damned ... atasheets/

Less than 10sec spent on this and few thousand more according to Googlue.. Anyway it's starting to get a little sticky in here so I'm out. TGIF.
I found that one example (from that one time, in 2008) too. It's not exactly an expression I would describe as "famous".

Anyway, bye then.
Oh no, not again.

danjperron
Posts: 4487
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Fri Jun 30, 2023 9:18 pm

Cheaper and easy solution is to use an old power adapter that output AC. I do have a lot of those They output around 12Vac. Then I use a simple bridge using 1n4004 and a small resistor load hook up to a 2n3904 transistor which feed a pico. A little program using PIO will then provide the period in microsecond between cycle.

ex: viewtopic.php?t=352450&start=25#p2114159

mehmet88
Posts: 4
Joined: Thu May 18, 2023 1:09 pm

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Thu Jul 06, 2023 7:20 pm

I think most of you are missing my original question. I don't want to develop a zero crossing circuit myself since this will be a part of a research project but the main point is not the frequency measurement. So, I need to measure it in a simple way. That's why I'm looking for a ready-to-use (Plug-in) HAT or any other device which suitable to connect Rasberry Pi. So, is there any suggestion?

ghp
Posts: 3414
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Thu Jul 06, 2023 8:39 pm

If you need a fast and ready to use solution, then you have to buy equipment from the usual vendors. Most times expensive. But ready to use, you get a handbook, a lot of software and the possibility to get trainings or certifications.

From fluke I have seen a mains analyzer; my multimeter can measure frequencies but most possibly not in the accuracy you need. Guess frequency measurement or waveform analysis is possible with most good oscilloscopes supporting fft, filters, data analysis. Look for high voltage adapters and isolation, of course.

Below are links on which tools are used for german grid frequency measurement.

https://www.netzfrequenzmessung.de/
https://www.netzfrequenzmessung.de/messung.htm
https://www.gobmaier.de/datenblatt/Date ... ng_V23.pdf (There is no price tag on this tool, I am curious what the price is)

Basically it is possible to build things for low money, but you need a lifelong experience in electronics design, signal analysis and a bunch of tools to validate that the stuff build is really doing the job right. And all the knowledge about the safety rules.

And to be honest I think there are not that many people interested in measuring things on their own when frequency data can be retrieved from web pages.

ame
Posts: 7814
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Is there any zero crossing detector HAT to measure grid frequency (50HZ)

Thu Jul 06, 2023 9:56 pm

mehmet88 wrote:
Thu Jul 06, 2023 7:20 pm
I think most of you are missing my original question. I don't want to develop a zero crossing circuit myself since this will be a part of a research project but the main point is not the frequency measurement. So, I need to measure it in a simple way. That's why I'm looking for a ready-to-use (Plug-in) HAT or any other device which suitable to connect Rasberry Pi. So, is there any suggestion?
mehmet88 wrote: I want to measure grid frequency with a resolution of 0.01 Hertz
If there was a HAT you would have found it. If you couldn't find one then asking here is a great idea because someone else may have spotted one. Since that doesn't seem to be the case there probably isn't one. Insisting that that is still what you want isn't going to make one appear.

But, what is a HAT? It's just a bunch of hardware assembled into a module that conveniently attaches to a Pi. That's it. You could replicate the same circuit on a breadboard and attach it with jumper wires.

If there isn't a HAT that does what you want you have to adapt one, or build your own.

Measuring zero-crossing is easy with a little bit of hardware and software. If you want to actually understand the research project you are undertaking you should probably understand elements like this in detail. If it's the raw data that underpins your project you need to be able to say precisely how you acquire that data.

danjperron's suggestion is probably the best starting point. It's safe, and simple.
Oh no, not again.

Return to “HATs and other add-ons”