Help configuring 2 CCP interupts


Results 1 to 12 of 12

Threaded View

  1. #5
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default Re: Help configuring 2 CCP interupts

    The define at the beginning of the code, I think. I actually missed it on the first post as I tried multiple combinations. I have one set as priority and the other not since it won't let me use the same define twice. I did not write the assembly routine. I did find a couple of errors and switched to timer1, but still can't get CCP2 to capture anything...

    Code:
    'PIC18F4620 CCP1 & CCP2 test
    
    OSCCON=%01110000            ' SET TO 8 MHZ internal oscillator
    DEFINE OSC 08               ' 8MHZ clock speed 
    DEFINE INTHAND CCP_INT      ' Declare high-pri interrupt handler
    DEFINE INTLHAND CCP2_INT    ' Declare interrupt handler
    ADCON1 = 15                 ' All digital 
    CMCON  = 7                  ' Turns off comparators 
    
    define LCD_COMMANDUS 1500   ' set command delay in us
    define LCD_DATAUS 50        ' set data delay in us
    define LCD_DREG PORTD       ' set LCD data port
    define LCD_DBIT 4           ' set LCD starting data bit
    define LCD_RSREG PORTD      ' define RS port
    define LCD_RSBIT 2          ' define RS bit
    define LCD_EREG PORTD       ' set LCD ENABLE port
    define LCD_EBIT 3           ' set LCD ENABLE bit
    define LCD_BITS 4           ' set LCD bits 4 or 8
    define LCD_LINES 2          ' set # of LCD rows 2 or 4            
    
    '*******************************************************************************
    '************************** V A R S  /  C O N S ********************************
    '*******************************************************************************
    'CCP1 INTERRUPT
    Symbol Capture   = PIR1.2      ' CCP1 capture flag
    SYMBOL CapIE     = PIE1.2      ' CCP1 interrupt enable bit
    SYMBOL CapPriEn  = IPR1.2      ' priority enable bit for CCP1 interrupt
    SYMBOL PriEnable = RCON.7      ' set to enable priority levels on interrupts  
    _T1             VAR WORD BANKA SYSTEM  ' 1st capture value
    PW              VAR WORD BANKA SYSTEM  ' 2nd capture value & ultimately final pulse width
    CF              VAR BYTE BANKA SYSTEM  ' indicates when last capture is ready
    Period          var word
    'CCP2 INTERRUPT
    Symbol Capture2   = PIR2.2      ' CCP2 capture flag
    SYMBOL CapIE2     = PIE2.2      ' CCP2 interrupt enable bit
    SYMBOL CapPriEn2  = IPR2.2      ' priority enable bit for CCP2 interrupt
    SYMBOL PriEnable2 = RCON.7      ' set to enable priority levels on interrupts  
    _T2             VAR WORD BANKA SYSTEM  ' 1st capture value
    PW2             VAR WORD BANKA SYSTEM  ' 2nd capture value & ultimately final pulse width
    CF2             VAR BYTE BANKA SYSTEM  ' indicates when last capture is ready
    Period2         var word
    
    'CONFIGURE DISPLAY 
    pause 100
    ln1 con $80
    ln2 con $C0
    CS  con 1
    pause 500
    LCDOUT $FE,CS
    
    CLEAR                  ' clear RAM on POR
    TRISC.2 = 1            ' CCP1 input pin (Capture1 input on 18F4620)
    TRISC.1 = 1            ' CCP2 input pin (Capture2 input on 18F4620)
    INTCON  = 0            ' Interrupts off for now
    
    pause 1000             'add bootup delay to allow things to settle
    GOTO start             'jump over interrupt handler
    
    ASM
    CCP_INT
      BTFSS CCP1CON,0       ; capture from rising edge?
      BRA Fall              ; no .. goto falling edge
      MOVFF CCPR1L, _T1     ; get low capture byte into _T1
      MOVFF CCPR1H, _T1+1   ; get high capture byte into _T1
      BRA IntExit           ; outta here
    Fall
      MOVFF CCPR1L, PW      ; get low capture byte into PW
      MOVFF CCPR1H, PW+1    ; get high capture byte into PW
      BSF CF,0              ; indicate last capture
    IntExit
      BTG CCP1CON,0         ; toggle between rising/falling edge captures
      BCF PIR1,2            ; clear capture interrupt flag bit
      RETFIE FAST           ; return/restore W, STATUS and BSR
    ENDASM
    
    ASM
    CCP2_INT
      BTFSS CCP2CON,0       ; capture from rising edge?
      BRA Fall2             ; no .. goto falling edge
      MOVFF CCPR2L, _T2     ; get low capture byte into _T1
      MOVFF CCPR2H, _T2+1   ; get high capture byte into _T1
      BRA IntExit2          ; outta here
    Fall2
      MOVFF CCPR2L, PW2     ; get low capture byte into PW
      MOVFF CCPR2H, PW2+1   ; get high capture byte into PW
      BSF CF2,0             ; indicate last capture
    IntExit2
      BTG CCP2CON,0         ; toggle between rising/falling edge captures
      BCF PIR2,2            ; clear capture interrupt flag bit
      RETFIE FAST           ; return/restore W, STATUS and BSR
    ENDASM
    
    start: 
    '******************** CCP1 / CCP2 / Timer 1 ********************
    CCP1CON = %00000111    'Capture mode, capture on 16th rising edge
    CCP2CON = %00000111    'Capture mode, capture on 16th rising edge
    T1CON.7=1              'Enable timer  16 bit `   
    T1CON.6=1              'Timer1 OSC
    T1CON.5=1              '1:8 prescaler   
    T1CON.4=1              '1:8 prescaler   
    T1CON.3=0              'Timer1 OSC off
    T1CON.2=0              'sychro clock
    T1CON.1=0              'Internal clock
    TMR1H = 0              'Clear high byte of TMR1 counter
    TMR1L = 0              'Clear low byte
    PriEnable = 1          'Enable priority levels on interrupts
    Capture = 0            'Clear capture flag bit
    Capture2 = 0           'Clear capture flag bit
    CapPriEn = 1           'Set CCP1 int to high priority
    CapPriEn2 = 1          'Set CCP2 int to high priority
    CapIE = 1              'Enable the CCP1 capture interrupt
    CapIE2 = 1             'Enable the CCP2 capture interrupt
    
    INTCON = %11000000     'Global + peripheral ints enabled
    T1CON.0 = 1            'Turn TMR1 on here
    
    main:
        IF CF.0 THEN         ' figure out & print result only after last capture
          period = PW-_T1  
          CF.0 = 0           ' clear flag bit
       ENDIF
           
        IF CF2.0 THEN         ' figure out & print result only after last capture
          period2 = PW2-_T2  
          CF2.0 = 0           ' clear flag bit
      ENDIF
      
    lcdout $fe, ln1, "#1 = ", dec period, "            "
    lcdout $fe, ln2, "#2 = ", dec period2, "            "
      
    goto main
    
    end
    Last edited by spcw1234; - 7th February 2015 at 21:45.
    Shawn

Similar Threads

  1. Help with configuring
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 17th August 2014, 01:08
  2. Question regarding CCP
    By spcw1234 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th April 2013, 09:55
  3. Configuring 16F616
    By Tobias in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th February 2009, 16:28
  4. CCP Module How to ?
    By capitano in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th February 2005, 08:08
  5. need help configuring 16F628
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd March 2004, 18:59

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