Analog: Calculating phase difference

Discussion in 'Analog & Mixed-Signal Design' started by SalceyForest, Aug 2, 2016.

  1. SalceyForest

    Thread Starter New Member

    Nov 6, 2015
    11
    2
    To introduce myself I'm an electronic technician. To those who don't know, the difference between technicians and engineers is that a technician just doesn't have the math.

    My problem is this: I have to measure the phase difference between two approximate (but always in sync) sine waves 10Hz - 200kHz. They're approximate because they're produced by pickups off rotating machinery. Could anyone point me in the direction of what area to study to resolve this problem, which is currently done by using comparators to produce a PWM signal relating to phase. I assume there are DSP chips which eat this sort of thing for breakfast but without knowing the principles I don't really know enough to choose one. The phase produced will be part of a control system, so will need to be read (or produced if fast enough) by some sort of PIC.

    Thanks in advance.
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,149
    1,792
    There are at leas two ways to look at a pair of harmonically related sine waves. They are peaks and zero crossings. So the phase difference can be measured as a time delay between the 10Hz. zero crossing (peak) and the 200kHz zero crossing (peak). In terms of circuitry zero crossings are generally easier to detect. This time delay can be either positive or negative. Once you have the time delay you can compute the phase angle in radians.
     
  3. SalceyForest

    Thread Starter New Member

    Nov 6, 2015
    11
    2
    It's odd, but you know how things suddenly make sense after you stupidly air them to the public? Forgetting the 10Hz, I was worried about the ability of hardware to measure a voltage at a suitably high frequency and then calculate a result without dropouts. But that isn't necessary is it? All I need to do is dedicate a couple of high-speed A-D's (20MHz+?) and trigger interrupts off the MSB change. Thanks!
     
  4. crutschow

    Expert

    Mar 14, 2008
    13,028
    3,238
    The required AD speed is determined by the phase resolution you need.
    Note that you need to look at the magnitude of the complete digital word, not just the MSBs to determine the peak point of the signal.
    What is the problem with using the comparators that are now being used?
     
  5. Papabravo

    Expert

    Feb 24, 2006
    10,149
    1,792
    Depending on the coding of the analog word the MSB transition from 1 (negative) to 0 (positive) defines the zero crossing, not the peak.
     
  6. crutschow

    Expert

    Mar 14, 2008
    13,028
    3,238
    Would it then not be the sign bit and not the MSB?
     
  7. Papabravo

    Expert

    Feb 24, 2006
    10,149
    1,792
    I don't think so since most converters use twos complement notation as opposed to sign magnitude format. Assuming a 4 bit word:

    -1 is 1111 in twos complement, and 1001 in sign magnitude
     
  8. BobaMosfet

    Active Member

    Jul 1, 2009
    109
    11
    The correct solution is an OpAmp. The difference between an engineer and a technician is that the former has math. The difference between a designer and an engineer is that the former has understanding.
     
  9. Papabravo

    Expert

    Feb 24, 2006
    10,149
    1,792
    Wrong. The correct distinction is that an engineer considers many possible solutions and picks the one that meets the requirements. Since the requirements are somewhat fuzzy at this point it is hard to make an evaluation. For the moment we are just spitballing here trying to define what done means in fundamental terms.
     
  10. SalceyForest

    Thread Starter New Member

    Nov 6, 2015
    11
    2
    The comparators are prone to spiking the power lines when they switch, being ultra-high speed notwithstanding decoupling also they and their associated interfacing (the input weakens as the wheel slows) are probably just unnecessary, error-inducing components. The original idea was just to buffer the inputs and ram them straight into a DSP which could do the hard work without influencing the signal in any way and then just output the speed, voltage and phase information to the PIC, probably via SPI.
     
  11. crutschow

    Expert

    Mar 14, 2008
    13,028
    3,238
    So which category are you? ;)
    An op amp isn't a solution without a circuit.
    How would you use the op amp to measure phase difference?
     
  12. Papabravo

    Expert

    Feb 24, 2006
    10,149
    1,792
    Not on a correctly designed PC board they don't.
     
  13. WBahn

    Moderator

    Mar 31, 2012
    17,760
    4,800
    Not really. Assuming the ADC output is in two's complement (probably a reasonable assumption), while we often refer to it the msb as the "sign bit" because it, alone, does give us that information, it also carries information about the magnitude of the value as well and, as a consequence, is not "just" a sign bit. The value represented by an N-bit two's complement value is

    <br />
V \; = \; b_{N-1} 2^{-(N-1)} \; + \; \sum_{k=0}^{N-2} b_k 2^k<br />

    where b_k is bit k such that b_0 is the lsb.

    This can be written a bit more compactly using predicate notation (think C's conditional operator) as

    <br />
V \; = \; \sum_{k=0}^{N-1} b_k 2^{\( (k < N-1)? \; k \; : \; -k \)}<br />
     
  14. BR-549

    Well-Known Member

    Sep 22, 2013
    2,004
    394
    Isn't a 10 Hz signal and a 200 kHz signal in sync, in phase?

    If you want to monitor mechanical play, don't compare the signals with each other. Compare both inputs with an independent reference. Or two independent references locked in phase.

    For sensor play, use AGC.
     
  15. WBahn

    Moderator

    Mar 31, 2012
    17,760
    4,800
    Not necessarily -- it depends on the precise definition being used for the term "in sync". Consider the three voltage waveforms of a three-phase power supply. Are they "in sync"? Whether the answer is yes or no depends on that precise definition. In the TS's context, it almost certainly means just that the two waveforms have a fixed relationship to each other.
     
  16. SalceyForest

    Thread Starter New Member

    Nov 6, 2015
    11
    2
    Sadly, that is EXACTLY what I meant by not having the math, although the tex reduction (V \; = \; \sum_{k=0}^{N-1} b_k 2^{\( (k < N-1)? \; k \; : \; -k \)}) etc. is much more comprehensible.

    Yes, the two waveforms are in a fixed relationship derived by a rotating shaft at varying speed.
     
  17. WBahn

    Moderator

    Mar 31, 2012
    17,760
    4,800
    Are the two waveforms always at the same frequency? If not, what is the relationship between the two frequencies? Some of the responses you've gotten have interpreted your initial post as saying that one waveform is at 10 Hz and the other is at 200 kHz -- is that what you meant?

    What do these waveforms look like? Are they sinusoidal?
     
Loading...