This is the stripped down version of my C code (i removed a lot of stuff that I had commented out while testing). This version just printed out the value of CCP_1 to the PC on every falling edge of the IR receiver. Previously I had it printing out bit_time where: bit_time = CCP_1 + ( timer1_overflow * 65536 ) The problem is that it's only detecting 5 falling edges instead of the expected 14 bits & start/stop bits or even half of that. I am using Panasonic 4602 which demodulates 39kHz carrier. The datasheet says 400uS pulses (min 200, max 600). could it be that my (JVC) remote control is not using compatible pulse lengths or something? From the information I have, the JVC remotes use different lengts of low time to determine if it's a 1 or 0 with a low time of 550uS for Zero and 1600uS for One with the high pulses being always 600uS. The start bit is high for 9.5mS and low for 4mS and the stop bit is 600uS. Anyway, here is the code. I just noticed that this code can essentially be the base for a generic frequency counter type project, SWEET! ------------------ START CODE ------------------------- #include <16f628.h> #fuses INTRC_IO,NOWDT,NOBROWNOUT,NOLVP #use delay(clock=4000000) #define tx PIN_B2 #define rx PIN_B1 #use rs232(baud=9600, xmit=tx, rcv=rx) //***************************************************************** // GLOBAL VARIABLES static int32 timer1_overflow; // Counts timer1 overflow static int32 bit_time; // Hold bit low time //***************************************************************** // INTERRUPT SERVICE ROUTINES #INT_CCP1 void ccp_isr ( void ) { printf("CCP_1: %lu\n\r",CCP_1); timer1_overflow = 0; // Reset timer1 overflow counter set_timer1(0); // Reset timer1 counter } #INT_TIMER1 void timer1_isr(void) { // Called on Timer1 Overflow timer1_overflow = timer1_overflow + 1; // Count Timer 1 Resets } //***************************************************************** // MAIN PROGRAM CODE void main ( void ) { delay_ms (200); // Allow PIC to stabilize printf("\n\rInitializing..."); // Initialization Started Message timer1_overflow = 0; // Initialize timer1 overflow to 0 bit_time = 0; // Initialize bit time counter to 0 setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_1 ); // Setup timer 1 to increment every 1uS setup_ccp1 ( CCP_CAPTURE_FE ); // Setup CCP to interrupt on Falling Edge enable_interrupts ( GLOBAL ); // Enable interrupts globally enable_interrupts ( INT_CCP1 ); // Enable CCP1 interrupt enable_interrupts ( INT_TIMER1 ); // Enable TIMER 1 overflow interrupt printf("Done\n\r"); // Initialization Completed Message while(TRUE){ } // Loop waiting for interrupts } ------------------ END CODE ------------------------- Also, does anyone know what protocol the Sony Playstation2 DVD remote control uses, is it the standard Sony protocol? This is about the only other remote control I have, would it be a better candidate for testing this? Thanks ahead of time for any info, much appreaciated! MJ Brush ----- Original Message ----- From: "Colombain Nicolas" To: Sent: Monday, May 31, 2004 7:16 AM Subject: Re: [PIC:] Counting IR pulses from Remote Control > Hi Matthew, > > > Am I correct in thinking that my Timer 1 will increment once every > microsecond? and then overflow every 65536 microseconds. > yes. The Timer clock (if set to internal one) will be OSC/4 > > > So then to see how long is in between each pulse, I am taking my CCP_1 + > (Timer1 Overflow * 65536) > Pulse width (in us) is: current CCP1 value - old CCP1 value if no overflow > occurs (current CCP1 > old CCP1 ) on timer 1 > > Are you using an RC5 transmitter/ receiver(removing the 38KHz) ? > I would be helpfull to send your program source if it is not too long.... > Regards, > > Nicolas > > > I have a simple PIC question. I'm running a PIC16F628A with the Internal > oscillator (ie. 4MHz). > > What I'm trying to do is decode my remote control. For right now, I just > have Timer1 setup with DIV_BY_1 and my CCP is set to capture on falling > >edge (inverted output from IR receiver). > > Am I correct in thinking that my Timer 1 will increment once every > microsecond? and then overflow every 65536 microseconds? > > I'm a little confused about the clock terminology. My instruction clock > is Osc./4 ? That's where I'm getting my 1uS per Timer1 increment. > > Then I count how many times Timer1 reset itself. > > So then to see how long is in between each pulse, I am taking my > > CCP_1 + (Timer1 Overflow * 65536) > > Not sure if this is the right way to do this, but any comments or > suggestions welcome. Right now I am just trying to see the width of the > pulses and >whatnot, but the results I'm getting are odd. The big thing > that makes me think something is wrong, is that I am only getting 5 pulses > per button press as >opposed to the 14-16 I was expecting. > >Could it be the fact that I'm sending RS232 data in the middle of the CCP > interrupt service routine? I just figured since the PIC I am using has > hardware >USART thing that it wouldn't interfere with my other stuff. > >Thanks ahead of time for any help/info anyone can provide, I've done quite > a bit of searching on the net, but I haven't found anything to help me too > much >other than the common IR protocols. > >P.S. If it makes any difference, I am using a C compiler. Also, I'm sorry > if I didn't explain myself better, it's really early :) > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads