# Ho to detect phase shift in 2 square waves ?

#### Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

•  Subject
• Author
• Posted on
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

Re: Ho to detect phase shift in 2 square waves ?
oN 29-Jan-04, Rodo said:

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

Re: Ho to detect phase shift in 2 square waves ?

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

Re: Ho to detect phase shift in 2 square waves ?

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

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

Re: Ho to detect phase shift in 2 square waves ?

Re: Ho to detect phase shift in 2 square waves ?
On Fri, 30 Jan 2004 05:00:49 GMT, the renowned "Rodo"

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.

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"
snipped-for-privacy@interlog.com             Info for manufacturers: http://www.trexon.com
We've slightly trimmed the long signature. Click to see the full one.