Measuring audio phase shift through a circuit with a PIC


Results 1 to 40 of 50

Threaded View

  1. #24
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    Hi Hank

    Since you're stuck, I wonder if you could post/PM your code of now so that I can take a whack at it. I'll see if I can find your problem with the min value of comp2 value.

    The barest minimum code which will compile and show the problem is sufficient. I should be able to run it.

    Regards
    Many thanks Jerson.

    The latest version of code was part of a hulking long program, but I found an earlier variant, which is purely deals with the comparator interrupt timer1 counting & therefore makes it a lot easier to look at...

    Code:
    @ __CONFIG _FCMEN_OFF & _HS_OSC & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOR_OFF & _PWRTE_OFF
    
    DEFINE  OSC 20          ' set Oscillator at 20Mhz.
    DEFINE  NO_CLRWDT 1   ' PBP doesn't clear WDT automatically
    DEFINE HSER_TXSTA 24h ' Enable transmit
    DEFINE HSER_SPBRG 129 ' set USART to 9600 baud  @20Mhz
    
    '*********************************************************************************
    '16F690 Pin Connections....
    ' PIN# NAME     USE & CONNECTION
                    '  1   Vdd      +5VDC power supply
    TRISC.4 = 0     '  6   RC4      C2OUT
    TRISC.3 = 1     '  7   RC3      C12IN3- (comparator1 input)
    TRISC.2 = 1     '  14  RC2      C12IN2- (comparator2 input)
    TRISA.2 = 0     '  17  RA2      C1OUT
                    '  20  Vss      Ground
    '*********************************************************************************
    OSCCON.0 = %0001000 
    txsta = %10100100   'setup the tx register
    RCSTA.7 = 1         ' Enable RB7 for TX USART
    INTCON.0 = 0        ' clears the RABIF Flag (to 0), COULD be 1 on reset (unique to F690)
    ANSEL      = 0      'disable AtoD.
    ANSELH     = 0      'disable AtoD.
    
    'Turn on & Set up Comparator 1
    CM1CON0.7 = 1       'Comparator 1 on.
    CM1CON0.6 = 0       'C1OUT POLARITY BIT
    CM1CON0.5 = 1       '1 = C1OUT is present on the C1OUT pin (pin 17)
    CM1CON0.4 = 1       'C1OUT logic - 0 is not inverted  (1 for inverted)
    CM1CON0.3 = 0       'unimplemented
    CM1CON0.2 = 1       'Connect internally to the output of C1VREF   (or 0 for the the associated comp 'in' ext pin)
    CM1CON0.1 = 1       'this bit with bit 1 set the external incoming pin - in this case c12in3- (pin 7)
    CM1CON0.0 = 1       'this bit with bit 1 set the external incoming pin - in this case c12in3- (pin 7)
    
    'Turn on & Set up Comparator 2
    CM2CON0.7 = 1       'Comparator 2 on.
    CM2CON0.6 = 0       'C1OUT POLARITY BIT
    CM2CON0.5 = 1       '1 = C2OUT is present on the C2OUT pin (pin 6)
    CM2CON0.4 = 1       'C1OUT logic is not inverted  (1 for inverted)
    CM2CON0.3 = 0       'unimplemented
    CM2CON0.2 = 1       'Connect internally to the output of C1VREF (or 0 for the the associated comp 'in' ext pin)
    CM2CON0.1 = 1       'this bit with bit 1 set the external incoming pin - in this case c12in2- (pin 14)
    CM2CON0.0 = 0       'this bit with bit 1 set the external incoming pin - in this case c12in2- (pin 14)
    
    ' Setup the internal VREF
    VRCON.7 = 1         'Comparator1 CV Ref enable bit
    VRCON.6 = 1         'Comparator2 CV Ref enable bit 
    VRCON.5 = 0         'high or low range  0 = High Range, 1 = low range
    VRCON.4 = 0         '0.6V Reference Enable bit   ....0 is disabled
    VRCON.3 = 0         'these 4 bits set the divider of the VREF ladder 16 values - 7 should yield 1/2 VCC
    VRCON.2 = 1         'these 4 bits set the divider of the VREF ladder 16 values - 7 should yield 1/2 VCC
    VRCON.1 = 1         'these 4 bits set the divider of the VREF ladder 16 values - 7 should yield 1/2 VCC
    VRCON.0 = 1         'these 4 bits set the divider of the VREF ladder 16 values - 7 should yield 1/2 VCC
    
    
    Comp1Time       var  word    ' used to amalgamate TMR1 High & Low Bytes.
    Comp2Time       var  word
    
          
    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
            INT_Handler   CMP2_INT,  _Comp2_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
    @ INT_ENABLE  CMP2_INT     ; enable Comparator 2 interrupts
    
    'Main body of Code****************************************************************
    Main:
            HSEROUT ["comp1=",dec Comp1Time,9,"comp2Time=", dec comp2time, 13, 10]
            PAUSE 80
            goto Main
            end       
    
    'Comparator1 Interrupt Handler++++++++++++++++++++++++++++++++++++++++++++++++++++ 
    Comp1_Int:
            Comp1Time.Lowbyte = TMR1L       'Store timer1 Low into a variable  
            Comp1Time.Highbyte = TMR1H      'Store timer1 high into a variable.
            TMR1H = 0                                   'Set the high part of the timer value to 0
            TMR1L = 0                                    'Set the low part of the timer value to 0
    
    @ INT_RETURN
    
    
    'Comparator2 Interrupt Handler++++++++++++++++++++++++++++++++++++++++++++++++++++ 
    Comp2_Int:
            Comp2Time.Lowbyte = TMR1L       'Store timer1 Low into a variable 
            Comp2Time.Highbyte = TMR1H      'Store timer1 high into a variable.
            TMR1H = 0                                  'Set the high part of the timer value to 0
            TMR1L = 0                                   'Set the low part of the timer value to 0
            
    @ INT_RETURN
    Last edited by HankMcSpank; - 29th September 2010 at 08:21.

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