View previous topic :: View next topic |
Author |
Message |
Newbie Guest
|
Detect zero crossover |
Posted: Tue Oct 05, 2004 12:06 pm |
|
|
Hi,
I want to detect the zero crossover point of AC mains, can this be done with a PIC? or is there a nice little IC out there that will do the job?
Thanks |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Tue Oct 05, 2004 12:32 pm |
|
|
Look at Microchip application note AN521 at www.microchip.com. _________________ David |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Oct 05, 2004 4:23 pm |
|
|
If you doesnīt want to take any risk handling hot voltages, pick up through a
15-22K resistor the output of the rectifier - before filtering - in your power supply.
I assume you are using one in the range of 10 to 20V with a full wave rectiffier.
The another end of the resistor connected to the base of an NPN transistor (2N2222 or similar)
in common emitter mode (emitter grounded) and the collector connected to +5V
through a 2K2 resistor. In the collector you will get the signal that you need,
a clean going up pulse every time the line voltage is close to zero.
Should you need to insert a diode between the rectiffier and the filter capacitor
to be able to pick up a pulsating shape wave.
Best wishes,
Humberto |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Tue Oct 05, 2004 6:27 pm |
|
|
This method described above is simple and easy to implement however be careful because the main transformer can introduce a phase shift between the primary and secondary winding of the transformer.
You did not mention why the zero crossing detection was required. If it is to turn on a mains powered device at the zero crossing point there are devices available that will do that for you. |
|
|
J_Purbrick
Joined: 16 Sep 2003 Posts: 9
|
|
Posted: Tue Oct 05, 2004 10:50 pm |
|
|
You can check the input side of the line via an optoisolator. What you need to do is put a capacitor (rated for the line voltage, plus a good safety margin) in series with the isolator input, and a diode in parallel with the isolator's input but reversed relative to the LED. Then when the voltage is rising, the isolator turns on and when it's falling, it goes off. Trouble is, neither edge of the output signal gives you the zero crossing point, but you could calculate it by measuring the pulse width, and then adding half the width to the turn-on point. You can calculate the value of capacitor to use by working out the rate of change of voltage on the line, based on nominal voltage and frequency and the current you want through the LED. |
|
|
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
|
Posted: Wed Oct 06, 2004 12:27 pm |
|
|
See the data sheet for H11AA1. I use them all the time with PIC.
Code: |
33K 1W
120vac----/\/\/\/-------pin1 H11AA1
Neutral-----------------pin2
10K
+5------/\/\/\/---------pin5
Ground------------------pin4
Connect pin5 to processor input. Should see 60Hz pulses that occur at the 0 crossing.
|
|
|
|
Newbie Guest
|
Are these pins correct? |
Posted: Wed Oct 06, 2004 1:08 pm |
|
|
Thanks ljbeng thats just the simple solutio I'm looking for but are the pins correct?
Thx |
|
|
Newbie Guest
|
P.S. what size resistor for 240v AC |
Posted: Wed Oct 06, 2004 1:09 pm |
|
|
P.S. what size resistor for 240v AC |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Oct 06, 2004 2:51 pm |
|
|
I would recommend reading the app note even if you don't use that technique. It is only a few pages and explains how port pins work and acceptable error for a zero crossing detector. It is good background for any embedded programmer. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
|
Posted: Wed Oct 06, 2004 3:09 pm |
|
|
I just checked an existing schematic of mine and yes the pins are correct. I did not draw it well. It is a 6 pin device so the AC side is pins 1,2,3 and the low voltage side is 4,5,6. Pin 3 is a no connect. Pin 6 is the Base of the transistor and I have always left if float.
For 240VAC, I would use 66K 1W. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Wed Oct 06, 2004 6:45 pm |
|
|
Couple of suggestions to stop people from killing themselves....
Put a pair of 2.7 volt Zener diodes connected in inverse parallel across pins 1 and 2. This way if you have a component failure or a bad solder joint on the optoisolator pins 1 and 2 you will not end up putting mains voltage on the pins of the opto isolator.
Keep the pads under the opto isolator small such that you maximise the distance from the pins on the hot side to the pins on the other. It is good practice to cut a slot underneath the optoisolator such that pins 1 to 3 are isolated from pins 4 to 6 on the PCB.
IMHO the component values given for the example circuit are "too close" to the limits for producing a reliable clean output. The transfer function of the optoisolator is only 20%. Solutiuons are to use a 20K resistor instead of the 10K on the 5 volt side or use a H11AA3 or H11AA4 with transfer ratios of 50% and 100% respectively.
For 220V operation and above, if you use a H11AA4 you can safely double the input resistance value on the mains side (e.g. use a 100K or 120K resistor). This means you will reduce the power dissipation in the series resistor and avoid unnecessarily cooking the PCB.
Similarly, for 220V and above ensure that the resistor selected is capable of sustaining the peak voltages from the line. For example at 240V this means the resistor must have better than a 600volt breakdown voltage. |
|
|
J_Purbrick
Joined: 16 Sep 2003 Posts: 9
|
|
Posted: Sat Oct 09, 2004 11:07 pm |
|
|
The zener diodes would do the job, but if you wire it as shown in Ljbeng's diagram you are in for an unpleasant surprise. Half of the time, the reverse voltage across the optoisolator's LED will be the full line voltage, and it's not likely to be happy about it. A diode in parallel with the LED but pointed the opposite way would be adequate protection; a 1n914 is all you need. And I still say a capacitor is better than a resistor on the grounds of lower power dissipation, but it's true that it won't give you the exact zero crossing point. Then again, with the awesome computing power of a PIC available, that shouldn't be a problem. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sun Oct 10, 2004 8:39 am |
|
|
Just a comment,
A user who nick is Newbie asked this:
Quote: |
I want to detect the zero crossover point of AC mains, can this be done with a PIC? or is there a nice little IC out there that will do the job?
Thanks
|
Itīs not my intention to polemize nor attack to somebody, but I want to
state my point of view:
1)- As a "Newbie" I assume that he is fighting his firsts battles in this arena.
2)- As a "Newbie", I assume that he doesn't want to trigger or sinchronize
an atomic clock in nanoseconds range.
3)- I know that a transformer introduce a phase shift, from a Newbie
point of view, it doesnīt matter if the voltage is at 0° or 180°.
4)- He doesnīt mention that he needs to trigger or fire nothing.
5)- As a "Newbie" I think that we must guide him through the safest ways.
Regards,
Humberto |
|
|
|