Sie sind auf Seite 1von 6

by Karl Williams

Many robotics experimenters build small robots or devices that are intended to stay within the limits of a room in a house

or school. An inexpensive way to remotely control these machines is to use a television infrared remote control transmitter.

SERVO 01.2005 51

INFRARED REMOTE CONTROL SIGNAL ANALYSIS

INFRARED REMOTE CONTROL SIGNAL ANALYSIS Figure 1. A variety of infrared remote control transmitters. Most of

Figure 1. A variety of infrared remote control transmitters.

Most of the published literature focuses on using the Sony 12-bit protocol. I think the reason for this is because Sony uses a 12-bit standard without any error checking, making it easy to decode. I already have a lot of IR remote control transmitters lying around the house that have outlived their AV units, but none of them is from Sony — not to mention the three remotes in the living room for my television, VCR, and DVD player (Figure 1) that I could use for experimenting. This article will focus on analyzing the signals generated by standard 38 kHz IR transmitters and then deter- mining what information contained in

Figure 2. Information coding methods employed by infrared remote systems.

coding methods employed by infrared remote systems. those signals is useful for controlling small robots or

those signals is useful for controlling small robots or devices. Infrared remote controls use anywhere from 12 to 60 bits when transmitting codes. As you will see later in the article, only 8-10 of these bits are usually needed when controlling a robot. If you plan on using only the television controls on the remote, then as little as four bits of the information is necessary.

is used by Panasonic. The shift coded scheme uses the direction of transition (phase) of the signal to represent the data and all bits have a constant time period. In the shift coded scheme, a binary 0 is represented by the signal switching from high to low within a constant time period. A binary 1 is represented by the signal shifting from low to high within a time period. The shift coded protocol is known as RC-5 and is used by Philips. The most common technique and the one that we will investigate is known as Pulse Width Modulation (PWM). This method works by varying the duration of the ON or OFF periods of the modulated infrared. In order to control a device, a unique number representing the key that has been pressed on the remote and possibly information about which device this key is intended to control needs to be sent. This is done by representing the number in binary or base 2. In binary, there are only two digits — 0 and 1 — to deal with. Therefore, only two distinct “pulse widths” are needed to represent

each digit. This simplifies the process considerably. Using this scheme, the periods of ON and OFF will need to alternate. If they didn’t, it would be impossible to judge their widths. Either the width of the ON period or the width of the OFF period will vary, depending on the manufacturer. In summary, IR transmis- sions most often take place by varying the ON/OFF times of an IR emitter to represent binary numbers according to an established pattern. All that needs to be done is to capture

the entire signal, measure the width of each pulse, and then decode the pattern.

Infrared Signals and How They Work

IR remote control operates by modulating (turning on and off) an

infrared (IR) light source. Infrared light is located on the electromagnetic spectrum just below the visible light that our eyes can see. The rate at which the modulation occurs is called the carrier frequency. This is done to provide a transmission system that allows operation in noisy lighting environments. The remote control information is placed on the carrier using several different techniques, depending on the manufacturer. Three of the methods used are pulse coded, space coded, and shift coded, as illustrated in Figure 2.

With the space coded method, data is represented by varying the space (amount of time) between pulses. The space coded protocol is known as REC-80 and

Figure 3. PNA4602M and TRM1038 infrared receiver modules.

Figure 3. PNA4602M and TRM1038 infrared receiver modules. Analyzing an Infrared Remote Control Signal the infrared

Analyzing an Infrared Remote Control Signal

the

infrared packet being transmitted by the remote

To

capture

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

signal is present, the detector’s output is high. Because I had a Sanyo IR remote around, I decided to decode the signals that it produces to show an alternative to using the Sony codes. Hopefully, the information that follows will let you use all of those non-Sony remotes that are piling up. To analyze the signals that are being received by the PNA4602M IR module, an oscilloscope will be used along with a Microchip PIC 16F819 microcontroller that is clocked at 8 MHz internally. The PIC 16F819 will be interfaced to a personal computer through the serial port of the PC. The microcontroller will receive and store the incoming infrared packets from the PNA4602M IR module and then per- form an analysis of each signal based on the internal software

