Measuring audio phase shift through a circuit with a PIC


Closed Thread
Results 1 to 40 of 50

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hi Hank,

    One more suggestion...

    It takes a long time (relatively speaking) to send out your serial string. In PBP Ints, I'm pretty sure the interrupt is not responded to until the HSEROUT line is finished. So if code space isn't a particular issue at this time, try changing
    Code:
    HSEROUT ["  C1=",dec Comp1Time,9,"  C2=", dec comp2time,9, "phase_shift=", dec phase_shift/10,".",dec phase_shift//10, 13, 10]
    to (get ready for it...)
    Code:
    HSEROUT [" "]
    HSEROUT ["C"]
    HSEROUT ["1"]
    HSEROUT ["="]
    HSEROUT [dec Comp1Time]
    HSEROUT [9]
    HSEROUT [" "]
    HSEROUT ["C"]
    HSEROUT ["2"]
    HSEROUT ["="]
    HSEROUT [dec comp2time]
    HSEROUT [9]
    HSEROUT ["p"]
    HSEROUT ["h"]
    HSEROUT ["a"]
    HSEROUT ["s"]
    HSEROUT ["e"]
    HSEROUT ["_'}
    HSEROUT ["s"]
    HSEROUT ["h"]
    HSEROUT ["i"]
    HSEROUT ["f"]
    HSEROUT ["t"]
    HSEROUT ["="]
    HSEROUT ["dec phase_shift/10]
    HSEROUT ["."]
    HSEROUT [dec phase_shift//10]
    HSEROUT [13]
    HSEROUT [10]
    Or/and shorten what you are sending....

    Best Regards,
    Paul

  2. #2
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    This is an excellent work, and very easy to follow and read through. You should consider placing this in the Wiki or Project section.

    In a sort of backwards way, I had one of those aha moments out of this thread.

    I had thought the ANSEL turned on/off the AtoD for a given pin - certainly my comparators have been working with the corresponding ANSEL deselected? I had a similar discussion with Melanie & she considered them digital....
    This is absolutely true for the outputs (i.e. comparator output) as they will be either high or low. This is, however, not true for the inputs (i.e. comparator input) as your are using their analog nature to compare (in your case) against a reference (this is also alluded to on the post you mention);which is what I was referring to (ANSEL.6 and ANSEL.7). In summary, comparator outputs are digital, comparator inputs are analog.

    This is what was nagging me; something does not look correct, yet it behaves correctly (maybe). Then came the aha moment. You run the analog signal through the schmidt triggers effectively converting it from analog to digital. Then you feed the signal into the comparator. So why do you even need a comparator? You really don't, BUT, for your system you really need some sort of comparator (not an analog one, a digital one so you can trigger on its change of state). And, perhaps unbeknownst to you, that's what you created. By letting the comparator input pins be digital, you created a digital comparator (sort of like a logic gate) - very cool.

    With that said, you probably could save the schmidt triggers and run the analog waveforms straight to the comparator (they would have to be conditioned / buffered before hitting the comparator). But you have the concept working, so I would not change it now.

    Again, very nice job.

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by languer View Post
    This is an excellent work, and very easy to follow and read through.

    With that said, you probably could save the schmidt triggers and run the analog waveforms straight to the comparator (they would have to be conditioned / buffered before hitting the comparator). But you have the concept working, so I would not change it now.

    Again, very nice job.
    Thanks...& as it goes I'm pleased how the contributions rolled in - all had value...( and also gave me a 'second wind' so to speak) .

    In the end I do take the analogue sine waves, square them up by amplifiyng it a *lot* (my circuit will have a couple of unused opamp stages, so I figured it would save component space by using those vs Schmitts) ...then push it into the PIC comparators (so no schmitts were harmed in the making of this thread anymore).

    It works, but I'm not sure how robust the resulting comparator triggering will be under certain circumstances - early on in the thread there were defintiely some severe phase outcome errors when the analog signals into the comparators were not of the same magnitude ...obvious in retrospect, but when you're getting wrapped up with all manner of new learning experiences blah blah (I now need to spend a bit more quality time, trying different permutations)

    My last workin g code I posted (late last night)....it all works, biut I'm sure seasoned programmers wince at the way I'm using DT's stuff - not sure one little bit if that's an acceptable practise. For example, where I setup the interrupts....

    Code:
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   CMP1_INT,  _Comp1_Int,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    the last two columns...are they right? (Hank makes a mental note -hmm, really must get around to learning programming properly, rather than winging/kludging/pleading whenever a need arrives ...and that includes interrupts!)

    Being an onld electronics type, I too initially related a PIC's comparator inputs to being analog devices...and to tell you the truth I'm still not sure if from a PIC perspective, whether its comparator inputs are analog or digital...I just roll with what works...and deselecting ANSEL for the pins involved works! (perhaps someone can chime in what the true definition of ANSEL funtion is - ie is it purely related to the AtoD functionality or does it mean 'analogue' in general?)


    PS tks Paul for the stuff about HSerout - & whilst that 'tip' is somewhat ugly on the eye, it all makes complete sense!
    Last edited by HankMcSpank; - 30th September 2010 at 19:17.

  4. #4
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default ANSEL controls analog/digital state of input, not to what function is routed to

    perhaps someone can chime in what the true definition of ANSEL funtion is - ie is it purely related to the AtoD functionality or does it mean 'analogue' in general?
    I thought I answered this in the previous post. In any case, ANSEL controls whether the respective PIC inputs are set to analog or digital. It does not care about the ADC. Other registers allow you to decide whether the respective analog input is used for the ADC or the Comparator, or ...

    In your case you lucked out because even though you did not set the inputs to analog, you had already squared up the inputs to make them sort of digital.

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by languer View Post
    I thought I answered this in the previous post. .
    Apologies, I'd picked up (misread), that there was still a degree of uncertainty!

    Quote Originally Posted by languer View Post
    In your case you lucked out because even though you did not set the inputs to analog, you had already squared up the inputs to make them sort of digital.
    That sums it up nicely - got it! (that said, what you're saying would suggest, it wouldn't be the comparator' Internal VREF deciding the 'flip/trigger point', but the PIC's internal high low digital detection circuitry? (ie when is a '1' a 1' and when is it a '0')

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