# AC powerline monioring, zerro crossing detection

Discussion in 'Embedded Systems and Microcontrollers' started by iceman529, Mar 6, 2014.

1. ### iceman529 Thread Starter New Member

Jun 17, 2013
16
0
Hi I am working on a project analyzing the ac power line and I need to detect the zero-crossing point using an 16bit ADC, is there a smarter/better way of doing this than

I sample 128 times per period and I'm calculating the adc_average every period, by using the method above I'm still having some jitter when detecting the zero-crossing.

Last edited: Mar 6, 2014
2. ### blueroomelectronics AAC Fanatic!

Jul 22, 2007
1,758
98
A comparator.

3. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,973
1,834
It's better to do this digitally: drop a transistor next to your power transformer to capture the AC wave and make power line synched pulses.

Jul 18, 2013
17,512
5,281
Check the Fairchild APP note AN-3006, you may be able to adapt that.
Max.

5. ### iceman529 Thread Starter New Member

Jun 17, 2013
16
0
I have to use the ADC for doing this so the only way i see it is maybe there a better mathematical solution to my question?

6. ### ericgibbs Moderator

Jan 29, 2010
7,382
1,494
hi,
Sampling at 128/sec is every ~8mSec, so if the mains frequency is say 50Hz, 20mS, I would expect you would always get jitter when trying to detect zero crossing using this method.

As suggested, a comparator which triggers a MCU interrupt would be the way I would go, you can still process the AC waveform using the ADC.

E

7. ### nigelwright7557 AAC Fanatic!

May 10, 2008
525
74
I used to do it with 2 resistors as a potential divider into an I/O pin

8. ### THE_RB AAC Fanatic!

Feb 11, 2008
5,430
1,311
Hi Eric, I believe he is sampling 128 times during each mains cycle period?

For the O.P, I think you can use a "debouncing" system to remove any noise artifacts near the zero cross point.

You can use similar code but detect when the ADC has been >avg for X samples (detects / edge), then when it has been <avg for X samples you detected the \ edge.

A more sophisticated system uses a window, and will be safe even when any individual zero-cross is damaged;

The one above I have used many times with excellent result. Because it syncs first, then only tests for the edge during a tiny window, it will negate large errors that occur during any one cycle and give a solid sync even if there is some nasty noise at times.

More mains sync systems are shown on this page (3/4 down the page);
http://romanblack.com/onesec/High_Acc_Timing.htm#decfreq