that will be written. 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

emerging. While single chip RS- 232 level converters are Figure 4. Infrared decoding circuit schematic diagram.

Figure 4. Infrared decoding circuit schematic diagram.

common and inexpensive — thanks to current RS-232 implementation and the excellent I/O specifications of the PICmicro MCU — most applications

don’t require level converters. Rather,

be

used when transmitting from the PICmicro to the computer. A 1K current limiting resistor is suggested, but not necessary.

The infrared decoding circuit schematic (Figure 4) is simple enough to construct on an experimenter’s breadboard. When the circuit is wired, attach the circuit to the computer’s serial port using a straight through serial cable. Attach the channel 1 oscilloscope probe to the output pin of the PNA4602M module, as indicated

inverted TTL (N300

N9600)

can

in Figure 4. I use a Tektronix TDS 210

two channel, 60 MHz oscilloscope.

Set channel 1 to 2 volts per division,

a horizontal time of 10 ms, and the

trigger mode to single. If you need more information about how to use an oscilloscope, then check out the excellent oscilloscope tutorial on the Tektronics website ( www.tektronix.com/ Measurement/App_Notes/XYZs/). Before writing a signal analysis program for the microcontroller, let’s take a look at the signal being transmit- ted from the Sanyo remote control using an oscilloscope. Apply power to the circuit and set the oscilloscope as described above. Pressing the “1” key produces the waveform shown in

Figure 5. Waveform produced by pressing the “1” key on the Sanyo remote.

the waveform shown in Figure 5. Waveform produced by pressing the “1” key on the Sanyo

SERVO 01.2005 53

INFRARED REMOTE CONTROL SIGNAL ANALYSIS

CODE 1

START:

PULSIN IR_DETECT,ACTIVE_HIGH,IR_PULSE(0) IF IR_PULSE(0) = 0 THEN START FOR I = 1 TO 33 PULSIN IR_DETECT,ACTIVE_HIGH,IR_PULSE(I) NEXT I

CODE 2

HIGH LED FOR I = 0 TO 33 IF IR_PULSE(I) > 150 THEN SEROUT COM,COM_BAUD,[“PULSE “, #I, “ - “, #(IR_PULSE(I) * 53) / 10, “ US = 1”] ELSE SEROUT COM,COM_BAUD,[“PULSE “, #I, “ - “, #(IR_PULSE(I) * 53) / 10, “ US = 0”] ENDIF SEROUT COM,COM_BAUD,[13,10] NEXT I LOW LED

Figure 6. Pulse timing values and their binary representations.

6. Pulse timing values and their binary representations. Figure 5. It is made up of 34

Figure 5. It is made up of 34 pulses — if you include the last one — that represent bits. As you can see, the large amount of time (relatively speaking) of 9.2 ms goes by with the output being low (0 volts) before the first pulse. This indicates the start of the transmission. The first pulse in the packet is much wider (4.2 ms) than those that follow and will be used by the microcontroller soft- ware to trigger the measuring and storing of the width values of each pulse in the pack- et. All of the pulses that follow are 5 volts

and either have a width of approximately 0.4 ms or 1.6 ms, except for the last pulse. The space between each pulse is 0 volts and is consistently 0.7 ms. The 0 volt, 0.7 ms space is a marker to differentiate

between each bit. The 5 volt pulses that are 0.4 ms wide represent logic zero (0) and the pulses that are 1.6 ms wide represent logic one (1). With the help of the oscilloscope, we now know exactly what

microcontroller software will need to be written in order to capture and analyze the IR packet. The software examples are given in the PicBasic Pro language developed by microEngineering Labs (www.melabs.com) for Microchip Technology’s powerful Picmicro micro- controllers. The PicBasic Pro compiler is “BASIC Stamp II-like” and has most of the libraries and functions of both the BASIC Stamp I and II. Being a true compiler, programs execute much faster than their interpreted Stamp equivalents. You will also need a hardware programmer — such as the EPIC Plus programmer, also available at www.melabs.com — to program the PIC with the .HEX files that are generated by the compiler. I also use a free integrated development environ- ment called MicroCode Studio (www.mecanique.co.uk) because it makes editing, compiling, and pro- gramming PIC microcontrollers easier. One of the nice features of MicroCode Studio is the serial communications window that will be used to display the signal analysis data.

Capturing and Storing the Signal

The PicBasic Pro code segments will be listed for each of the functions as they are discussed and then the

entire program will be listed at the end of the article. The first thing that the microcon- troller IR analysis program needs to do is to determine the start of an IR pack- et transmission. This is done by moni- toring for the first high

pulse on the output of the PNA 4602M, as shown in Figure 5. The PULSIN command is look- ing to measure the width of a pulse and — since the output is constantly high — PULSIN returns a value of 0 when there is no activity. As soon as the start of the transmission has been detected, the program will measure the

CODE 3

HIGH LED FOR I = 0 TO 33 IF IR_PULSE(I) > 150 THEN SEROUT COM,COM_BAUD,[“1”] ELSE SEROUT COM,COM_BAUD,[“0”] ENDIF NEXT I SEROUT COM,COM_BAUD,[13,10] LOW LED

INFRARED REMOTE CONTROL SIGNAL ANALYSIS

width of each of the following pulses and then store these values in an array variable that

we

IR_pulse(33). The PicBasic Pro code segment is shown in Code 1. Now that the pulse width infor- mation has been stored in the array, a routine will deter- mine the timing values of each pulse, decide whether each pulse represents either logic “1” or logic “0,” and output the results to the serial communications window on the PC. The light emitting diode (LED) will be turned on at the beginning of the

routine and turned off when it completes so that the user is aware that a packet is being processed. One thing to note is that the PicBasic Pro PULSIN command calculates its values assuming that the processor is clocked at 4 MHz. Since we are using an 8 MHz clock, the timing values that have been obtained are smaller than the actual times. This means that — for a .4 ms time — a value of approximately 76 is returned by PULSIN and a value of 302 is returned for a 1.6 ms pulse. To get the proper measurements in microseconds, those values will need to be multiplied by 5.3. The 5.3 multiplier was determined so that the PIC timing values correspond to the accurate oscilloscope timing values of the pulses and to compensate for the actual oscillator frequency. Because PicBasic can’t perform floating point math and I wanted better precision for the timing values, I used the technique of multiplying by 53 then dividing the result by 10. Set up a communications terminal with a

CODE 4

‘ OUTPUT ALL BITS IN THE PACKET

HIGH LED FOR I = 0 TO 33 IF IR_PULSE(I) > 150 THEN SEROUT COM,COM_BAUD,[“1”] ELSE SEROUT COM,COM_BAUD,[“0”] ENDIF NEXT I SEROUT COM,COM_BAUD,[13,10]

‘ CONVERT BITS 15 THROUGH 23 TO A DECIMAL VALUE

RESULT = 0 POWER = 1 FOR I = 0 TO 8 IF IR_PULSE(15 + I) > 150 THEN RESULT = RESULT + POWER ENDIF POWER = POWER * 2 NEXT I SEROUT COM,COM_BAUD,[“ = “,#RESULT,13,10] LOW LED RETURN

SEROUT COM,COM_BAUD,[“ = “,#RESULT,13,10] LOW LED RETURN Figure 7. Binary packet information with decimal

Figure 7. Binary packet information with decimal equivalents of bits 15 through 23.

changed from one packet to the other. Once a complete list of key values is output to the communications window, it is easy to see from the binary patterns that bits 15 through 23 pro- duce unique values for each key pressed on the remote control. To make life easier, bits 15 through 23 are converted to decimal values. Bits 0 through 14 remain consistent for most of the keys and are probably used to identify which device the signal is meant to control. The next code seg- ment will display the binary values of the entire packet — along with the decimal equivalent of bits 15 through 23, with bit 15 being the least significant bit. The output produced by this routine is shown in the code in Figure 7. The decimal values that are derived from the bits in the packet can now be used to control a robot or any other application that needs close proximity remote control. If you plan

SERVO 01.2005 55

will

call

baud rate of 2400, parity = none, byte size = 8, and

stop bits = 1. In order to advance the cursor to the next line in the communications receive window, the numbers 13 and 10 decimal are transmitted after each line of output. This corresponds to the ASCII carriage return and new line characters (CR and NL), respectively. Figure 6 is a screen shot of the communications window displaying the output produced by the routine in Code 2 when the “1” key is pressed on the Sanyo remote. The next step will be to capture and display the binary packet values transmitted for each of the buttons on the remote control so that we can analyze and determine which bits can be used to control a robot or device. Code 3 will output all of the bits in the packet to the communications window. I transmitted the codes for all of the keys on the remote so that I could visually determine which bits were consistent and which ones

INFRARED REMOTE CONTROL SIGNAL ANALYSIS

on using only the television controls on the remote, then bits 25 through 28 can be used to create unique values — that’s only four bits! To summarize, all you need to do to control a device with an IR remote is to capture the packet information in an

array,

convert

the

useable

bits

to

a

remote is called ir-decode.bas and is listed in Code 5. It can be used as a starting point when writing routines for other remotes. The PicBasic program and the HEX file to program the PIC 16F819 can be downloaded at www.thinkbotics.com SV

decimal

value,

and

then

use

that

value to determine what events you

want

to

occur

by

using

an

IF

THEN

ELSE

ENDIF

or SELECT CASE

decision statement. The entire program to analyze the packets from a Sanyo

 

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 IF IR_PULSE(I) > 150 THEN SEROUT COM,COM_BAUD,[“1”] ELSE SEROUT COM,COM_BAUD,[“0”] ENDIF NEXT I SEROUT COM,COM_BAUD,[13,10] LOW LED RETURN

@ DEVICE PIC16F819, INTRC_OSC_NOCLKOUT, WDT_OFF, LVP_OFF, PWRT_ON, PROTECT_OFF, BOD_OFF

INCLUDE “MODEDEFS.BAS”

TRISA = %00011111 TRISB = %00000001 DEFINE OSC 8 OSCCON = $70

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

IR_DETECT

VAR PORTB.0

COM

VAR PORTB.1

CONVERT_BITS:

LED

VAR PORTB.2

HIGH LED RESULT = 0 POWER = 1 FOR I = 0 TO 8 IF IR_PULSE(15 + I) > 150 THEN RESULT = RESULT + POWER ENDIF POWER = POWER * 2 NEXT I SEROUT COM,COM_BAUD,[“BITS 15 TO 23 = “,#RESULT,” DECI-

COM_BAUD

CON N2400

IR_PULSE

VAR WORD(33)

ACTIVE_LOW CON 0 ACTIVE_HIGH CON 1

RESULT

VAR WORD

I

VAR BYTE

POWER

VAR WORD

LOW LED

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:

‘——————— INPUT PULSE STREAM —————————-

HIGH LED FOR I = 0 TO 33 IF IR_PULSE(I) > 150 THEN SEROUT COM,COM_BAUD,[“PULSE “, #I, “ - “, #(IR_PULSE(I) * 53) / 10, “ US = 1”] ELSE SEROUT COM,COM_BAUD,[“PULSE “, #I, “ - “, #(IR_PULSE(I) * 53) / 10, “ US = 0”] ENDIF SEROUT COM,COM_BAUD,[13,10] NEXT I LOW LED RETURN

FOR I = 1 TO 33 PULSIN IR_DETECT,ACTIVE_HIGH,IR_PULSE(I) NEXT I

‘———————- CALL SUBROUTINES ——————————

GOSUB PULSE_TIMING GOSUB DISPLAY_PULSE GOSUB CONVERT_BITS