Why not use a transformation from polar to rectangular coordinates?,=20 let's say make some vectors (1,phase) --> (x,y) and average all x and y components and then take the angle=20 of the resulting vector (atan(y/x)). I know this math can be a little=20 slow on a PIC, but maybe it's worth a try. El 07-06-2011 16:05, RNGolding@aol.com escribi=F3: > Hi, not sure if this should be PIC or EE, but I have opted for PIC > > I have an application where I need to measure the phase difference betwee= n > two sine waves of same frequency. I'm using two zero crossing detectors t= o > trigger the CCP1 and CCP2 inputs of a PIC. The CCP counter is clocked by= a > PLL/VCO at 360 x the sine wave frequency, so the difference between the > CCP1 and CCP2 counts provides a direct phase measurement with a resoluti= on of > 1 degree. > > So far so good, however the sine waves have some jitter so I thought I > would take the average of a few consecutive phase measurements. That is = where > I come unstuck, how do you average phase readings? > > To illustrate the problem, if the phase is jittering about zero degrees > giving 4 phase readings of say, 358, 359, 1 and 2 degrees, a simple aver= age > calculation yields 180 deg, which is obviously wrong. Does anyone know h= ow > calculate the true average, which should be 0 degrees? I'm sure the ans= wer > is obvious, but it has defeated me so far. > > Richard Golding > --=20 Lorenzo Luengo Contreras Ingeniero Civil Electr=F3nico Laboratorio MIDGEO (LF-106) Facultad de Ciencias F=EDsicas y Matem=E1ticas Universidad de Concepci=F3n Concepci=F3n - Chile +56-41-2207400 http://midgeo.udec.cl --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .