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

Williams.

qxd 12/8/2004 9:44 AM Page 51

Many robotics experimenters

build small robots or devices

that are intended to stay within

the limits of a room in a house


by Karl Williams

or school. An inexpensive way to

remotely control these machines

is to use a television infrared

remote control transmitter.

SERVO 01.2005 51

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.


Williams.qxd 12/8/2004 9:45 AM Page 52

INFRARED REMOTE CONTROL SIGNAL ANALYSIS


those signals is useful for is used by Panasonic. The shift coded
controlling small robots or scheme uses the direction of transition
devices. (phase) of the signal to represent the
Infrared remote controls data and all bits have a constant time
use anywhere from 12 to 60 period. In the shift coded scheme, a
bits when transmitting binary 0 is represented by the signal
codes. switching from high to low within a
As you will see later in constant time period. A binary 1 is
the article, only 8-10 of represented by the signal shifting
these bits are usually needed from low to high within a time period.
when controlling a robot. If The shift coded protocol is known as
you plan on using only the RC-5 and is used by Philips.
television controls on the The most common technique and
remote, then as little as four the one that we will investigate is
bits of the information is known as Pulse Width Modulation
Figure 1. A variety of infrared remote control necessary. (PWM). This method works by varying
transmitters. the duration of the ON or OFF periods
Infrared Signals of the modulated infrared. In order to
Most of the published literature and How They Work control a device, a unique number
focuses on using the Sony 12-bit representing the key that has been
protocol. I think the reason for this is IR remote control operates by pressed on the remote and possibly
because Sony uses a 12-bit standard modulating (turning on and off) an information about which device this
without any error checking, making it infrared (IR) light source. Infrared light key is intended to control needs to be
easy to decode. I already have a lot is located on the electromagnetic sent. This is done by representing the
of IR remote control transmitters spectrum just below the visible light number in binary or base 2. In binary,
lying around the house that have that our eyes can see. The rate at there are only two digits — 0 and 1 —
outlived their AV units, but none of which the modulation occurs is called to deal with.
them is from Sony — not to mention the carrier frequency. This is done to Therefore, only two distinct “pulse
the three remotes in the living provide a transmission system that widths” are needed to represent
room for my television, VCR, and allows operation in noisy lighting each digit. This simplifies the process
DVD player (Figure 1) that I could use environments. The remote control considerably.
for experimenting. information is placed on the carrier Using this scheme, the periods of
This article will focus on analyzing using several different techniques, ON and OFF will need to alternate. If
the signals generated by standard depending on the manufacturer. they didn’t, it would be impossible to
38 kHz IR transmitters and then deter- Three of the methods used are judge their widths. Either the width of
mining what information contained in pulse coded, space coded, and shift the ON period or the width of the OFF
coded, as illustrated in Figure 2. period will vary, depending on the
Figure 2. Information coding methods With the space coded method, manufacturer. In summary, IR transmis-
employed by infrared remote systems. data is represented by varying sions most often take place by varying
the space (amount of time) the ON/OFF times of an IR emitter to
between pulses. The space coded represent binary numbers according to
protocol is known as REC-80 and an established pattern. All that needs
to be done is to capture
Figure 3. PNA4602M and TRM1038 infrared the entire signal, measure
receiver modules. the width of each pulse,
and then decode the
pattern.

Analyzing
an Infrared
Remote
Control Signal
To capture the
infrared packet being
transmitted by the remote
52 SERVO 01.2005

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.


Williams.qxd 12/8/2004 9:46 AM Page 53

INFRARED REMOTE CONTROL SIGNAL ANALYSIS


