Recently ive been using this idea. That page describes how to run an LED from the mains but with just the capacitor and resistor you can run an AC input darlington opto. Ive been using this method for detecting the presence of AC but it should work fine to detecting a zero crossing too.
I always use an opto for safety. I did try a huge resistor feeding directly into the PIC which seemed to work fine till i connected the PIC to my laptop through serial and the laptop turned itself off.
My prefered method is to use the 12V coming from the supply transformer. If you can use a transformer for the supply then you only need 2 extra diodes and a resistor to feed into the PIC.
As for the code, i dont like using oninterrupt but i do use the interrupt flags. The program doesnt have to check the interrupt after each command that way. It checks it when you want.
Bookmarks