Interface for infrared remote control (18F PIC)

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
I have added infrared receiver from old television to my 18F TFT LCD board.
Particulary it could be useful to enter for instance address for memory copy.

It works so far, if I press button on the remote control, the LED blinks. This is done in hardware not via PIC.

How can I implement interface in software (XC8, PIC 18f24j10)?

I have some idea, but I am stuck with this. Today I have added serial RAM (32K), and just now moved the blinking LED + programmed TIMER0 interrupt.

I plan to use TIMER0 interrupt every 167 usec.
Using a counter to count upto 3000, I get blinking LED 2 times a second or something like this.

Here is the protocol that is to be used, old PANASONIC format.
Indeed the remote control can be programmed with numbers to many different formats.

I appreciate any ideas how to implement this in software. Neither assembler or delay loops can be used.

Also I don't want double codes in a row, so I must take care for repeated codes that are sent. Only after a new start condition, the same code can become accepted again, and only if it has been processed.

I don't even know if the remote control will issue repeated start conditions in a row, or simply repeat the data. But this is important, I need to detect if the code is repeating, or the button was released even if only for a short while.
 

Attachments

ErnieM

Joined Apr 24, 2011
8,377
I did something like this a few years back "just because" (I had no application for it). The received code would be written to an alphanumeric LCD display. "How" I did the code is forgotten, but it isn't very difficult.

The 18f24j10 has 3 timers on board, I would set one up to give me a nice resolution for the bit rate you get. On either a 0->1 or a 1->0 transition the timer is read and then reset so you get a 'read' on the pulse length. (A interrupt on input change would work nice here if you want this to run in the background.) Then you need to make a state machine to process this data, begin with the two START pulses, then decode the data. A timer overflow may also be used to detect when the remote stops transmitting.

I had a nice digital scope handy when I did this so I could "see" what each button did and then hard code them into the code.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
yes this is about what I have in mind to transform into program code.

This is what I have now:

Rich (BB code):
void interrupt high_isr(void)
{

  //  if(SSP1IF==1);
   //   {
   // SSP1IF=0;
    //  }

      if(TMR0IF==1)
      {
          TMR0IF=0;
          tmr_led++;
          if(tmr_led==3000){tmr_led=0;
          if(v_status&c_status_led0)
          {
           v_status&=(0xff-c_status_led0);
           LB3=1;
          }else
          {
           v_status|=c_status_led0;
           LB3=0;
          }}
      }
Note the serial interrupt is not used, the flag is polled directly.
I want to use Timer0 and have programmed it to what I believe about 167uSec/each interrupt.

And the signal from IR receiver will also trigger interrupt. The receiver is supplied from 5V, and 2.2k + green LED should reduce this to 3V. But it's inverted, isn't it, even if the LED itself would light up non-inverted?

The LEDs is flashing up by random sometimes for very short moments, adding 1uF very close to the receiver somehow solved the problem.
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
I suspect that you don't want to be using the serial interrupt.
The way I'd do it:
Use a pin that can generate an interrupt on a rising edge.
Set the timer prescaler so it won't overflow (longer than the start period).
On a rising edge read the timer to determine if it's a 0 or 1 and reset the timer.
Also have a timer interrupt that will detect if transmission has stopped / been interrupted.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
OK I found some time + nerves today to work on this.

Here is what I wrote:

Rich (BB code):
void interrupt high_isr(void)
{

  //  if(SSP1IF==1);
   //   {
   // SSP1IF=0;
    //  }

    if(INT0IF&&(!INT0IE))
    {INT0IF=0;}

    if(INT0IF&&(INT0IE))
    {INT0IF=0;

    if(v_status&c_status_IR_start)
    {
        v_status|=c_status_IR_start2;
    }

    v_status|=c_status_IR_start;

          if(v_status&c_status_led0)
          {
           v_status&=(0xff-c_status_led0);
           LB3=1;
          }else
          {
           v_status|=c_status_led0;
           LB3=0;
          }
    }
    if(TMR0IF&&(!TMR0IE)){TMR0IF=0;}

      if(TMR0IF&&TMR0IE)
      {
          TMR0IF=0;

          if(v_status&c_status_IR_start)
          {
              if(!(v_status&c_status_IR_start2))
              {
              ir_start++;
              }
          }

          tmr_led++;
          if(tmr_led==3000){tmr_led=0;


          if(v_status&c_status_led0)
          {
           v_status&=(0xff-c_status_led0);
          // LB3=1;
          }else
          {
           v_status|=c_status_led0;
          // LB3=0;
          }}
      }
ir_start will increment to 41 (when I push the remote control button), if I calculate 16T * 425 uSec, and divide through 167uSec, this results in 40.7

Somehow I need to capture the time between interrupts, and store them in an array. I want to display values numerically on the LCD, to see if the start condition is repeated, or what repeats actually.

I know the code is not good, just barely got it working today.
 

Thread Starter

takao21203

Joined Apr 28, 2012
3,702
Here are some samples. It has something to do with this old Panasonic protocol, however, the inverted codes are absent, and the start condition is repeated.

Maybe my state machine is not really fully correct, however there is different combination for each remote control key.

Simply, when a second interrupt occurs, I store the timer int's that have elapsed. and reset the flags. Maybe it's out of phase or something.
 

Attachments

Top