PIC Input Capture

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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.

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


Re: PIC Input Capture
Quoted text here. Click to load it

I'm wondering the C compiler is somehow optimizing your code to:
last_fall = fall = CCP2;

You might want to check via disassembly.

Re: PIC Input Capture
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
....................       report_flag=1;
0080:  BSF    33.2
0081:  BCF    0D.0
0082:  BCF    0A.3
0083:  GOTO   02C

Quoted text here. Click to load it

Re: PIC Input Capture
The only thing left is that CCP_2 is returning the same value all (or most) of
the time. Does the C compiler insert code to clear the CCP2 interrupt flag? If
not, then you'd be getting an interrupt soone after returning from your
interrupt routine. Since CCP_2 probably hasn't changed in that time, last_fall
and fall would be the same value most of the time.

Re: PIC Input Capture
Forgot. You should also disable interrupts while calculating your pulse with
and pulse interval since the values you are using can change at any time if you
don't. If you don't, you'd still get weird values. Say  this happens:

MOVF    low(fall),w
<CCP2 int happens here>
SUBWF  low(last_fall),w

You'd get an interval of 0 once more.

Re: PIC Input Capture
Thanks for your help, I'm getting better results by dis/ena interupts, but
how do I reset the Timer1 value, so that I can get more consistent
(synchronous) results?

Quoted text here. Click to load it
if you

Re: PIC Input Capture
Quoted text here. Click to load it

Hmm. You can't just set Timer1 to 0 just before the end of your CCP2 interrupt
service routine??

Site Timeline