control, an IR receiver module that
responds to a 38 kHz carrier will
be needed. These detectors have a
band-pass filter that limits the input to
38 kHz only. This means that the
detector will give an output only when
a 38 kHz infrared signal is received. I
experimented using the Panasonic
PNA4602M module and two others (a
part labeled TRM1038 and a generic
unlabeled module) that I picked up at
a surplus electronics shop and each
functioned with the same results
(Figure 3).
The PNA4602M detector’s output
is active-low. That means that the
output is low when a 38 kHz IR signal
is being received. When no 38 kHz Figure 4. Infrared decoding circuit schematic diagram.
signal is present, the detector’s output
is high. Because I had a Sanyo IR common and inexpensive — thanks to in Figure 4. I use a Tektronix TDS 210
remote around, I decided to decode current RS-232 implementation and two channel, 60 MHz oscilloscope.
the signals that it produces to show an the excellent I/O specifications of the Set channel 1 to 2 volts per division,
alternative to using the Sony codes. PICmicro MCU — most applications a horizontal time of 10 ms, and the
Hopefully, the information that follows don’t require level converters. Rather, trigger mode to single.
will let you use all of those non-Sony inverted TTL (N300..N9600) can be If you need more information
remotes that are piling up. used when transmitting from the about how to use an oscilloscope,
To analyze the signals that are PICmicro to the computer. A 1KΩ then check out the excellent
being received by the PNA4602M IR current limiting resistor is suggested, oscilloscope tutorial on the Tektronics
module, an oscilloscope will be used but not necessary. website (www.tektronix.com/
along with a Microchip PIC 16F819 The infrared decoding circuit Measurement/App_Notes/XYZs/).
microcontroller that is clocked at 8 schematic (Figure 4) is simple enough Before writing a signal analysis
MHz internally. The PIC 16F819 will be to construct on an experimenter’s program for the microcontroller, let’s
interfaced to a personal computer breadboard. When the circuit is wired, take a look at the signal being transmit-
through the serial port of the PC. The attach the circuit to the computer’s ted from the Sanyo remote control
microcontroller will receive and store serial port using a straight through using an oscilloscope. Apply power to
the incoming infrared packets from the serial cable. Attach the channel 1 the circuit and set the oscilloscope as
PNA4602M IR module and then per- oscilloscope probe to the output pin of described above. Pressing the “1” key
form an analysis of each signal based the PNA4602M module, as indicated produces the waveform shown in
on the internal software
that will be written. Figure 5. Waveform produced by pressing the “1” key on the Sanyo remote.
When the analysis is
being performed, the
information will be sent
from the microcontroller
to a communications
terminal window on a PC
so that you can see what
is going on. This method
was used instead of a
serial LCD because I
wanted to be able to
display a list of packet
information to see what
sort of patterns were
emerging.
While single chip RS-
232 level converters are
SERVO 01.2005 53

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.


Williams.qxd 12/8/2004 9:48 AM Page 54

INFRARED REMOTE CONTROL SIGNAL ANALYSIS


Figure 5. It is made up microcontroller software will need to
CODE 1 of 34 pulses — if you be written in order to capture and
START: include the last one — analyze the IR packet.
PULSIN IR_DETECT,ACTIVE_HIGH,IR_PULSE(0) that represent bits. The software examples are
IF IR_PULSE(0) = 0 THEN START As you can see, the given in the PicBasic Pro language
FOR I = 1 TO 33 large amount of time developed by microEngineering Labs
PULSIN IR_DETECT,ACTIVE_HIGH,IR_PULSE(I) (relatively speaking) (www.melabs.com) for Microchip
NEXT I of 9.2 ms goes by Technology’s powerful Picmicro micro-
with the output being controllers. The PicBasic Pro compiler is
low (0 volts) before “BASIC Stamp II-like” and has most of
CODE 2 the first pulse. This the libraries and functions of both
indicates the start of the BASIC Stamp I and II. Being a true
HIGH LED the transmission. compiler, programs execute much
FOR I = 0 TO 33 The first pulse in faster than their interpreted Stamp
IF IR_PULSE(I) > 150 THEN the packet is much equivalents.
SEROUT COM,COM_BAUD,[“PULSE “, #I, “ - “, wider (4.2 ms) than You will also need a hardware
#(IR_PULSE(I) * 53) / 10, “ US = 1”] those that follow and programmer — such as the EPIC Plus
ELSE will be used by the programmer, also available at
SEROUT COM,COM_BAUD,[“PULSE “, #I, “ - “, microcontroller soft- www.melabs.com — to program the
#(IR_PULSE(I) * 53) / 10, “ US = 0”] ware to trigger the PIC with the .HEX files that are
ENDIF measuring and storing generated by the compiler. I also use a
SEROUT COM,COM_BAUD,[13,10] of the width values of free integrated development environ-
NEXT I each pulse in the pack- ment called MicroCode Studio
LOW LED et. All of the pulses (www.mecanique.co.uk) because it
that follow are 5 volts makes editing, compiling, and pro-
and either have a gramming PIC microcontrollers easier.
Figure 6. Pulse timing values and their binary width of approximately One of the nice features of MicroCode
representations. 0.4 ms or 1.6 ms, except Studio is the serial communications
for the last pulse. window that will be used to display the
The space between signal analysis data.
each pulse is 0 volts and is
consistently 0.7 ms. The 0 Capturing and
volt, 0.7 ms space is a
marker to differentiate
Storing the Signal
between each bit. The The PicBasic Pro code segments
5 volt pulses that are will be listed for each of the functions
0.4 ms wide represent as they are discussed and then the
logic zero (0) and the entire program will be listed at the end
pulses that are 1.6 ms of the article.
wide represent logic one The first thing that the microcon-
(1). With the help of troller IR analysis program needs to do
the oscilloscope, we now is to determine the start of an IR pack-
know exactly what et transmission. This is done by moni-
toring for the first high
CODE 3 pulse on the output of
the PNA 4602M, as
HIGH LED shown in Figure 5. The
FOR I = 0 TO 33 PULSIN command is look-
IF IR_PULSE(I) > 150 THEN ing to measure the width
SEROUT COM,COM_BAUD,[“1”] of a pulse and — since the
ELSE output is constantly high
SEROUT COM,COM_BAUD,[“0”] — PULSIN returns a value
ENDIF of 0 when there is no
NEXT I activity. As soon as the
SEROUT COM,COM_BAUD,[13,10] start of the transmission
LOW LED has been detected, the
program will measure the
54 SERVO 01.2005

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.


Williams.qxd 12/8/2004 9:49 AM Page 55

INFRARED REMOTE CONTROL SIGNAL ANALYSIS


width of each of the
following pulses CODE 4
and then store ‘ OUTPUT ALL BITS IN THE PACKET
these values in an
array variable that HIGH LED
we will call FOR I = 0 TO 33
IR_pulse(33). The IF IR_PULSE(I) > 150 THEN
PicBasic Pro code SEROUT COM,COM_BAUD,[“1”]
segment is shown in ELSE
Code 1. SEROUT COM,COM_BAUD,[“0”]
Now that the ENDIF
pulse width infor- NEXT I
mation has been SEROUT COM,COM_BAUD,[13,10]
stored in the array, a
routine will deter- ‘ CONVERT BITS 15 THROUGH 23 TO A DECIMAL
mine the timing VALUE
values of each
pulse, decide RESULT = 0
whether each pulse POWER = 1
represents either FOR I = 0 TO 8
logic “1” or logic IF IR_PULSE(15 + I) > 150 THEN
“0,” and output the RESULT = RESULT + POWER
results to the serial ENDIF
c o m mu n i c a t i o n s
POWER = POWER * 2
window on the PC.
NEXT I
The light emitting
SEROUT COM,COM_BAUD,[“ = “,#RESULT,13,10]
diode (LED) will be
LOW LED
turned on at the
RETURN
beginning of the
routine and turned
off when it completes so that the user baud rate of 2400, parity Figure 7. Binary packet information with decimal
is aware that a packet is being = none, byte size = 8, and equivalents of bits 15 through 23.
processed. One thing to note is that stop bits = 1. In order to
the PicBasic Pro PULSIN command advance the cursor to the next line in changed from one packet to the other.
calculates its values assuming that the the communications receive window, Once a complete list of key values is
processor is clocked at 4 MHz. the numbers 13 and 10 decimal output to the communications window,
Since we are using an 8 MHz are transmitted after each line of it is easy to see from the binary
clock, the timing values that have been output. This corresponds to the ASCII patterns that bits 15 through 23 pro-
obtained are smaller than the actual carriage return and new line duce unique values for each key
times. This means that — for a .4 ms characters (CR and NL), respectively. pressed on the remote control. To
time — a value of approximately 76 is Figure 6 is a screen shot of the make life easier, bits 15 through 23 are
returned by PULSIN and a value of 302 communications window displaying converted to decimal values. Bits 0
is returned for a 1.6 ms pulse. To the output produced by the routine in through 14 remain consistent for most
get the proper measurements in Code 2 when the “1” key is pressed on of the keys and are probably used to
microseconds, those values will need to the Sanyo remote. identify which device the signal is
be multiplied by 5.3. The 5.3 multiplier The next step will be to capture meant to control. The next code seg-
was determined so that the PIC timing and display the binary packet values ment will display the binary values of the
values correspond to the accurate transmitted for each of the buttons entire packet — along with the decimal
oscilloscope timing values of the pulses on the remote control so that we can equivalent of bits 15 through 23, with
and to compensate for the actual analyze and determine which bits can bit 15 being the least significant bit.
oscillator frequency. be used to control a robot or device. The output produced by this routine is
Because PicBasic can’t perform Code 3 will output all of the bits in shown in the code in Figure 7.
floating point math and I wanted the packet to the communications The decimal values that are
better precision for the timing values, window. I transmitted the codes for derived from the bits in the packet can
I used the technique of multiplying by all of the keys on the remote so that I now be used to control a robot or any
53 then dividing the result by 10. Set could visually determine which bits other application that needs close
up a communications terminal with a were consistent and which ones proximity remote control. If you plan
SERVO 01.2005 55

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.


Williams.qxd 12/8/2004 9:50 AM Page 56

INFRARED REMOTE CONTROL SIGNAL ANALYSIS


on using only the television controls on array, convert the useable bits to a remote is called ir-decode.bas and is
the remote, then bits 25 through 28 decimal value, and then use that listed in Code 5. It can be used as a
can be used to create unique values — value to determine what events you starting point when writing routines
that’s only four bits! want to occur by using an for other remotes. The PicBasic
To summarize, all you need to do IF..THEN..ELSE..ENDIF or SELECT CASE program and the HEX file to program
to control a device with an IR remote is decision statement. The entire program the PIC 16F819 can be downloaded at
to capture the packet information in an to analyze the packets from a Sanyo www.thinkbotics.com SV

CODE 5
‘————————————————————————- GOTO START
‘ NAME : IR-DECODE.BAS
‘ COMPILER : PICBASIC PRO - MICROENGINEERING LABS ‘———————- DISPLAY PULSE STREAM ————————
‘ NOTES : IR REMOTE CONTROL DECODING PROGRAM
‘ AUTHOR : KARL P. WILLIAMS DISPLAY_PULSE:
‘————————————————————————- HIGH LED
FOR I = 0 TO 33
@ DEVICE PIC16F819, INTRC_OSC_NOCLKOUT, WDT_OFF, IF IR_PULSE(I) > 150 THEN
LVP_OFF, PWRT_ON, PROTECT_OFF, BOD_OFF SEROUT COM,COM_BAUD,[“1”]
ELSE
INCLUDE “MODEDEFS.BAS” SEROUT COM,COM_BAUD,[“0”]
ENDIF
TRISA = %00011111 NEXT I
TRISB = %00000001 SEROUT COM,COM_BAUD,[13,10]
DEFINE OSC 8 LOW LED
OSCCON = $70 RETURN

‘———— CONVERT USEABLE BITS DECIMAL VALUE ————-


IR_DETECT VAR PORTB.0
COM VAR PORTB.1 CONVERT_BITS:
LED VAR PORTB.2 HIGH LED
COM_BAUD CON N2400 RESULT = 0
IR_PULSE VAR WORD(33) POWER = 1
ACTIVE_LOW CON 0 FOR I = 0 TO 8
ACTIVE_HIGH CON 1 IF IR_PULSE(15 + I) > 150 THEN
RESULT VAR WORD RESULT = RESULT + POWER
I VAR BYTE ENDIF
POWER VAR WORD POWER = POWER * 2
NEXT I
LOW LED SEROUT COM,COM_BAUD,[“BITS 15 TO 23 = “,#RESULT,” DECI-
MAL”,13,10,13,10]
‘———- WAIT FOR START OF PACKET TRANSMISSION ———- LOW LED
RETURN
START:
‘—————— DISPLAY PULSE TIMING VALUES ——————-
PULSIN IR_DETECT,ACTIVE_HIGH,IR_PULSE(0)
IF IR_PULSE(0) = 0 THEN START PULSE_TIMING:
HIGH LED
‘——————— INPUT PULSE STREAM —————————- FOR I = 0 TO 33
IF IR_PULSE(I) > 150 THEN
FOR I = 1 TO 33 SEROUT COM,COM_BAUD,[“PULSE “, #I, “ - “,
PULSIN IR_DETECT,ACTIVE_HIGH,IR_PULSE(I) #(IR_PULSE(I) * 53) / 10, “ US = 1”]
NEXT I ELSE
SEROUT COM,COM_BAUD,[“PULSE “, #I, “ - “,
‘———————- CALL SUBROUTINES —————————— #(IR_PULSE(I) * 53) / 10, “ US = 0”]
ENDIF
GOSUB PULSE_TIMING SEROUT COM,COM_BAUD,[13,10]
GOSUB DISPLAY_PULSE NEXT I
GOSUB CONVERT_BITS LOW LED
RETURN

56 SERVO 01.2005

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

You might also like