Author Topic: IR Remote Decoding, sending IR with PIC microcontroller  (Read 531 times)

0 Members and 1 Guest are viewing this topic.

Offline vasonline

  • Contributor
  • Posts: 20
IR Remote Decoding, sending IR with PIC microcontroller
« on: November 28, 2018, 08:34:10 pm »
Hi,

I have captured the ON/OFF button from my Set Top Box (STB)
I would like automate it with my PIC 16F716 microcontroller.
Watched Dave's excellent video.

Saw that it is the NEC protocol.
https://techdocs.altium.com/display/FPGA/NEC+Infrared+Transmission+Protocol

I made the capture by creating this:
https://www.analysir.com/blog/2014/05/04/silver-bullet-oscilloscope-infrared-receiver/

Capture button from original remote went Ok.
Wrote the following PIC program (excuse my crude coding capabilities)

As far as I can tell I am outputting the expected signal?
It it correct? Since I have never done this before. I might have overlooked something?

Problem is, when testing, that it does not work. The STB (Set top box) does not respond to the command from
the PIC breadbord.
- Know things: IR led works.
- I checked it with camera and scope method.
I have attached as many pictures as possible.

I have calculated IR LED current to 100mA. I am driving it on/off with a BC548 connected to the MCU

I am kinda try to figure out if it's a software problem in the waveform or something in the hardware design.
The original IR remote LED is still a bit brighter.
My IR led is from a scrapped remote.


In the pictures:
- CH2 is the original remote waveform
- REF is my own PIC program transmitted.

I have attached the waveforms as a zip file.

Greetings and my thanks for reading and/or responding!

Code: [Select]
// *************************************************************************************************************************
// AAN/UIT Knop programmeren van de AnroidTV decoder.
// Microchip PIC 16F716.
// MPLAB IDE.
// Complier: Hi-Tech C.
//
// *************************************************************************************************************************

#include <htc.h>

__CONFIG (FOSC_HS & WDTE_OFF & BOREN_ON & BODENV_40 ); // Instellen PIC 16F716 Externe Oscillator. Kan ook met GUI -> Configure -> Configuration bits

#define _XTAL_FREQ 16000000 // 16MHz kristal op de PIC.Opgelet voor de snelheid van het kristal!: FOSC_HS! FOSC_LP
#define DrukKnop RA0 // Als de drukknop op RA0 ingedrukt is, de wachttijd overslaan. (debugging)


// Functies

void StartOp(void);
void Timer2Initialisatie(void);


// Variabelen

unsigned char RodeLedTeller;
unsigned char Aan_UitIndex;
unsigned char GridVorigeWaarde;
unsigned char LeesGrid;

// 'Aan/uit code'
const unsigned char Aan_Uit[215] = {
44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,
0,0,0,0,0,0,0,0,
44,0,44,0,44,0,44,0,44,0,44,0,44,0,44,0,44,
0,0,0,44,0,0,0,44,0,0,0,44,0,0,0,44,0,0,0,44,0,0,0,44,0,0,0,44,0,0,0,44,
0,44,0,0,0,44,0,44,0,0,0,44,0,0,0,44,0,44,0,44,0,44,0,0,0,44,0,44,
0,0,0,44,0,44,0,44,0,0,0,44,0,0,0,44,0,0,0,44,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,
44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,0,0,0,0,44
};


void main()
{

StartOp();
Timer2Initialisatie();
 
 
for (;;)
{

    // Hoofdlus komt hier.
 
if (Aan_UitIndex < 215) {
  CCPR1L =  Aan_Uit[Aan_UitIndex++]   ;  // Installeer de volgende bit uit de aan/uit code.
__delay_us(478
);

}
else {
// Aan_UitIndex=0; //Test: herhalen van de aan_uit code.
CCPR1L = 0;  //Stoppen met zenden indien de Index doorlopen.
RB2 = 0;
}


GridVorigeWaarde = LeesGrid;
LeesGrid = RB4; // Lees de huidige waarde van de netinvoer op RB4 (digitale puls) in.


if ( GridVorigeWaarde == LeesGrid) { // 1 en 1 of 0 en 0
//Wachten: niet herhalen van de aan_uit code.                                                                                                                                                                                                                                                 
}

else {
            RB2 = 1; 
Aan_UitIndex=0; //Herhalen van de aan_uit code.                                                                                                                                                                                                                                                 
}


}
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////


void StartOp(){
//    XX  XX  XX  RA4 RA3 RA2 RA1 RA0
TRISA=0b11111111; // declare porta als input  RA0-RA3
//    RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0
TRISB=0b00010000; // 0 = Output 1 = Input  RB4 Input, RB3 output: PWM AAN
GIE=1;     //Enable Global Interrupt
PEIE=1; //Enable Peripal Interrupts   The PIR registers contain the interrupt flags for the “peripheral” interrupt sources, which include: The ADC, UART, CCP, USB, TMR3, TMR2, TMR1, and TMR0 modules.
Aan_UitIndex=216;
RB2 = 0;


}



// Main Interrupt Service Routine (ISR)
void interrupt isr(void){

if (TMR2IF == 1) { // PWM.
//*** PWM ***
//----------------------------------------------------------------------------------------
TMR2IF = 0;          // Clear TMR2 interrupt flag  Om TMR2 interrupt vlag actief te zetten.
}

}




void Timer2Initialisatie(){

   // *** PWM ***

   PR2 = 104;                // PWM periode 38kHz
//
//

   CCP1CON = 0b00001100;     // '00------' unimplemented bits
                             // '--00----'   DC1B1:DC1B0 duty cycle 10 bit resolutie. De andere 8 bits sttan in ccprl
                             // '----1100' active hi PWM mode P1A B C en D actief.
   TMR2IF = 0;              // TMR2IF wissen, op nul zetten. Deze komt op 1 van zodra PR2 = TMR2. (één PWM puls)
   TMR2IE = 1;              // Timer2 interrupt aan.
   T2CON = 0b000010000;     // '0-------' unimplemented bit
                            // '-0000---' TOUTPS<3:0>, Postscaler 0000 = 1:1 / 0001 = 1:2 / 0010 = 1:3
                            // '-----1--' TMR2ON, turn Timer 2 on
                            // '------01' T2CKPS<1:0>, 0:0 = Prescaler 1:1 / 0:1 = Prescaler 1:4
   TMR2ON = 1;
   CCPR1L = 0;          // Duty Cycle

}






« Last Edit: November 28, 2018, 08:48:22 pm by vasonline »
 

Offline oPossum

  • Super Contributor
  • ***
  • Posts: 1076
  • Country: us
  • The other white meat.
Re: IR Remote Decoding, sending IR with PIC microcontroller
« Reply #1 on: November 28, 2018, 09:40:56 pm »
NEC codes usually send a repeat code at least three times, or in some cases send the whole code at least three times.

See first two waveforms here... http://compendiumarcana.com/irwidget/gallery/gallery.html
 
The following users thanked this post: cdev, vasonline

Offline vasonline

  • Contributor
  • Posts: 20
Re: IR Remote Decoding, sending IR with PIC microcontroller
« Reply #2 on: November 29, 2018, 07:03:17 pm »
Hi OPussuim,

Very good point!

I had a quick look today. And compared it to the original remote.
Long pressing the button, short pressing the button while comparing on my scope.
Then I found the problem: it had worked all the way....I decoded the wrong button from the original remote....
no wonder it did not work :)

No other changes needed on the HW or SW.

Fixed!
« Last Edit: November 29, 2018, 07:05:35 pm by vasonline »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf