0900 - Remote Control IR Decode

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Copyright © 2008, Wimborne Publishing Ltd

(Sequoia House, 398a Ringwood Road, Ferndown, Dorset BH22 9AU, UK)
and TechBites Interactive Inc.,
(PO Box 857, Madison, Alabama 35758, USA)

All rights reserved.

The materials and works contained within EPE Online — which are made available by 
Wimborne Publishing Ltd and TechBites Interactive Inc — are copyrighted. 

TechBites Interactive Inc and Wimborne Publishing Ltd have used their best efforts in preparing these materials and works. However, TechBites 
Interactive Inc and Wimborne Publishing Ltd make no warranties of any kind, expressed or implied, with regard to the documentation or data 
contained herein, and specifically disclaim, without limitation, any implied warranties of merchantability and fitness for a particular purpose. 
 
Because of possible variances in the quality and condition of materials and workmanship used by readers, EPE Online, its publishers and agents 
disclaim any responsibility for the safe and proper functioning of reader‐constructed projects based on or from information published in these 
materials and works. 

om
 
In no event shall TechBites Interactive Inc or Wimborne Publishing Ltd be responsible or liable for any loss of profit or any other commercial 
damages, including but not limited to special, incidental, consequential, or any other damages in connection with or arising out of furnishing, 
performance, or use of these materials and works. 

.c
 
READERS’ TECHNICAL ENQUIRIES 
ag
We are unable to offer any advice on the use, purchase, repair or modification of commercial equipment or the incorporation 
or modification of designs published in the magazine. We regret that we cannot provide data or answer queries on articles or 
projects that are more than five years’ old. We are not able to answer technical queries on the phone. 
m
PROJECTS AND CIRCUITS 
pe

All reasonable precautions are taken to ensure that the advice and data given to readers is reliable. We cannot, however, 
guarantee it and we cannot accept legal responsibility for it. A number of projects and circuits published in EPE employ voltages 
.e

that can be lethal. You should not build, test, modify or renovate any item of mains‐powered equipment unless you fully 
understand the safety aspects involved and you use an RCD adaptor. 
w

COMPONENT SUPPLIES 
w

We do not supply electronic components or kits for building the projects featured; these can be supplied by advertisers in our 
publication Practical Everyday Electronics. Our web site is located at www.epemag.com 
w

We advise readers to check that all parts are still available before commencing any project. 

 
To order you copy for only $18.95 for 12 issues go to www.epemag.com 
PIC Programming Project

REMOTE CONTROL
IR DECODER
ROGER THOMAS
the infra-red signal. The final stage is a
Allows PIC programming enthusiasts comparator circuit which gives a clean
TTL output signal. Using this device is
to remotely control their designs. considerably easier (and cheaper) than
building a circuit using a separate infra-red
detector and amplifier. Pinouts are given in
design was created to enable PIC are recognised by the PIC software and

T
HIS
Fig.4.
microcontroller circuits to be used to switch these l.e.d.s on or off. Data output from the sensor is connect-
enhanced by the addition of a low Resistors R1 and R2 limit the l.e.d. cur- ed directly to the PIC at Port B pin RB0.
cost infra-red sensor and suitable decoding rent from the PIC. Additional l.e.d.s with (It could also be added to an existing PIC
software. The operation of the PIC soft- suitable current limiting resistors can be circuit with minimal additional wiring if a

om
ware can then be selected via a remote added but note that the PIC can only spare port pin is available.)
control handset. This control option may source a maximum current of 20mA per With no infra-red signal the output of
be preferable to interfacing external port pin, with a maximum current total of the device is 5V (logic 1) and consumes a
switches to the PIC. 100mA for Port B. maximum current of 4·5mA (2·8mA typi-
The circuit and program could also be The circuit can easily be built on strip- cal). The recommended power supply
used just as a simple tester to show that a
remote control is working.

BASIC FUNCTIONS
supply. No constructional details are
.c
board and requires a regulated +5V power

offered. Software is available as stated later.


range is 4·7V to 5·3V.
ag
Referring to Fig.1, the Remote Control SERIAL INTERFACE
Decoder uses an infra-red sensor (IC2) the It can be difficult to predict what com-
demodulated output from which is con- mand code a particular remote control
m

nected to a PIC16x84 microcontroller handset key will generate. Instead of


(IC1) for decoding. switching on or off l.e.d.s, the value of the
Remote control handsets can use a vari- command code generated by the remote
pe

ety of different protocols. The PIC soft- control handset can also be serially trans-
ware decodes either the RC5 (Philips) or mitted to a PC-compatible computer. Fig.2. 9-pin D-type female serial
SIRC (Sony) transmission protocol as To achieve this, R3 is a series current- connector.
these are most likely to be used to control limiting resistor and connects Port B pin
.e

equipment in the home. These protocols RB3 to pin 2 of a 9-pin D-type serial port

COMPONENTS
are described later so that the decoding socket (SK1 in Fig.2) so that the data from
software can be understood and incorpo- the PIC circuit can be sent direct to the
w

rated as part of another program for a more PC’s serial port. In serial mode, the PIC
elaborate circuit. software needs to be amended with the
To help demonstrate the decoding l.e.d. output routine replaced by the serial Resistors See
SHOP
w

R1, R2 680W
process, and provide programming exam- port emulation software. (2 off)
ples, the PIC circuit incorporates two light By running the PC serial link version of
emitting diodes (D1 and D2) connected to the PIC software the command values of
R3 470W
TALK
w

Port B. Certain remote control key codes different remote control handset keys are page
Capacitors
displayed. The lists C1 10mF elect. 10V
which illustrate vari- C2, C3 33pF ceramic (2 off)
ous command codes
are given later, but can Semiconductors
only be used as a gen- D1, D2 red l.e.d. (2 off)
IC1 PIC16x84
eral guide to what microcontroller,
µ
command code a preprogrammed

given key on the (see text)
handset may generate. IC2 IS1U60 infra-red sensor

INFRA-RED Miscellaneous
SENSOR
Ω SK1 9-pin D-type serial
connector, female
The IS1U60 X1 4MHz crystal

remote control infra-
red sensor, IC2, is Stripboard, size to suit; 5V power
manufactured by supply (see text)
Sharp. As can be
seen from the block
diagram in Fig.3, this
device filters, ampli-
Approx. Cost
Guidance Only £8
excluding PSU
Fig.1. Circuit diagram for the Remote Control IR Decoder. fies and demodulates

698 Everyday Practical Electronics, September 2000


Fig.3. Block diagram for the IS1U60 remote control IR sensor.

Next is the Address (A4 to A0) of the Table 1. Example RC5 device addresses.
equipment that is to respond to the com-
mand transmitted. With five bits there are Address Device
0 TV receiver 1
32 different devices that can be addressed. 1 TV receiver 2
Some of the more common addresses are 2 teletext
given in Table 1. Note that the software of 5 video recorder 1
the decoder described here does not actu- 6 video recorder 2
ally decode the device address but the pro- 7 experimental

om
gram could be altered to do so. 8 satellite
After the address come the six 16 preamplifier 1
Command code bits (C5 to C0), giving a 17 tuner
18 audio tape recorder 1
total of 64 different commands that can be 19 preamplifier 2
transmitted. Some of the more common 20 CD player
commands are listed in Table 2.

.c
Commands 0 to 17 are used mostly to con-
trol a TV receiver, commands 41 to 46 are
23 audio tape recorder 2
ag
used for teletext, and 47 to 55 used to con- Table 2. RC5 command codes.
trol a video tape recorder. Command Function
0-9 numerals 0 to 9
10 digits
m

11 select
12 stand-by
13 mute
pe

14 presets
15 display
16 volume +
Fig.4. Pinouts for the IS1U60 sensor. 17 volume –
41 page
.e

42 timer
RC5 PROTOCOL 43
44
large
reveal
The RC5 remote control code protocol
w

45 cancel
was developed by Philips and is used by 46 subtitle
several other manufacturers. However, it is 47 store
w

worth noting that not all products manu- 48 pause


factured by Philips use this protocol. 49 erase
An RC5 transmission has a duration 50 fast reverse
w

µ
of approximately 25 milliseconds and 51 fast forward
contains 14 bits of data. A logic 0 is 52 rewind
encoded by a high-to-low transition and Fig.5. RC5 timing of logic 0 and logic 1 53 play
data. 54 stop
a logic 1 by a low-to-high transition. 55 record
This is called bi-phase coding, as illus-
trated in Fig.5.
The arrangement of the 14-bit code is
given in Fig.6. The first two bits (S) of the
RC5 DECODING is read (TIMERVAL) after every interrupt
transmission are Start bits and are always SOFTWARE and the RTCC timer is then set to zero and
transmitted as logic 1. This allows the IR RC5 transmissions are relatively slow in begins to count up again. PIC software
receiver to adjust its automatic gain con- comparison to the operation of the PIC times the IR sensor output from falling
trol to suit the infra-red signal strength. microcontroller. However, due to the bi- edge to falling edge. With a 4MHz crystal
The Control bit (C) toggles whenever a phase encoding, a more complicated clock and prescaler set to 16, the timer is
new key is pressed, or if a key is held downdecoding algorithm is needed than might incremented every 16 microseconds.
and a repeated transmission is made every be expected. As can be seen from the various logic
113 milliseconds. The decoding software works by using combinations in Fig.7, despite the number
the falling edge of of different waveform permutations, the
the RC5 signal to edge-to-edge timing can be one of only
generate an inter- three different values.
rupt. The 8-bit inter- The output from the infra-red sensor is
nal RTCC (Real high and goes low when a signal is
Time Clock received, so on the first interrupt the timer
Fig.6. RC5 code format. Counter) timer value value is not valid. Program variable BITS

Everyday Practical Electronics, September 2000 699


Observation of the waveform will
show that if the last pulse of an RC5
transmission is zero, then there is no
final falling edge to enable an interrupt
to read the timer. With no interrupts the
RTCC timer will reach 255 (maximum
byte value) and start counting from zero.
This “roll-over’’ sets the timer overflow
flag, which is used to indicate the end of
transmission and the LEDDISPLAY
output routine is called.
RC5 ASSEMBLER
PROGRAM
Once the RC5 assembler listing is pro-
grammed into the PIC the decoding soft-
ware can be tested. If the key marked “1’’
on the remote control is pressed one l.e.d.
(D1) will come on, if the “2’’ key is
pressed then the other l.e.d. (D2) will
come on. If the “3’’ key is pressed then
both l.e.d.s come on.
To change which key alters the l.e.d.,
change the CBINARY comparison
value in the LEDDISPLAY routine.
For example, using a VCR remote con-
trol, change the three comparisons to
D’53’, D’54’, D’55’ (to change from
hexadecimal to decimal notation
replace H’nn’ with D’nnn’ in the assem-

om
bler program).
On the remote control handset pressing
the VCR Play key should generate com-
mand code 53 and one of the l.e.d.s should
light. Pressing the Stop key should gener-

.c ate code 54 and light the other l.e.d.


Pressing the Record key should generate
55 and both l.e.d.s should be on.
ag
Fig.7. Example RC5 timing diagram.
m

is used to ensure that on the first interrupt last bit received. If


(BITS = 1) the program variables are ini- TIMERVAL = 2 and
tialised but the RTCC timer value is not the previous bit was
pe

used. 0 then the result is


On the second interrupt (BITS = 2) the binary 10. Fig.8. SIRC code format.
RTCC timer value of the start bit is The ADDBINARY routine is then
assigned to variable TIMERVAL. This called, which updates the value of the SIRC PROTOCOL
SIRC (Serial Infra-Red Control) proto-
.e

value is used as a reference and all subse- CBINARY (command binary) variable
quent timer value calculations use it. using the THISBIT variable value. The col is the name given to Sony’s IR remote
The XVALUE variables are used to set BITS value must be greater than eight so control system. The 12-bit protocol is the
most common format used with domestic
w

the three different TIMERVAL value that only the command part of the RC5
ranges, this determines the waveform tim- sequence is decoded. products but there are others, including
ing (see Listing 1). Using ranges of values If THISBIT = 1 then the appropriate 15-bit and 20-bit versions. Control-S pro-
w

rather than direct comparison to the first bit within the CBINARY variable byte is tocol is the hard-wired TTL version of the
reading ensures that any timing discrepan- set to 1. This is done by logic ORing BIT- infra-red SIRC signal.
cy does not affect the operation of the pro- VALUE and CBINARY. Dividing BIT- In most respects these transmissions
w

gram. Small variations in the RTCC value VALUE by two sets the next bit within are easier to decode than RC5. Several
are inevitable due to PIC interrupt latency this variable to 1. of the routines and variables used in the
and tolerances between different remote Initially the value of BITVALUE is 32 SIRC decoding program are similar to
controls. (binary 100000), so dividing BITVALUE the ones used in the RC5 program. The
Once the TIMERVAL comparison is by two gives 16 (binary 010000). Division command word is made up of 12 bits,
made, the appropriate waveform time can by two is done by shifting the variable to and consists of a 5-bit device code fol-
be determined. If TIMERVAL = 1 then the right by one place using the RRF lowed by a 7-bit command code, see
the result will be the same as the last bit instruction (Rotate Right File). If THIS- Fig.8. This SIRC format uses pulse
(value of variable LASTBIT). If TIMER- BIT = 0, only BITVALUE needs to be width modulation of the infra-red signal
VAL = 1·5 then the result is to invert the altered as the relevant bit within CBINA- to transmit the data.
RY is already zero. The SIRC transmission is preceded by a
An alternative decoding method con- single start bit, unlike the RC5 code. The
LISTING 1. Setting TIMERVAL values. sidered was to use a timer-generated inter- SIRC decoding software waits for this
XVALUE1 = 0.5 x initial TIMERVAL rupt to sample the waveform every 889 start bit of 2·4 milliseconds. When it is
XVALUE2 = 1.25 x initial TIMERVAL microseconds, after detecting the initial correctly received the START variable is
XVALUE3 = 1.75 x initial TIMERVAL waveform edge. However, if the RC5 set to 1 to allow the rest of the transmis-
if (current TIMERVAL > XVALUE1 and transmission is faster or slower due to dif- sion to be decoded.
< XVALUE2) then TIMERVAL = 1 ferences between remote handsets, then Using a unique signal as a start bit helps
if (current TIMERVAL > XVALUE2 and there is a possibility that accumulated tim- prevent the software trying to decode an
< XVALUE3) then TIMERVAL = 1.5 incomplete transmission. The infra-red
if current TIMERVAL > XVALUE3 then ing error would cause either a pulse to be
TIMERVAL = 2 missed or the same pulse to be sampled sensor uses this start pulse to set its auto-
twice. matic gain control.

700 Everyday Practical Electronics, September 2000


The SIRC command sequence is usual-
ly transmitted at least three times and, for Table 3. SIRC device code. PC SOFTWARE
The Windows 95/98 software does not
some reason best known to Sony, the data Command Device decode the IR transmission but displays
is sent in reverse order. There is no equiv- 1 TV receiver
2 video tape recorder 1
the value of the CBINARY variable sent
alent to the control toggle bit as used in the from the PIC. The program also displays,
RC5 protocol. Like the RC5 transmission 4 video tape recorder 2
6 laser disk if available, a text message describing the
there is no additional information trans- key pressed. This text is read from two text
12 surround sound unit
mitted to allow for error detection. 16 cassette deck/tuner files, called RC5.TXT and SIRC.TXT,
The SIRC data consists of either pulses 17 CD player these files must be located in the same
of 0·6ms or 1·2ms duration, meaning logic 18 equaliser directory as the program.
0 and logic 1 respectively. Each pulse is The text can easily be altered using
preceded by a 0·6ms pause. The pulse Notepad to coincide with the intended
length is measured by the falling edge of Table 4. SIRC VCR FUNCTIONS remote control handset. These files store
the waveform generating an interrupt. The the relevant text in ascending order. For
timer value is incremented every 16 Command Function
0-9 numerals 0 to 9 example, the first line is text for CBINA-
microseconds and is read on every 9 10/0 RY = 0, the second line is for CBINARY
interrupt. 20 x2 play = 1, and so on.
To work out the likely timer values, 21 power Operation of the PC software is very sim-
divide the expected pulse width by the 22 eject ple, select the serial communications port
timer “tick’’, illustrated in Fig.9 and 24 stop that the PIC circuit is connected to and then
Fig.11. 25 pause
26 play select the required protocol. The Reload key
27 rewind reloads the text files if they have been
pulse width = start pulse = 2·4ms = 150 28 fast forward changed while the program is active. The
timer 16ms 16ms 29 record relevant protocol l.e.d. should flash when
data is received from the PIC circuit.
Fig.9. SIRC timer formula.
Table 5. SIRC TV FUNCTIONS
Command Function
0-9 numerals 0 to 9

om
2·4ms = 150 (start) 9 10/0
2·4ms + 0·6ms = 187 (start) 16 channel +
1·2ms + 0·6ms = 112 (logic 1) 17 channel –
0·6ms + 0·6ms = 75 (logic 0) 18 volume +
19 volume –
20 mute
Fig.10. SIRC TIMERVAL for all pulse
widths.
21
22
23
power
reset
audio mode .c
ag
24 contrast +
25 contrast –
26 colour +
27 colour – Fig.12. Example PC screen display.
30 brightness +
m

31 brightness – REMOTE CONTROLS


38 balance left A manufacturer using remote control of
39 balance right its equipment can allocate any command
pe

47 power off
Fig.11. SIRC timing details. number to any key. Remote controls are
not required to be compatible or exchange-
able with equipment from another manu-
The program uses the timer value to received correctly. Also, strong sunlight facturer, hence the plethora of remote con-
.e

determine the waveform. For example, if falling on the sensor can generate a signal. trols and protocols found in most homes.
the value is between 90 and 150 then a The author has come across a remote con-
logic 1 is assumed and THISBIT = 1. If SERIAL PORT trol for a portable TV that uses RC5 cod-
w

the value is between 50 and 90 then a logic The PIC16x84 microcontroller does not ing for some of the keys and another pro-
0 is assumed and THISBIT = 0. The have a built-in serial port but one can be tocol (not SIRC) for the remaining keys.
w

ADDBINARY routine is called and the implemented in software. Replace the As neither PIC program decodes the
appropriate bit within CBINARY is set to entire routine LEDDISPLAY with the device address then the result is a wider
the value of THISBIT. TXDATA code in the PIC assembler pro- choice of remote controls being available.
w

gram. Add the two equates to the top of the


SIRC ASSEMBLER assembler program and the BCF
However, if a suitable remote control hand-
set is not available then replacement remote
PROGRAM PORTB,RS232 to the MAIN (SIRC) or controls are readily obtainable with a variety
With the SIRC code running press the START (RC5) procedure. This enables the of functions and key layout. Most of these
Increase Volume key on the Sony remote RB3 port pin to be used as an output. In handsets are programmable and can replace
control and one l.e.d. (D1) will come on routine LOOP replace CALL LEDDIS- many different models; therefore there is an
the other l.e.d. (D2) will be off. Press the PLAY with CALL TXDATA. implied choice of protocol.
Decrease Volume key and the l.e.d.s will The TXDATA routine works by Clearly the IR decoding program could
invert. ANDing each data bit with the relevant bit alter a variable value or the status of a
To change which key controls the in CBINARY. This sets the output bit Boolean flag or control a device attached
l.e.d., select the appropriate value for the (called RS232), then the OP (output) rou- to one of the PIC ports. A number of dif-
key function and use that value in the tine is called and takes the pin RB3 high or ferent functions could be added as the
LEDDISPLAY routine. Note that the low according to the value of bit RS232. assembler code associated with the LED-
remote control may generate different Directly changing RB3 in the TXDATA DISPLAY routine can be increased as
numbers for the same function so that the routine would cause a timing error. necessary. Numeric input to a PIC pro-
Sony equipment can distinguish Once the RB3 output is set, this data gram via a remote control handset can
between, for example, Play for the CD output value has to be held, consequently easily be achieved.
player and Play for the tape recorder. See several NOP commands are required to
Tables 3 to 5. ensure correct timing. There is no hand- RESOURCES
As there is no error detection or data shaking or data transmission from the PC, The software discussed in this article is
verification with either of the IR protocols, therefore the connection from the PIC to available as stated on this month’s
errors can occur if the IR signal is not the serial socket has only two wires. Shoptalk page. 6

Everyday Practical Electronics, September 2000 701

You might also like