manejo IR

download manejo IR

of 30

Transcript of manejo IR

  • 8/9/2019 manejo IR

    1/30

    Da 3: receptor/emisor IR

    Los l ed infrarrojos s e caracterizan por emitir radiacin electromagntica, invisible al ojo humano, ya que su

    longitud d e o nda e s m ayor a l a d el espectro v isible.

    Para comprobar si un led IR funciona p odemos m irarlo a t ravs de la c mara d e n uestro m vil, ya q ue

    este tipo d e c maras si que detectan rad iacin infrarroja.

    http://www.davidmiguel.com/arduino/wp-content/uploads/2013/03/arduinopna4602.gifhttp://www.davidmiguel.com/arduino/wp-content/uploads/2013/03/arduinopna4602.gif
  • 8/9/2019 manejo IR

    2/30

    Los r eceptores de infrarrojos son u nos p equeos integrados que p oseen u na foto-clula q ue detecta

    emisiones infrarrojas. En e l siguiente d iagrama de bloques p odemos ver su funcionamiento:

    PIN: sensor de infrarrojos (foto-diodo), convierte la seal luminosa incidente en seal elctrica. AGC (control automtico de ganancia): proporciona una seal de salida constante. Si la seal de

    entrada e s pe quea, aumenta la g anancia y vi ceversa. Band Pass (ltro paso banda): ltra las f recuencias n o deseadas (E j: luz v isible). Demodulator (demodulador): r ecupera la informacin transportada p or la o nda p ortadora. Botn transistor: invierte la seal. Si del demodulador sale un 1, la salida se conecta a masa. Por

    lo tanto, si no recibimos n ada, la s alida va a ser 5V.

    *Para q ue el receptor se co mporte b ien, el led IR que u semos tiene q ue tener l a longitud de onda a la c ual

    es m s sen sible e l sensor. La ms com n es 94 0nm. Podemos en contrar estos da tos en el datasheet de

    los com ponentes.

  • 8/9/2019 manejo IR

    3/30

    Existen multitud de dispositivos que utilizan tecnologa infrarroja para control remoto, por ej emplo los

    mandos d e las televisiones. Su funcionamiento se basa en la emisin de secuencias de pulsos de luz IR

    que t ransportan u n c digo d e N bits q ue identica la t ecla p ulsada.

    Existen muchos p rotocolos de comunicacin infrarroja, nos va mos a c entrar en el protocolo NEC , que e s

    el que u san los m andos un iversales.

    El protocolo N EC utiliza pulsos d istancia para l a t ransmisin de u n m ensaje. Este p rotocolo funciona a una

    frecuencia de 38kHz, es decir, los pulsos d uran 562.5 s. El mensaje se transmite de la siguiente forma: 0 lgico : Enva u n pulso d e 5 62,5 s, seguido de un espacio de 5 62,5 s de duracin (tiempo

    de transmisin de 1,125 ms) 1 lgico: Enva un pulso de 562,5 s segu ido de u n e spacio de 1 .6875 m s de duracin (tiempo

    de transmisin de 2 ,25 ms)

    Cuando pulsamos un botn de un mando, se en va la si guiente cad ena d e p ulsos:

    1. Una rfaga de pulsos de 9 ms.

    2. Un espacio 4,5 ms

    3. La direccin para e l dispositivo receptor (8 bits)

    4. El inverso l gico d e la d ireccin (8 b its) (para comprobar errores)

    5. El comando (8 bits)6. El inverso lgico del comando (8 bits)

    7. Un pulso de 5 62.5 s para indicar el nal de la transmisin del mensaje.

    A continuacin se i lustra co n una imagen para u na direccin 00000000 y u n co mando 1 0110101:

    http://wiki.altium.com/display/ADOH/NEC+Infrared+Transmission+Protocolhttp://wiki.altium.com/display/ADOH/NEC+Infrared+Transmission+Protocol
  • 8/9/2019 manejo IR

    4/30

    Vamos a empezar con una prctica sencilla que nos va a permitir comprobar el correcto funcionamiento

    de n uestro rece ptor. Realizamos e l siguiente m ontaje:

    Como hemos m encionado a ntes, si no mandamos n ingn pulso a l receptor, la sa lida de este tendra q ue

    dar 5V. Sin e mbargo, si apretamos u n b otn de un mando a d istancia, el led debera p arpadear por unos

    instantes, ya que cuando recibe un pulso, la salida se pone a 0V. Si ocurre esto, nuestro receptor funcionacorrectamente.

    El siguiente c digo nos pe rmite registrar la su cesin de pulsos que m anda un mando cuando p ulsas u n

    botn. Adems t e p repara e l cdigo para q ue lo puedas implementar, como ver emos a continuacin. No

    vamos a explicar este cdigo , ya que es b astante complejo, nos l imitaremos a utilizarlo.

    1

    2

    3

    45

    6

    7

    8

    9

    10

    11

    12

    13

    14

    1516

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    /* Raw IR decoder sketch!This sketch/program uses the Arduno and a PNA4602 todecode IR recei ed This can "e used to make a IR recei er#"$ %ooking &or a particu%ar code'or transmitter #"$ pu%sing an IR () at +,-. &or thedurations detected1ode is pu"%ic domain check out www %ad$ada net and ada&ruit com&or more tutoria%s!*/

    // 3e need to use the raw pin reading methods// "ecause timing is er$ important here and the digita%Read#'// procedure is s%ower!//uint-5t IRpin 27// igita% pin 82 is the same as Pin 2 see// http9//arduino cc/en/ acking/Pin:apping;6- &or the raw pin mapping8de&ine IRpin5PIN PIN8de&ine IRpin 2

    // the ma mi%%iseconds is a %ong time8de&ine :A?P@( ) 6>000

    // what our timing reso%ution shou%d "e %arger is "etter// as its more precise = "ut too %arge and $ou wont get// accurate timing8de&ine R) B(@TIBN 20

    // we wi%% store up to ;00 pu%se pairs #this is =a %ot='uint;65t pu%sesC;00DC2D7 // pair is high and %ow pu%se

    uint-5t currentpu%se 07 // inde< &or pu%ses we re storing

    https://github.com/adafruit/Raw-IR-decoder-for-Arduinohttps://github.com/adafruit/Raw-IR-decoder-for-Arduinohttp://arduino.cc/en/Hacking/PinMapping168https://github.com/adafruit/Raw-IR-decoder-for-Arduinohttp://arduino.cc/en/Hacking/PinMapping168
  • 8/9/2019 manejo IR

    5/30

    28

    29

    30

    31

    32

    3334

    35

    36

    37

    38

    39

    40

    41

    42

    43

    4445

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    65

    66

    67

    68

    69

    70

    71

    72

    73

    74

    75

    7677

    oid setup# oid' E eria% "egin#F600'7 eria% print%n#GRead$ to decode IR!G'7H

    oid %oop# oid' E

    uint;65t highpu%se %owpu%se7 // temporar$ storage timing highpu%se %owpu%se 07 // start out with no pu%se %ength

    // whi%e #digita%Read#IRpin'' E // this is too s%ow! whi%e #IRpin5PIN #; JJ IRpin'' E // pin is sti%% IK

    // count o&& another &ew microseconds highpu%seLL7 de%a$:icroseconds#R) B(@TIBN'7

    // I& the pu%se is too %ong we timed out = either nothing // was recei ed or the code is &inished so print what // we e gra""ed so &ar and then reset i& ##highpu%se M :A?P@( )' #currentpu%se ! 0'' E printpu%ses#'7 currentpu%se 07 return7 H H // we didn t time out so %ets stash the reading pu%sesCcurrentpu%seDC0D highpu%se7

    // same as a"o e whi%e #! #IRpin5PIN 5 O#IRpin''' E

    // pin is sti%% (B3 %owpu%seLL7 de%a$:icroseconds#R) B(@TIBN'7 i& ##%owpu%se M :A?P@( )' #currentpu%se ! 0'' E printpu%ses#'7 currentpu%se 07 return7 H H pu%sesCcurrentpu%seDC;D %owpu%se7

    // we read one high=%ow pu%se success&u%%$ continue! currentpu%seLL7

    H oid printpu%ses# oid' E eria% print%n#G n r n rRecei ed9 n rBQQ tBNG'7 &or #uint-5t i 07 i J currentpu%se7 iLL' E eria% print#pu%sesCiDC0D * R) B(@TIBN )1'7 eria% print#G usec G'7 eria% print#pu%sesCiDC;D * R) B(@TIBN )1'7 eria% print%n#G usecG'7 H

    // print it in a arra$ &ormat eria% print%n#Gint IRsigna%CD EG'7 eria% print%n#G// BN BQQ G'7 &or #uint-5t i 07 i J currentpu%se=;7 iLL' E

  • 8/9/2019 manejo IR

    6/30

    78

    79

    80

    81

    82

    8384

    85

    86

    87

    88

    89

    90

    91

    92

    93

    9495

    96

    97

    98

    99

    100

    101

    102

    103

    104

    105

    106

    107

    // eria% print#G tG'7 // ta" eria% print#Gpu%seIR#G'7 eria% print#pu%sesCiDC;D * R) B(@TIBN )1'7 eria% print#G'7G'7 eria% print%n#GG'7 // eria% print#G tG'7 eria% print#Gde%a$:icroseconds#G'7 eria% print#pu%sesCiL;DC0D * R) B(@TIBN )1'7 eria% print%n#G'7G'7

    H // eria% print#G tG'7 // ta" eria% print#Gpu%seIR#G'7 eria% print#pu%sesCcurrentpu%se=;DC;D * R) B(@TIBN )1'7 eria% print#G'7G'7

    H

    Si cargamos el cdigo en nuestro Arduino y a brimos la consola, nos d ir que est listo para decodicar IR.

    Entonces t enemos q ue pulsar el botn que d eseamos y n os a parecer la relacin de tiempos de los

    diferentes pulsos y a dems nos l os preparar para poder implementarlo en nuestro p rograma.

  • 8/9/2019 manejo IR

    7/30

    Ahora q ue tenemos la se cuencia d e p ulsos qu e e mite e l mando al pulsar un botn determinado, podemos

    reproducir ese botn gracias a A rduino y a un led IR. Este s e c onecta como un led normal:

    Vamos a reutilizar parte del cdigo que utilizamos p ara la prctica del monitor serie. Los p ulsos va n a ser

    enviados c uando p ulsemos l a b arra e spaciadora e n e l monitor. En la funcin emitirPulsos() pegaremos

    el cdigo que n os ha proporcionado e l programa a nterior.

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    2728

    /*(ed IRApaga $ enciende una te%e isi n mediante un %ed IR*/

    int %edIR ;,7 // ec%aro pin para e% %ed IR

    oid setup#' Epin:ode#%edIR B@TP@T'7 //1on&iguro e% pin ;, como sa%idaeria% "egin#F600'7 //Inicio %a comunicaci n serieeria% print%n#G %ed IR G'7eria% print%n#G**********************************G'7eria% print%n#G* 1ontro% TO9 *G'7eria% print%n#G**********************************G'7eria% print%n#G* )ncender/Apagar9 *G'7eria% print%n#G* "arra espaciadora *G'7eria% print%n#G**********************************G'7H

    oid %oop#'E int serie7 //A%maceno %os datos Sue %%eganpor serie

    whi%e # eria% a ai%a"%e#' M 0'E //1uando ha$ datos para %eer

    serie eria% read#'7 //(eo esos datos

    switch#serie'E case 9 // arra espaciadora emitirPu%sos#'7 //(%amo a %a &unci n Sue emite %os pu%sos eria% print%n#G)n iado!G'7 de%a$#2000'7 "reak7

  • 8/9/2019 manejo IR

    8/30

    29

    30

    31

    32

    33

    3435

    36

    37

    38

    39

    40

    41

    42

    43

    44

    4546

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    65

    66

    67

    68

    69

    70

    71

    72

    73

    74

    75

    76

    7778

    de&au%t9 // i es otra cosa "reak7 //no hago nada H HH

    oid emitirPu%sos#'E /*ASu pegamos e% c digo proporcionado por e% anterior programa*/ pu%seIR#-0'7 de%a$:icroseconds#U;40'7 pu%seIR#60'7 de%a$:icroseconds#U-20'7 pu%seIR#-0'7 de%a$:icroseconds#4240'7 pu%seIR#;00'7 de%a$:icroseconds#U200'7 pu%seIR#-0'7 de%a$:icroseconds#;460'7 pu%seIR#-0'7

    de%a$:icroseconds#6,40'7 pu%seIR#-0'7 de%a$:icroseconds#;;>40'7 pu%seIR#60'7 de%a$:icroseconds#2-0'7 pu%seIR#;20'7 de%a$:icroseconds#>U60'7 pu%seIR#60'7 de%a$:icroseconds#2;60'7 pu%seIR#;20'7 de%a$:icroseconds#;60'7 pu%seIR#;00'7 de%a$:icroseconds#;;U40'7

    pu%seIR#;40'7 de%a$:icroseconds#>-0'7 pu%seIR#60'7 de%a$:icroseconds#>440'7 pu%seIR#2-0'7 de%a$:icroseconds#F600'7 pu%seIR#;60'7 de%a$:icroseconds#2-40'7 pu%seIR#;60'7 de%a$:icroseconds#F420'7 pu%seIR#;00'7 de%a$:icroseconds#;0220'7 pu%seIR#-0'7

    de%a$:icroseconds#>420'7 pu%seIR#;20'7 de%a$:icroseconds#4U20'7 pu%seIR#4-0'7 de%a$:icroseconds#;02-0'7 pu%seIR#60'7 de%a$:icroseconds#,2-0'7 pu%seIR#-0'7 de%a$:icroseconds#,-;00'7 pu%seIR#;40'7 de%a$:icroseconds#2>>20'7 pu%seIR#-0'7 de%a$:icroseconds#;2400'7

    pu%seIR#60'7 de%a$:icroseconds#40U-0'7 pu%seIR#;20'7

  • 8/9/2019 manejo IR

    9/30

    79

    80

    81

    82

    83

    8485

    86

    87

    88

    89

    90

    91

    92

    93

    94

    9596

    97

    98

    99

    100

    101

    102

    103

    104

    105

    106

    107

    108

    109

    110

    111

    112

    113

    114

    115

    116

    117

    118

    119

    120

    121

    122

    123

    124

    125

    126

    127128

    de%a$:icroseconds#;60'7 pu%seIR#-0'7 de%a$:icroseconds#,FF-0'7 pu%seIR#60'7 de%a$:icroseconds#4420'7 pu%seIR#60'7

    de%a$:icroseconds#;;F60'7 pu%seIR#60'7 de%a$:icroseconds#-U-0'7 pu%seIR#-0'7 de%a$:icroseconds#UF60'7 pu%seIR#60'7 de%a$:icroseconds#;2;60'7 pu%seIR#;00'7 de%a$:icroseconds#42220'7 pu%seIR#-0'7 de%a$:icroseconds#,-F,2'7 pu%seIR#;00'7 de%a$:icroseconds#,>40'7

    pu%seIR#-0'7 de%a$:icroseconds#>;F40'7 pu%seIR#;00'7H oid pu%seIR#%ong microseg'E /*Kenera %os pu%sos de ,-. de &recuencia durante < microsegundos VParWmetros9 microseg*/

    c%i#'7 // desa"i%itamos cua%Suier interrupci nwhi%e #microseg M 0' E /*,-. son apro< ;,microseg en IK $ ;,microseg en (B3

    %a instrucci n digita%3rite tarde ,microseg en eXecutarse por %o Sue hacemos dos de%a$s de ;0 en e de ;, )n tota% e% cic%o dura 26microseg cuando se comp%eta restamos a% tiempo Sue tiene Sue estar mandando e% pu%so*/digita%3rite#%edIR IK '7de%a$:icroseconds#;0'7digita%3rite#%edIR (B3'7de%a$:icroseconds#;0'7microseg = 267Hsei#'7 // acti a %as interrupcionesH

  • 8/9/2019 manejo IR

    10/30

  • 8/9/2019 manejo IR

    11/30

    F"R #$C Protocol Ba ed Remote Control for thi Bord

    Remote %ontrol *or his 0oard

    #$C Infrared Protocol

    http://www.circuitvalley.com/2013/09/nec-protocol-ir-infrared-remote-control.htmlhttp://www.circuitvalley.com/2013/09/nec-protocol-ir-infrared-remote-control.html
  • 8/9/2019 manejo IR

    12/30

  • 8/9/2019 manejo IR

    13/30

    2 &its *or the address (address > inverse) re?uire 6 inverse)

    also re?uire 6 address inverse) or (command>command inverse) willalwa"s contain 4 9 9s and 4 929s so (4 @ 2.26,ms) > (4 @ 6.6,ms) AA 6 .,ms>66

  • 8/9/2019 manejo IR

    14/30

    the image give &low is ta e &" Rigol DB2 ,6$Cscilloscope

    'o&ic naly er how the timin& detail 2 leading pulse at 4 .22,ms 6 space on 13.64ms 3 +ddress starts at 1

  • 8/9/2019 manejo IR

    15/30

    he #$% protocol is so widel" used that soon all possi&le addresseswere used up. 0" sacri=cing the address redundanc" the address range wase tended *rom 6, possi&le values to appro imatel" , di erent values.

    his wa" the address range was e tended *rom 4 &its to 2 &its withoutchanging an" other propert" o* the protocol. he command redundanc" is

    still preserved. here*ore each address can still handle 6, di erentcommands.in e tended protocol instead o* sending address and addressinverse we send address low and address high as shown in the image &low.

    Repeat Codes

    If the key on the remote controller is kept depressed, a repeat code will be issued,typically around 40ms after the pulse burst that signified the end of the message. A repeat codewill continue to be sent out at 108ms intervals, until the key is finally released. he repeat codeconsists of the following, in order!

    A "ms leading pulse burst A #.#$ms space A $%#.$&s pulse burst to mark the end of the space 'and hence end of the transmitted repeat

    code(.the figures give blow show the timing of repeat codes

  • 8/9/2019 manejo IR

    16/30

    if user keeps the key depressed the repeat codes keep coming

  • 8/9/2019 manejo IR

    17/30

    8 shows the timing of repeat code

    Decoding NEC Protocol with microcontroller)ecoding *+ is really easy ,there are certainly various methods to do, some e-amples i

    have see n used polling method in which the firmware keep polling the input pin of microcontroller which connects to I sensor , other method is to user interrupt ,inthis demonstration we will be using the interrupt method as this one is better, we will be usinginterrupt on change.

    Schematic :

    SOFTWARE

    Git !" Repo

    Clic# here DOWN$OAD T E SO%RCE CODE & F'R(WARE And Schematic

    https://github.com/circuitvalley/IR-Remote-Controlhttps://sites.google.com/site/microembededfiles/home/september-2012/NEC%20IR%20REMOTE.zip?attredirects=0&d=1https://github.com/circuitvalley/IR-Remote-Controlhttps://sites.google.com/site/microembededfiles/home/september-2012/NEC%20IR%20REMOTE.zip?attredirects=0&d=1
  • 8/9/2019 manejo IR

    18/30

    PROTOT)PE

  • 8/9/2019 manejo IR

    19/30

    http!//www.circuitvalley.com/#01#/0"/infrared ir nec microcontroller pic avr.html

    EXTRAER DIRECCION Y COMANDO

    #include #use delay(clock=20000000)#fuses N !" $%&$ ' $ N ' *+ $ , !N $ -+ $ N /'$ N +'"

    oid e 3 + ( oid)5

    #define 3 N' ' N3,0 77 he "ecode9 has o :e connec ed o anin e99u; ;in

    #define 3& A & ( in;u ( 3 N' )) 77 in e9 si nal f9o ecei e9

    y;edef s 9uc in 8 da a?2@5in 8 s a e5

    9c 3s 9uc 5

    http://www.circuitvalley.com/2012/09/infrared-ir-nec-microcontroller-pic-avr.htmlhttp://www.circuitvalley.com/2012/09/infrared-ir-nec-microcontroller-pic-avr.html
  • 8/9/2019 manejo IR

    20/30

    9c 3s 9uc 9c 5

    77 in e99u; func ion fo9 eB e9nal in e99u; ;in#in 3*C *C 3is9() e 3 + ()5

    77 + decodinin 1 e 3 + ( oid) in 16 ;$ 5 in i5 in 1 in;5

    se 3 i e91(0)5 77 9ese i e9 Dhile( 3& A &==1)5

    = e 3 i e91()5

    if ((

  • 8/9/2019 manejo IR

    21/30

    ;= ; E 0B 0005 77 clea9 ,i s 1 $14 I 1

    ;= ; I 0B Hff5 77 cu off o le:i

    9c .da a?0@= ; I 0Bff5 77 eB 9ac de ice add9ess

    ;>>=85

    9c .da a?1@= ; I 0Bff5 77 eB 9ac co and code

    9c .s a e = 15 77 se fla fo9 successful co and decodin

    disa:le3in e99u; s( N 3*C )5 77 disa:le n e99u; s un il 9ecei edco and has :een ;9ocessed

    9e u9n 15

    oid ain() 77 con 9olle9 ini ialisie9en se u;3 i e930( ++3 N * NA E ++3" /31)5 se u;3 i e931( 13 N * NA E 13" /3,J38)5 77 i e91 is used fo9 +decodin . !hen he chi; 9uns K 20-%L$

    77 a ;9escale9 of 8 has o :e used

    se u;3 i e932( 23" &A, *"$0$1)5 se u;3co ;a9a o9(N+3N+3N+3N+)5 se u;3 9ef(FA &*)5

    77 ena:le in e99u; sena:le3in e99u; s( N 3*C )5

    ena:le3in e99u; s(M ,A )5

    9c .s a e = 05

    Dhile(1) if(9c .s a e==1) 77 did De 9ecei e a alid co and

    9c .s a e = 05

    ;9in f(O"e iceP QuRnO$ 9c .da a?0@)5 77 dis;lay de ice add9ess ;9in f(O+o andP QuRnO$ 9c .da a?1@)5 77 dis;lay co and code

  • 8/9/2019 manejo IR

    22/30

    ena:le3in e99u; s( N 3*C )5 77 9eena:le in e99u; s

    http://www.microchip.com/*orums/m, 122 .asp

    )escription

    This project shows how to decode IR remote controls which use RC5 code with a PIC

    microcontroller.

    With being able to read IR remote control command it is possible to use standard remote

    controls as input device for a microcontroller.

    $ asics

    n 9oduc ion

    The RC5 protocol was developed by Philips as consumer IR infrared! remote control

    communication protocol for consumer electronics.

    "a a Fo9 a

    The RC5 code is "# bits long. $ach code includes % start bits& " toggle bit& a 5 bit address or

    system! and a ' bit command. This allows for (% systems li)e T*& C+& video& etc.! and '#

    commands per system.

    http://www.microchip.com/forums/m509110.aspxhttp://www.microchip.com/forums/m509110.aspx
  • 8/9/2019 manejo IR

    23/30

    The two start bit indicate the start of the RC5 frame.

    Note:

    Af e9 so e i e 64 co ands ;e9 sys e didnS see o :e enou h hou h$ so an eB 9a

    co and :i Das added o alloD 128 co ands. o ain ain :ackDa9d co ;a i:ili y Di h

    he s anda9d + $ he fo9 a i self Das lef unchan ed. he second s a9 :i (&2) Das

    9e;laced :y +6. he 9esul in fo9 a is called *B ended + .

    The toggle bit T changes each time a new command is transmitted. It allows detection if the

    same )ey is pressed twice. ,ince a code is being sent as long as the )ey is pressed& a short

    release of the button and again pressing it again would otherwise not be recogni-ed.

    The address bits 5.. / specifies the system or device! the command shall be sent to& e.g.

    T*& C+& *ideo& etc.

    0inally& the command bits specify the command to be performed.

    -odula ion

    RC5 uses 1anchester coding. 1anchester coding has a transition in the middle of a bit.

    logical " is coded as a / in the first half of the bit and a " in the second half of the bit.

    logical / is coded as a " in the first half of the bit and a / in the second half of the bit.

  • 8/9/2019 manejo IR

    24/30

    Important hint:

    -os of he ecei e9s (e. . he &F% 110 o9 & '1H 6) ha e an in e9 ed ou ;u &o a

    lo ical 1 a he ou ;u of he ecei e9 Dill :e 9e;9esen ed :y a 1 in he fi9s half of he :i

    and a 0 in he second half$ a lo ical 0 Dill :e 9e;9esen ed :y 0 in he fi9s half of he :i and

    a 1 in he second half.

    + *Ba ;le

    In the e2ample below an e2ample of an RC5 code which shows how the information is coded.

    In this e2ample the toggle bit is /& the address is also / and the command is 3& i.e. )ey 434

    has been pressed.

    2ardware

    s IR Receiver I used a ,065""/ (' which is a IR Receiver for Remote Control ,ystems. lso

    other IR Receivers li)e& a ,065/' (' or T,7P"8(' will wor). Important is that the IR

    Receiver is designed for a carrier fre9uency of (')6- which is the carrier fre9uency used by

    RC5!.

    The interface to the PIC microcontroller is very simple& the output of the IR Receiver just

    needs to be connected to an :interrupt on change: pin. I used a PIC"'0;;' where port < has

    :interrupt on change: capability& so I connected it to port pin R

  • 8/9/2019 manejo IR

    25/30

    3oftware

    The RC5 software driver is written in C language and currently is compatible to CC, C

    compiler and 1icrochip C"; compiler.

    "ecodin

    The decoding happens in the interrupt service routine of the :on change: interrupt of port

  • 8/9/2019 manejo IR

    26/30

  • 8/9/2019 manejo IR

    27/30

    @ow we need to add the interrupt handler which calls the RC5 decoding function of the RC5

    driver. The decoding function is RC5_InterruptHandler() .

    /*****************************************************************************//* Interrupt5R*//**//* Port change interrupt ser ice routine*//* @sed to decode R1> IR signa%*//*****************************************************************************/8INT5Roid Interrupt5R # oid 'ER1>5Interrupt and%er#'7c%ear5interrupt#INT5R '7H

    nd finally& we need to configure the timer / which will be the time base for the RC5

    decoding function and enable the :on change: interrupt.

    /* QB 1/4 is timer source *//* QB 1 20: M >: i e timer increment e er$ t ;/#QB 1/4' 200ns *//* with presca%er o& ;2- timer wi%% increment e er$ 2> 6us */setup5timer50#RT115INT)RNA(YRT115 IO5;2-'7/* con&igure port interrupt on change */set5tris5"#0

  • 8/9/2019 manejo IR

    28/30

    /*** QI() )A )R****************************************************************** QI()NA:)9 rc>demo c* AT)9 26 0U 20;;* A@T BR9 1hristian tad%er** ) 1RIPTIBN9 R1> demo which shows usage o& R1 decoder dri er*******************************************************************************//* make compi%er case sensiti e */8pragma case8inc%ude 8inc%ude Gt$pes hG/* === R1> dri er con&iguration === */8de&ine R1>5 ATA5PIN PIN5 ; /* IR sensor # Q >;;0=,6'connected to R ; */8de&ine R1>5TI1. 5P)R5: #;000/26' /* timer increments e er$

    2> 6us *//* i e around ,F ticks per mi%%isecond */8de&ine R1>5KetTimer#' get5timer0#' /* timer0 sha%% "e used&or R1> decoding */8inc%ude Grc> hG /* R1> dri er inc%ude *//* === macros to switch on/o&& () === */8de&ine (ed5Bn#' output5high#PIN5A0'8de&ine (ed5B&' output5%ow#PIN5A0'/*****************************************************************************//* Interrupt5R*/

    /**//* Port change interrupt ser ice routine*//* @sed to decode R1> IR signa%*//*****************************************************************************/8INT5Roid Interrupt5R # oid 'E(ed5Bn#'7

    R1>5Interrupt and%er#'7c%ear5interrupt#INT5R '7(ed5B&'7H/*****************************************************************************//* main*//**//* 1on&igures timer0 as time "ase &or R1> decoding and ena"%es port */

    /* interrupt on change*/

  • 8/9/2019 manejo IR

    29/30

    /* :ain %oop checks i& a R1> code has "een recei ed and writes thecode *//* to the R 2,2 inter&ace*//*****************************************************************************//* NBT)9 1urrent%$ it on%$ works i& PI1 is reset a&ter programmingZ */oid main#'Euint;6 rc>code7/* QB 1/4 is timer source *//* QB 1 20: M >: i e timer increment e er$ t ;/#QB 1/4' 200ns *//* with presca%er o& ;2- timer wi%% increment e er$ 2> 6us */setup5timer50#RT115INT)RNA(YRT115 IO5;2-'7/* con&igure port interrupt on change */set5tris5"#0 1ode 0code'R1>5KetTogg%e it#rc>code'R1>5Ket1md#rc>code''7H/* this &unction increments the R1> timeout timer *//* NBT)9 ecoding wi%% a%so work without ca%%ing this &unction "ut *//* it cou%d happen that R1> codes are sometimes not getting *//* recogni ed "ecause o& decoding state machine stucks due *//* to erroneous R1> signa% */R1>5TimeoutIncrement#'7H

    H

  • 8/9/2019 manejo IR

    30/30

    )ownload

    +emo project CC, C Compiler!D rc5AdecoderAccsA"""/"'.-ip +emo project 1icrochip C"; Compiler!D rc5AdecoderAc";A"""/"3.-ip +river source code CC, C Compiler& 1icrochip C"; Compiler!D rc5.h

    http://mem&ers.aon.at/electronics/pic/pro!ects/rc,Edecoder/inde .html

    http://members.aon.at/electronics/pic/projects/rc5_decoder/rc5_decoder_ccs_111016.ziphttp://members.aon.at/electronics/pic/projects/rc5_decoder/rc5_decoder_c18_111019.ziphttp://members.aon.at/electronics/pic/projects/rc5_decoder/rc5.hhttp://members.aon.at/electronics/pic/projects/rc5_decoder/index.htmlhttp://members.aon.at/electronics/pic/projects/rc5_decoder/rc5_decoder_ccs_111016.ziphttp://members.aon.at/electronics/pic/projects/rc5_decoder/rc5_decoder_c18_111019.ziphttp://members.aon.at/electronics/pic/projects/rc5_decoder/rc5.hhttp://members.aon.at/electronics/pic/projects/rc5_decoder/index.html