Determining phase difference between two signals
LukeH
Posts: 22
This should be a real easy one.
I have a sensor which reads an angular position and returns the information by phase modulating a square wave. On a separate channel, the sensor also outputs a non-shifted reference square wave of the same frequency as the signal wave; the frequency varies somewhat, but at any given moment, both the reference and the data signal are always exactly the same frequency. Only the phase difference between the two signals is of interest; the frequency itself carries no information. Both are 50/50 duty cycle square waves and both are on a DC bias, so that they swing between 0 and +V. Conveniently, the phase shift of the sensor signal is directly equal to the angular position of the physical sensor. The frequency is relatively low, approx. 500 Hz plus or minus a couple hundred.
Given this relatively simple phase modulation, how best to interface it to a Propeller? I have little experience with the Prop's counters, but I think this problem lends itself readily to counter use. Send the reference signal and the data signal to a counter or counters, and use some kind of differential or logic mode to accumulate the phase difference somehow, then write this into a variable in the hub which gets updated every time the counters complete a measurement. I know in general how to set up the counters, but not sure which mode to use. Again I don't need to measure the frequency, only the phase difference.
Overall, I don't need more than a degree of resolution from this sensor, and something like 30 degrees of resolution/precision would even be acceptable.
Not looking for someone to solve the entire problem for me, but looking for a starting point. I haven't enough experience with counters, and think I could learn something from this. Ideas?
I have a sensor which reads an angular position and returns the information by phase modulating a square wave. On a separate channel, the sensor also outputs a non-shifted reference square wave of the same frequency as the signal wave; the frequency varies somewhat, but at any given moment, both the reference and the data signal are always exactly the same frequency. Only the phase difference between the two signals is of interest; the frequency itself carries no information. Both are 50/50 duty cycle square waves and both are on a DC bias, so that they swing between 0 and +V. Conveniently, the phase shift of the sensor signal is directly equal to the angular position of the physical sensor. The frequency is relatively low, approx. 500 Hz plus or minus a couple hundred.
Given this relatively simple phase modulation, how best to interface it to a Propeller? I have little experience with the Prop's counters, but I think this problem lends itself readily to counter use. Send the reference signal and the data signal to a counter or counters, and use some kind of differential or logic mode to accumulate the phase difference somehow, then write this into a variable in the hub which gets updated every time the counters complete a measurement. I know in general how to set up the counters, but not sure which mode to use. Again I don't need to measure the frequency, only the phase difference.
Overall, I don't need more than a degree of resolution from this sensor, and something like 30 degrees of resolution/precision would even be acceptable.
Not looking for someone to solve the entire problem for me, but looking for a starting point. I haven't enough experience with counters, and think I could learn something from this. Ideas?
Comments
-Phil
I suspect I may need to use two counters; one in POSEDGE mode to count the frequency and thus determine the period to watch for; the other to run the XOR accumulation.
-Phil
Addendum: I guess I was a bit hasty in my analysis. But, at 500 Hz, this should be doable in software. Let me think some more about it.
Inspired by a different thread, I am trying to build a simple assembly which roughly simulates the way a heat-seeking missile seeker works. A small motor spins a reticle, half clear half opaque, through which incoming light passes, on its way to a single phototransistor. A separate LED+phototransistor around the very edge, out of the lens field of view, provides the reference signal. The whole thing is very crude and needs some discrete components to amplify and filter the noisy signal, but works well enough in a dark room when a bright light (laser pointer) is aimed through different quadrants of the reticle, on to the primary (signal-generating) phototransistor. I should send a photo or diagram.
The phase shift occurs over the entire period of the data signal, not just half. The domain of the sensor is exactly one complete revolution, and it wraps around when it passes <0 or >360. Thus -20 or +340 are functionally equivalent. This is also why I put in the reference signal, to give something to compare it to.
I think my objective can be accomplished by sensing the rising edge of the reference wave, then timing until encountering the rising edge of the signal wave, then timing again until encountering the rising edge of the reference wave again. The ratio of the two times will represent the angle around the circle, from the reference point, where the incoming light beam is hitting. Now just to figure out the best way to do that with a prop (can probably even be done with analog components too).
This is also kind of how some aircraft navigation systems (VOR) work, as a very rough analogy.
By the way, I overestimated the speed of the motor, the sensor actually generates a signal closer to 120-150 Hz. Plenty of time to do computations in software.