I do a 12K per year job with a 12c508 and the internal diodes work fine. I use 2 x 4m7 in series and a small cap (470p) on the pin. You have to watch the voltage rating of the resistors they are at best 200v and the peak voltage is 1.707 x 240 (350 ish) particularly on 0805 smd parts. Regards Steve... -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU] On Behalf Of Olin Lathrop Sent: 26 October 2003 16:29 To: PICLIST@MITVMA.MIT.EDU Subject: Re: [PIC]: PIC <-> 240VAC Mohit Mahajan wrote: > Refering to Microchip's AN521, it shows a PIC connected to AC supply > line (of "several hundred volts") using just a 5 megaohm resistor in > series in between. Safety issues apart, it looks too simple to be true. > Is this enough to detect a zero-crossing (eg. for a PIC based triac > dimmer)or should I put two clamping diodes on the pin detecting the > zero-crossing? I'm using a PIC16F870. I've read the manual and I believe > it doesn't have protection diodes in its i/o pins. > > --->|---o Vdd > R | > 240VAC o-------/\/\/\---o----o---------o PIC i/p > 5 M | | > | ---|<---o Vss > \ > R / > 100K \ > | > o > Gnd Actually PICs do have protection diodes on most pins. The exceptions are MCLR because is needs to tolerate 13V during high voltage programming, and RA4 when it is open drain. Aside from those pins, you don't need external diodes in the circuit above. However, while the protection diodes are there and they work, I would try not to rely on them unless this is a very high volume product where every penny matters. I've also seen strange A/D readings on one channel when another had a little current going thru its protection diode. I don't know how universally the issue applies. Barring very high volume design, I would do what you showed above, but then add a 10Kohm resistor in series with the PIC pin. Diode forward voltages can vary, and if your clamping diodes clip at a little higher voltage than those in the PIC, you can still get some current thru the PIC diodes. With the 10Kohm resistor in series, the difference in diode voltage will be divided by 10Kohms to make the PIC diode clamp current. That will be so small you can ignore it. After that, there are many other refinements. Whether they make sense depends on price, risk of failure, noise immunity, etc. For example, some hysteresis will be useful in some applications. Other applications might benefit from filtering high frequency noise. You might also consider splitting the 5Mohm resistor into two separate resistors to increase creapage distance and immunity to dirt and humidity. ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.