Shop OBEX P1 Docs P2 Docs Learn Events
New Project Questions — Parallax Forums

New Project Questions

CenlasoftCenlasoft Posts: 265
edited 2011-08-30 11:47 in Propeller 1
Hello everyone,
I working on the first phase of an ultrasonic non-destructive testing unit. I needed to measure the phase shift of two squarewaves. Attached is FFXOR.spin which includes a schematic in the comments. I am still not an expert at spin, therefore this program could use some work. I am having a prolem with some spin math and optimization. Here is my ultimate goal in this phase:
1. produced two squarewave to input to S1 and S2. Hopefully they should be out of phase.
2. run the squarewaves through a flip-flop and then X-OR.
3. use two prop pins to measure time of waveform.
4. use the formula: Phase_Shift = (t/T)*360, 't' is output of X-OR (pin 3) and 'T' is S2
I used a scope with two channels attached and measured the phase shift with the cursors and was getting results within 1% error from the code.
Any help would be appreciated,
Curtis

Comments

  • AribaAriba Posts: 2,690
    edited 2011-08-29 21:28
    Can you provide a timing diagram of the signals, maybe there's a way to do it without the external hardware, only with a counter in XOR logic mode.
    Why the FlipFlops?

    Anyway here is a measuring methode that may work more exact because:
    - the full clock tick resolution is used (not microseconds)
    - it hits always the pos-edge by waiting first for the pin to be low
    - calculation of t(T is done in the right order (first mult than div)
    PUB Get_T_t(BT_Pin, Lt_Pin) : Time_Num | delta1, delta2, cnt1, us
    
      us := clkfreq / 1_000_000
      'Get the 'T' value
      waitpeq(0, |< BT_Pin, 0)                  ' Wait For Pin To Go LOW 
      waitpne(0, |< BT_Pin, 0)                  ' Wait For Pin To Go HIGH
      cnt1 := cnt                               ' Store Current Counter Value
      waitpeq(0, |< BT_Pin, 0)                  ' Wait For Pin To Go LOW 
      delta1 := cnt - cnt1                      ' Store delta value
      'Get the 't' value
      waitpeq(0, |< Lt_Pin, 0)                  ' Wait For Pin To Go LOW 
      waitpne(0, |< Lt_Pin, 0)                  ' Wait For Pin To Go HIGH
      cnt1 := cnt                               ' Store Current Counter Value
      waitpeq(0, |< Lt_Pin, 0)                  ' Wait For Pin To Go LOW 
      delta2 := cnt - cnt1                      ' Store delta value
      Time_Num := delta2 * 360 / delta1         ' Return value of 360*(t/T)
      pst.dec(delta1 / us)                      ' Debug
      pst.NewLine
      pst.dec(delta2 / us)
      pst.NewLine
      pst.dec(Time_Num)
      pst.NewLine
    
    The precision of puls measuring can be improved with the help of a counter, but then you need to generate the 2 square waves in another cog to free the counters.

    Andy
  • CenlasoftCenlasoft Posts: 265
    edited 2011-08-30 07:06
    Andy,
    Thank you very much for your help. I'll try it this morning. As for the Flip-Flops, If I were to input directly into the X-OR, I would could only measure phase shift between 0 and 180 degrees. This way I can go from 0 to 360 degrees. At least that is what I read in an article from India for a simple phase meter. I used some of their ideas. Thanks, I'll post the entire project when I finish. It will be a sensitive ultrasonic instrument used for non-destructive testing on cultural materials.
    Curtis
  • CenlasoftCenlasoft Posts: 265
    edited 2011-08-30 11:47
    Hi everyone and thanks to Andy for his help. I used some of the code that Andy gave me and tested the results. I used the scope to verify the phase shifts and amazingly at frequencies les than 30khz, I was only .1 degrees off from the scope measurement. I plan on using this at 40 khz and at this frequency, I was .3 degrees off from the scope. I beleive this will work fine. This concludes Phase One. In Phase Two:
    1. I need to replace the two squarewaves produced from the counters with a signal (squarewave) (S2) from a prop pin exciting a ultrasonic transmitter (transducer) and the other signal (sinewave) (S1) coming from the ultrasonic receiver (transducer). The task at hand will be to convert the received echo from the ultrasonic receiver to a squarewave in order to input into the flip-flop (S1) and keep its phase at the same time.

    I will try an opamp (lm358(1)) to amplify the echo and an (lm358(2)) as a schmitt trigger to covert the signal. If there are any better solutions, please let me know. Any help will be appreciated.
    Thanks,
    Curtis
Sign In or Register to comment.