Ho to detect phase shift in 2 square waves ?

Jan 30, 2004 5 Replies

Hi all...



I have 2 square waves that are out of phase by 90 degrees. I want to be able to tell when the first wave shifts from "leading" to "lagging". The second wave will do the opposite. I'm trying to do this in software. I have some ideas on how to do it with interrupts but I'd like to explore other possibilities. So, if someone can suggest where to dig out info on the subject. It would be great. BTW the frequency of the waves varies between 0 and about 1000Hz.



Thanks in advance


able

second

between 0

Input one wave to the D input of a flop, and the other to the clock. As = long as the waves are always the same frequency, the output state will = tell you which leads and which lags. Of course, given two input pins and = an interrupt, you could do it in software, as well.

Bill Posted with XanaNews Version 1.16.1.4

First thing is to decide just how quickly you need to make that decision. If it needs to be on the first available edge, then you will need to respond to all 4 edges in interrupts, or poll fast enough to catch the change at MAX freq. If you can wait a cycle, then the SW can be simpler, as it becomes a UP/DN counter problem -> just sample the level of one phase, on a given edge of the other. Look for Quadrature Encoder / Qudarature Decoder info.

-jg

On the rising edge of one of the inputs, sample the state of the other input. If it high, then the second input leads. If it is low, then the first input leads.

-Robert Scott Ypsilanti, Michigan (Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)

Reading a rotary encoder? :)

If you have the bandwidth on your processor, you could sample it at a few kHz and determine the up/down edge (or illegal state change) from the delta from the previous snapshot of the two encoder outputs. Obviously, there are 4 possiblities.

If you use interrupts directly, the loading on your processor varies with the frequency, which may make debugging and bulletproofing your code more challenging. If the frequency goes to high with polled inputs you start to miss counts. The other way, you could conceivably have more serious problems.

Best regards, Spehro Pefhany

"it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required