I'm using a 16F88 to measure and accumulate quite variable length positive pulses with high precision. This means I need more than the standard 16 bit resolution of the CCP1 peripheral, so I am trying to extend it by counting Timer 1 overflows by monitoring TMR1IF while making sure I only count the ones that happen during the positive pulse. If I am within the pulse and there is no CCP1IF I always count the overflow. But if I have both TMR1IF and CCP1IF I need to figure out whether the capture occurred before or after the Timer 1 overflow. I'm doing that by comparing CCPR1H and TMR1H. This is all happening in the interrupt routine. I am not using the Timer 1 interrupt, just using the flag. My interrupts are a fast (PR2 = 250) Timer 2 interrupt and the CCP1 interrupt. Fortunately none of my pulses or idle times are shorter than a several TMR2 interrupts. This may or may not be the right way to do it, my code seems very pedantic. I am including the important variable declarations and part of the interrupt. It works and does fit fine, and in fact I have sped it up in the real code, because things like "pulse_isr = -(unsigned long)CCP1;" are not efficient after a compiler has at it. But I wanted to show it in as few lines as possible. So you don't need to criticize my use of longs and C (although I won't mind), it's really the basic idea that some brilliant programmer could say "duh, do it all in 12 instructions like this". So here it is, let me know what you think. I used Hi-Tech PICC. Thanks, Bob global declarations: static volatile unsigned int CCP1 @0x15; // CCPR1L,CCPR1H static volatile unsigned long pulse_accum; // multipulse total static unsigned long pulse_isr; // holds one pulse static volatile unsigned char pulse_count; // how many pulses static volatile bit f_pulse_fall; // pulse complete isr snippet: if (TMR1IF) { // a timer 1 rollover? if (!(CCP1CON&1)) { // waiting for fall if (!CCP1IF) { // no falling edge yet TMR1IF = 0; // clear flag because we'll add pulse_isr += 0x10000; // overflow value } } } if (CCP1CON & 1) { // if trigger set to rising edge TMR1IF = 0; // don't care about prior overflows if (CCP1IF){ // got a rising edge if (CCPR1H > TMR1H) // timer 1 rollover after CCP1? TMR1IF = 1; // it will get counted next ISR pulse_isr = -(unsigned long)CCP1; // subtract start time CCP1CON &= ~1; // set ccp1 to falling edge trigger CCP1IF = 0; // ready for next interrupt } } else { // triggering on falling edge if (CCP1IF) { // got falling edge, pulse over if (TMR1IF) { // a rollover, does it count? if (TMR1H >= CCPR1H) // rollover was before capture pulse_isr += 0x10000; // add it in } pulse_isr += CCP1; // add final time CCP1CON |= 1; // now look for rising edges CCP1IF = 0; // ready for next interrupt pulse_accum += pulse_isr; // add new pulse to total pulse_count++; // log this completed pulse f_pulse_fall = 1; // flag to main } } That's it. -- http://www.fastmail.fm - The professional email service -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist