0900 - Remote Control IR Decode
0900 - Remote Control IR Decode
0900 - Remote Control IR Decode
(Sequoia House, 398a Ringwood Road, Ferndown, Dorset BH22 9AU, UK)
and TechBites Interactive Inc.,
(PO Box 857, Madison, Alabama 35758, USA)
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
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
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
µ
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
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-
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.
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
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