That's a great start Ken!
INT_ENABLE is a Darrel Taylor command for his DT_INTS. This is the same as enabling, or disabling a certain interrupt. To set up CCP interrupts, you first add a line like my code had:
Then enable it:Code:INT_Handler CCP1_INT, PWMeasure, ASM, yes
@ INT_ENABLE CCP1_INT
But you will also have to configure it. Make portc.2 an input. And configure your CCP1
CCP1CON = %00000101 ;capture every rising edge
Now I used Chuck's code to do the capture. It needs the sub16.inc include file to be included, and we will need some variables like
Code:risetime var word ;used for pulse width measure start of pw falltime var word ;time at end of pulse width falltime_l var falltime.byte0 falltime_h var falltime.byte1 risetime_l var risetime.byte0 risetime_h var risetime.byte1Now, if you read the data sheet, you see in 11.1 Table 11-1 that capture mode uses timer1. So you will have to set this. Looks like it may be same settings as I have in T1CON. This will also start the timer. It runs continuously, and we don't care about interrupts on T1. We just want to read the timer at interrupt high edge of CCP1, and read timer on low edge of pulse. Then we should have a value present at falltime, representing the length of the pulse.Code:asm PWMeasure BTFSS CCP1CON, CCP1M0 ; Check for falling edge watch GOTO FALL_EDGE ; Go pick up the falling edge MOVF CCPR1L,W ; else store leading edge value MOVWF _risetime_l ; into 16 bit word risetime MOVF CCPR1H,W MOVWF _risetime_h BCF CCP1CON, CCP1M0 ; Now capture the trailing edge GOTO ISR_2 ; Exit the interrupt service routine FALL_EDGE: BSF CCP1CON, CCP1M0 ; Re-set for trailing edge capture MOVF CCPR1L,W ; Store the captured value into MOVWF _falltime_l ; falltime_l and ... MOVF CCPR1H,W MOVWF _falltime_h ; ... falltime_h ; ; 16 bit subtract ; falltime = falltime - risetime ; SUB16 _falltime, _risetime ISR_2 INT_RETURN endasm





Bookmarks