www.piclist.com/techref/microchip/devices.htm?key=pic

XOR 'em together Bob, then

the 1's represent when the two signals are different, and the 0's when they

are the same

Count the time that it's a 1

Count the time that it's a 0

the sum of the two times is the period......therefore gives frequency

the ratio of the two times gives phase angle 0 through 180 degrees

To get 180 to 360 degrees, you'll need to start counting it when say, A goes

up, and if B is already a 1, then B is leading A, so this is a minus lag if

you prefer. I would personally prefer to use a range -180 to +180, but

whatever!

A hardware XOR would allow you to use the CCP peripheral to do some timing,

or do the XOR in s/w. At 120Hz, a degree is about 23 microseconds, so

there's a reasonable amount of time to play with.

does this help?

Regards, Kevin

{Original Message removed}

See also: www.piclist.com/techref/microchip/devices.htm?key=pic