Hello Hasan, I think I have found the problem. The CCP module in capture mode uses timer1 as a resource. You haven't properly configured timer1, though you are turning it on and off. In the 16F628 datasheet read up on timer1 and its control register T1CON. You need to select a prescaler value, clock source, and there are a few other bits to check. The bit in T1CON you overlooked is called T1OSCEN. This enables or shuts-off the oscillator for the timer. I also have a comment about the code: In the detectFor65ms() function I think you should order some of the statements differently. Here is a part of that function's body: TMR1ON = 0; CCP1CON = 0x05; TMR1IE = 1; CCP1IE = 1; PEIE = 1; GIE = 1; timeout = 0; detected = 0; TMR1ON = 1; #if defined DEBUG TMR1L = 0xe0; TMR1H = 0xff; #endif TRISB = 0b00001000; I think you should initialize everything _before_ enabling the interrupts. As it stands now, it is possible for a capture interrupt to occur before the variables timeout and detected are set to zero! That means you could miss your compare event. I would organize the above code like this: TMR1ON = 0; CCP1CON = 0x05; TRISB = 0b00001000; #if defined DEBUG TMR1L = 0xe0; TMR1H = 0xff; #endif timeout = 0; detected = 0; TMR1IE = 1; CCP1IE = 1; PEIE = 1; GIE = 1; TMR1ON = 1; When I encounter a problem like this I do two things (in this order). One, read the datasheet throughly; be absolutely certain you understand everything about the module you are using. Second, re-write the code, in as simple a manner as possible, to do only thing you're having trouble with (in your case, get rid of the timeout stuff and concentrate on the CCP module). I hope this helps you. There may be someother problems with your code that I've not found; I've never used the CCP module before. Good luck, Matthew. -- Memory is like an orgasm. Its a lot better if you dont have to fake it. -- Seymour Cray, commenting on virtual memory -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist