Quote Originally Posted by ardhuru View Post
I need to monitor the 3 mains phases and detect if (a) one goes dead and (b) if the 3 phases are incorrectly sequenced. The 3 phases are being fed to 3 different pins on a 16F676.
Off the top of my head...just an idea...may or may not work...

Rectify and regulate each phase, use a zener diode on each phase to get each phase to output a 5v pulse.

Input each phase's output pulse to RA0-1-2, use the 'Interrupt on Change' feature.

Set up TMR1 with your oscillator speed (prescalers, etc) so you can get decent resolution and yet be able to count up to 10.33ms.

Enable RA0/RA1/RA2 I/O/C. Wait for the leading edge of the RA0 pulse using the Interrupt. Save TMR1 value. Wait for the RA1 pulse, save that time. Wait for the RA2 pulse and while waiting, subtract the TMR1 values for the RA1 and RA0 pulses and make sure they're within spec.

If, for instance, after you get the RA0 pulse, you get the RA2 pulse next, you know you've skipped the RA1 pulse and that phase is probably missing.

I'm thinking of a sort of 'software latch', where one pulse enables getting another pulse, which in turn enables getting another pulse. If anything other than the pulse you are waiting for shows up, then flag an error. And in the meanwhile waiting for pulses, you do a bit of math to make sure the pulses are coming at the right times.