Evil AVR app note that uses microcontroller body diodes to zero cross detect mains. Insanity writ large. http://www.atmel.com/dyn/resources/prod_documents/doc2508.pdf The AVR IC designers must tear their hair out when their app note writers commit such lunacy. They effectively use 2 megohm input resistance (although they are not obviously aware of this from in-text comments). Diode currents of around +/- 240 x 1.414 / 2 m =3D~ 150 uA+ can be expected= .. Well above the "microamp range" that Microchip recommend in their not quite as bad but still stupid foray in figs 10-1 and 10-2 here. http://ww1.microchip.com/downloads/en/DeviceDoc/chapter%208.pdf Russell McMahon _____________________ Copy and paste from my stack exchange rant here http://electronics.stackexchange.com/questions/25691/measuring-frequency-= of-a-signal-above-5v-with-a-microcontroller PROTECTION DIODES: Many people are unaware of or just ignore the datasheet distinction between "Absolute maximum" ratings and recommended operating conditions. Absolute maximum ratings are those which the device is guaranteed to survive without damage. Correct operation is not guaranteed. The PIC concerned allows Vdd + 0.3V on its pins as an absolute maximum rating. Operation is not guaranteed during this condition. Most data sheets clearly specify that during normal operation input voltages should not exceed the ground to Vdd range. This datasheet may or may not ro so in its several hundred pages. It is still wrong to do so. Many people have thought that concerns about protection diode currents are baseless. Only some of them have rued the day they thought so and most have probably lived to rue it or not :-). Note that the (evil) Atmel application note here uses a 1 megohm resistor (connected to AC mains ! ) and the Microchip app note here - figs 10-1 10-2 at least has the grace to say " ... The current through the clamp diodes should be kept small (in the micro amp range). If the current through the clamping diodes gets too large, then you risk the part latching up." Atmels hundreds of uA is NOT "inh the microamp range". BUT latch up is the least of your problems. IF you latchup the part (SCR action triggered by currents into IC substrate) the IC often turns into a smoking ruin and you realise that something may possibly be wrong. The problem with body diode currents is when you do NOT get an immediate smoking ruin. What happens is that the IC was never designed to accept current between input pin and substrate - the layer hat the IC is laid down on. When you raise Vin > Vdd the current effectively flows out of the ICV proper into a phantom fairyland that the iC is unaware of and that the designer did not and usually cannot design for. Once there you have small potential;s set up that are never normally there and current can flow back into adjacent circuit modes, of not quite adjacent nodes or even into locations some distance away depending on how big the currents are and what voltages are set up. The reason this is hard to describe and pin down is because it is totally undesigned and essentially undesignable. One effect is to iject currents into floating nodes that have no formal output path. Thse may act as gates for FETs - formal or accidental ones, that tuirn on or off semirandom parts of your circuit. Which parts ? When? How often? How long? How hard? Answer - who can tell / nobody can tell - its undesigned an undesignable. Q: Does this actually happen? A: Oh yes! Q: Have I seen it happen? A: Yes. I started what has now proved to be a 1+ decade crusade to make people aware of this (even though I should have been well aware of it) after being very badly bitten by it. I had a relatively simple async serial circuit that caused me no end of strife. Processor operation was intermittent or semi random. Code faulted sometimes and not other times. Nothing was stable. The problem? Body diode conduction, of course. I had copied a simple circuit from an application note supplied with a product and away we went. If you do this without due care it WILL bite you. If you do it with care and intelligence and design it may well not bite you. But may. This is akin to pulling over the centre line into ongoing traffic to overtake - done with care and not too often and leaving what may be good enough margins you will usually not die. If you do you will probably not be surprised :-). So it is with body diode conduction. Microchips 'microamp range" may be OK. Atmel's 1 megohm off mains is an accident waiting to happen. Suit yourself. --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .