Measuring audio phase shift through a circuit with a PIC


Results 1 to 40 of 50

Threaded View

  1. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    I haven't checked your code, but, from the description, I think you need to look at it differently to get the correct results. Try it this way.

    enable comparator1 and 2 interrupts

    when comparator1 interrupts,
    clear timer1
    clear timer2
    start timer1 and timer 2 running

    when comparator1 interrupts again, do the following....

    stop timer1 running & store the 'count' (this gives a clock pulse 'count' for the arriving frequency, but since I'm only after phase shift...which is a time based measurement, I don't calculate the frequency)

    when comparator2 interrupts, stop timer2 & store the count
    Thanks for you input....seems reasonable - I'll be revisiitng this tonight (last night I got waylaid trying to get PIC to control a digital pot via SPI .....failed - http://www.picbasic.co.uk/forum/show...3540#post93540 )

    Using your revised approach, I reckon to calculate the phase change it's this....

    time lag (ie phase difference) = timer2 - timer1

    then to work out the phase ....time lag x 360/timer1/


    So an example, lets say timer1 = 2000 & timer2 = 2,200

    this would give a difference (time lag) of 200 clock pulses

    Now bearing in mind timer1 = 360 degrees (one complete cycle)

    Therefore to establish out how many single degrees of phase...

    200 * 360 /2000 ....which means in this example the phase shift is a 36 degrees lag.


    Putting that into actual frequency ....

    clock = 2us
    one 'wave' period = 2000 x 2us = 4ms
    In Hertz = 1/0.004 = 250hz

    time lag of second waveform = 200 x 2us = 400us

    Now being lazy, to verify, using an online phase calculator & inputing 250Hz & a lag time of 400us...

    http://www.sengpielaudio.com/calcula...delayphase.htm

    = 36 degrees.
    Last edited by HankMcSpank; - 7th September 2010 at 10:28.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts