Measuring audio phase shift through a circuit with a PIC


Results 1 to 40 of 50

Threaded View

  1. #15
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Ok, this seems to work (ie it allows a 'main body' of program to run, with an interrupt handler)....

    Code:
    Comp1Time       var  word    
    Comp2Time       var  word
    phase_shift     var  word
    c               var  word
    dummy           var word
    
    
    T1CON.0= 1  'start timer
    
    Comp1Time = 0 'clear down Comp1Time, prior to starting.
    comp2Time = 0  'clear down Comp2Time, prior to starting
    
    PIR2.5 = 0    'Clear the Comp1 interrupt flag
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System  PO90OOO9
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   CMP1_INT,  _Comp1_Int,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON.0= 1  'start timer
    
    Comp1Time = 0 'clear down Comp1Time, prior to starting.
    comp2Time = 0  'clear down Comp2Time, prior to starting
    
    @ INT_ENABLE  CMP1_INT     ; enable Comparator 1 interrupts
    
    Top:
            c = 3600
            dummy = comp2time * c  
            phase_shift  = DIV32 comp1time
            HSEROUT ["  C1=",dec Comp1Time,9,"  C2=", dec comp2time,9, "phase_shift=", dec phase_shift/10,".",dec phase_shift//10, 13, 10]
            goto top
    
    Comp1_Int:
            PIR2.5 = 0
        Loop1:
            WHILE PIR2.5 = 0       
            GOTO Loop1
            WEND
            TMR1H = 0                    
            TMR1L = 0
            PIR2.5 = 0
            
            Comp1_count:
            WHILE PIR2.5 = 0
            goto Comp1_count
            wend 
            Comp1Time.Highbyte = TMR1H  
            Comp1Time.Lowbyte = TMR1L+2
            TMR1H = 0                    
            TMR1L = 0
            PIR2.6 = 0
            'HSEROUT [dec Comp1Time,13, 10]
                
            Comp2_count:
            WHILE PIR2.6 = 0
            goto Comp2_count
            wend
            Comp2Time.Highbyte = TMR1H  
            Comp2Time.Lowbyte = TMR1L+6
            TMR1H = 0                    
            TMR1L = 0
            if comp2time> comp1time-23 then comp2time = 0
            'HSEROUT ["C1=",dec Comp1Time,9,"C2=", dec comp2time, 13, 10]
            PIR2.5 = 0
    @ INT_RETURN
    The actual final phase calculation jitters about a bit (but I suspect that down to the somewhat jittery quality of my audio input signal into the PIC comparators)...



    Now I'm sure there are more efficient ways of doing the above - but for now, it work s& I'm chuffed!

    The actual final phase calculation jitters about a bit (but I suspect that down to the somewhat jittery quality of my audio input signal into the PIC comparators!)...




    Listen guys - a great collaborative effort there - I can't thank you all enough....hopefully this gives a bit of closure to a long & painful saga!
    Last edited by HankMcSpank; - 30th September 2010 at 00:25.

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