Forums

PIC Input Capture

Started by DssSouth January 26, 2004
Below is the ISR for CCP2(fall edge), the input is also tied to CPP1(rise).
Only the CCP2 interrupt is enabled. I need to get Pulse Width and Pulse Rate
from this interupt, and I would use the following equations;

PW = fall(n)-rise(n);
PR = fall(n+1) - last_fall(n);

PW works, but I can't get PR to work, fall always seems to be equal to
last_fall, equating to zero.
I would also like to reset Timer1 to 0 after each interupt, how?

Any help with this code would be appreciated.

#int_ccp2
void isr_ccp2()
{
      last_fall = fall;
      rise = CCP_1;
      fall = CCP_2;
      report_flag=1;
}
            ______                                           ______
______|           |_____________________|            |___
            ^          ^                                         ^
^
          rise(n)    fall/last_fall(n)                  rise(n+1)
fall/last_fall(n+1)

TIA



> last_fall = fall; > rise = CCP_1; > fall = CCP_2; >
I'm wondering the C compiler is somehow optimizing your code to: last_fall = fall = CCP2; You might want to check via disassembly.
That was a good suggestion, but here is the asm.
1B/1C=CCP_2
54/55=fall
50/51=last_fall

....................       last_fall = fall;
0074:  MOVF   55,W
0075:  MOVWF  51
0076:  MOVF   54,W
0077:  MOVWF  50
....................       rise = CCP_1;
0078:  MOVF   16,W
0079:  MOVWF  4F
007A:  MOVF   15,W
007B:  MOVWF  4E
....................       fall = CCP_2;
007C:  MOVF   1C,W
007D:  MOVWF  55
007E:  MOVF   1B,W
007F:  MOVWF  54
....................       report_flag=1;
0080:  BSF    33.2
0081:  BCF    0D.0
0082:  BCF    0A.3
0083:  GOTO   02C


"Gary Kato" <garykato@aol.com> wrote in message
news:20040126232223.11447.00000783@mb-m05.aol.com...
> > last_fall = fall; > > rise = CCP_1; > > fall = CCP_2; > > > > I'm wondering the C compiler is somehow optimizing your code to: > last_fall = fall = CCP2; > > You might want to check via disassembly. >