> I have a question which may be defined as FAQ. > I have to synchronize a zero cross main signals with an output nibble on > both rising and falling edge. > I have done this in hardware using one 4093 and a few resistors, > capacitors and one zenner for detection and a 74ls373 for command. > I'm not sure if the best choice on a PIC will be to use rb0 as zero > cross detection interrupt. The nibble must be outputed > synchronously with the rising edge of the mains signal and shutted off > after a desired time period on the falling edge of the same signal. > I think also interrupt on change could satisfy this request but I want to > know other opinions. > The PIC will be 16F628. If I understand you right, you want to set an output on the rising zero crossing of the power line and reset the output some specified time period after the falling zero crossing. Since the power line frequency is very stable and predictable, you probably don't even need to look at the falling zero crossing unless the timing relative to it is VERY tight. Using the RB0 interrupt followed by timing should be fine. The only thing to watch out for is the phase shift introduced by the filtering and scaling of the power line to get to RB0 (220V AC is a bit much for the protection diodes ;-o). This should be repeatable so should not be hard to account for. If you really want to be fancy, use the CCP module in capture mode. This will allow you to measure the power line period very accurately and always know where you are within a power cycle. I did something like this once for spinning LEDs. The CCP module was used to catch timer 1 at a fixed point in the revolution, which allowed very accurate measurment of the period. I then used timer 0 to time the pixels around the circle. Worked very well. ******************************************************************** Olin Lathrop, embedded systems consultant in Littleton Massachusetts (978) 742-9014, olin@embedinc.com, http://www.embedinc.com -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.