CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Detect zero crossover

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Newbie
Guest







Detect zero crossover
PostPosted: Tue Oct 05, 2004 12:06 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 05, 2004 12:32 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 05, 2004 4:23 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Oct 05, 2004 6:27 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 05, 2004 10:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 06, 2004 12:27 pm     Reply with quote

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?
PostPosted: Wed Oct 06, 2004 1:08 pm     Reply with quote

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
PostPosted: Wed Oct 06, 2004 1:09 pm     Reply with quote

P.S. what size resistor for 240v AC
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Oct 06, 2004 2:51 pm     Reply with quote

drh wrote:
Look at Microchip application note AN521 at www.microchip.com.


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

View user's profile Send private message

PostPosted: Wed Oct 06, 2004 3:09 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Oct 06, 2004 6:45 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Oct 09, 2004 11:07 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Oct 10, 2004 8:39 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group