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.
last_fall = fall;
rise = CCP_1;
fall = CCP_2;
______| |_____________________| |___
^ ^ ^
rise(n) fall/last_fall(n) rise(n+1)
I'm wondering the C compiler is somehow optimizing your code to:
last_fall = fall = CCP2;
You might want to check via disassembly.
Reply by DssSouth●January 27, 20042004-01-27
That was a good suggestion, but here is the asm.
.................... 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
0080: BSF 33.2
0081: BCF 0D.0
0082: BCF 0A.3
0083: GOTO 02C
"Gary Kato" <email@example.com> wrote in message
> > 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.