Text preview for : E021062.pdf part of Elector IR remote ,receiver and RC5 transmitter



Back to : E021062.pdf | Home

COMPUTER

Infrared Transceiver for the PC (1)
combined remote control and data link
Design by B. Kainka

This article does more than just describe an IR transceiver that you can use with your PC for remote control and data transfer. Based on the successful Elektor Electronics `PC Peripheral Design' series, it also provides information about the principles of the infrared transfer technique used and interface technology, which you can use for your own projects.
that appeared in the `PC Serial peripheral Design' course (Elektor Electronics 9/2000 through 3/2001). Infrared remote controls for television sets, video recorders and other entertainment electronics devices frequently use the Philips RC5 standard. It is easy to determine whether a particular remote control employs RC5 by using the program described in this article. This standard employs light signals modulated at a frequency in the range of 30 to 40 kHz. The remote control unit transmits `bursts', which are individual pulse packets. In our case, these bursts have a duration of either 0.888 ms or 1.776 ms. At a modulation frequency of 36 kHz, a short burst contains 32 individual pulses, while a long burst contains 64 pulses. A complete data packet has a duration of approximately 25 ms and is repeated every 100 ms as long as a button is held depressed. An infrared remote control unit can easily be used for other purposes. For example, it can be used to control certain functions of your own program. A typical application is

Infrared data transfer is becoming increasingly more important. Television remote controls use infrared light, but so do PC mice, keyboards, printers and other peripherals. Infrared light is also used in fibre-optic

cables. In a sense, the PC infrared transceiver presented here is a practical application that represents a continuation of the series of articles on PC interfaces and Visual Basic

62

Elektor Electronics

1/2002

COMPUTER
D2

IC1 78L05

IR Transceiver
R1 4k7 R2 4k7 C2 100n

D1

2x 1N4148 K1
1 6 2 7 3 8 4 9 5 GND D7 RxD RTS TxD CTS DTR D6 4µ7

C1 25V

IC3
T1 R3 100k 1 3

BC547

2

R8 22 C5

TSOP1836

DB9

D3

2x 1N4148

Technical specifications ­ Reception frequency: 30, 33 or 36 kHz, depending on the IC version fitted ­ Transmission frequency: 30­40 kHz, continuously adjustable ­ Power supply: from the serial interface ­ Range: approx. 10 m ­ IR receiver: for remote control per the RC5 standard ­ IR transmitter: RC5 compatible ­ IR data transceiver: serial data, 2400 baud max.



25V

1N4148
R7 1k C4 22n R5 4k7 D5

D4 P1 2k5 R4 470 7 DIS 8 4 R

1

2

3

IC1
6 2 C3 1 10n THR TR

OUT

3 R6 27k T2

T3

555
CV 5

BC337

BC547
010052 - 11

Figure 1. Schematic diagram of an IR transceiver for connection to the serial interface of a PC.

controlling a PC slide show. After starting the program, you can sit back and operate everything from where you are sitting.

Transceiver hardware
Thanks to the availability of integrated receivers, the reception of standard infrared signals is relatively simple. The well-known Siemens SHF506 is available with fixed modulation frequencies of 30 kHz, 33 kHz, 36 kHz and so on. The filter curve is relatively broad-band, so deviations of a few kilohertz cause only a relatively small reduction in sensitivity. The Vishai/Telefunken TSOP1836 is a similar IC. Both types of IC need only a 5-V supply voltage and draw less than 2 mA. They can thus be powered directly from the PC serial interface. The IR transceiver described here has a modulated IR transmitter in addition to the receiver. This light transmitter works with a carrier fre-

quency between 30 and 40 kHz. It can be used for the remote control of devices such as video recorders and television sets, but it can also be used for data transfer between two PCs. The schematic diagram shown in Figure 1 reveals the receiver IC (IC3) and a 78L05 voltage regulator (IC1). The supply voltage is taken from the DTR and RTS outputs of the RS232 interface, which are connected together via the isolating diodes D1 and D2. A voltage of around 10 V can be activated here using a program running on the PC. These two leads also power the transmitter portion of the circuit via D6 and D7. Since high pulse currents are needed for transmitting, a relatively large electrolytic capacitor (IC1, 4.7 µF) is used to smooth the input voltage of the voltage regulator. If the IR receiver IC receives an infrared signal modulated at 36 kHz, it produces an output signal on its middle pin with an active-low level.

These output pulses are connected directly to the CTS lead, where they must be decoded using software. A supplementary pull-up resistor is necessary here, since the CTS lead has a relatively low input resistance. The signal is also inverted by a transistor stage (T1) and applied to the RxD input of the serial interface. This lead serves for the reception of fast data, for example from a data link between two PCs. The infrared transmitter consists of a modulation stage (IC2) and a pulse amplifier (T2 and T3) driving two infrared diodes (D4 and D5). IC2 is a 555 timer IC wired as an oscillator, which generated narrow negative pulses with a width of around 2 µs. The frequency can be set between approximately 30 and 40 kHz using P1. Depending on the application, the trimpot can be used to tune the circuit to the suitable frequency in order to achieve the greatest possible range. The 555 receives its supply voltage from the TXD lead, which modulates (`keys') the transmitter by switching it on and off. The energy for the two IR transmitter diodes also comes from the serial interface. The DTR and RTS leads charge a 1-µF electrolytic capacitor (C5) via D6 and D7. The brief pulses on the output of the timer IC (pin 3) force the driver stage consisting of T2 and T3 into full conduction. This results in pulsed currents of approximately 200­300 mA. The range that is thus achieved is around 10 m. Although the charging current from the serial interface is relatively small at 40 mA, there is enough time between the pulses to allow the capacitor to recharge. This simple hardware can be constructed using the printed circuit board shown in Figure 2. All that you need to watch out for when fitting the components is to make sure that the diodes, electrolytic capacitors and ICs are soldered in or inserted the right way around. You should also avoid the common

1/2002

Elektor Electronics

63

COMPUTER
mistake of using a sub-D socket (9 holes) instead of a sub-D plug (9 pins).
T3
G1

T2

C3 P1

010052-1 C5

K1

D4

C4 R8 R6 R5 IC2 R4 R7 R1 IC1 R2 R3 C1 D2 D7 D3 D6

RD5 software decoder
The data output of the receiver IC is connected directly to the CTS lead. Signals from a remote control unit that have been demodulated by the receiver IC thus appear on this lead. A program for decoding the signal only has to evaluate the incoming pulses in order to recognise which button has been pressed on the remote control. Figure 3 shows a signal received from a RC5 remote control unit. The diagram was captured using a logic analyser. A program directly records the changes of the signal level on the CTS lead. The RC5 protocol uses what is called a `bi-phase' signal, with the actual information being contained in the phase changes. The signal level changes at least every 1.776 ms. The receiver can continuously resynchronise to the signal by means of these changes. The signal begins with a start sequence that is always the same. Following this come three data regions, in which level changes spaced 1.776 ms apart represent the actual data bits. Following each level change, the receiver first waits for slightly longer than 0.888 ms and skips any level change that may occur in this interval. The next following level change is both a synchronisation signal and a data bit. In principle, this technique can be used to transfer data words of any desired length. In the case of RC5 signals, the word length is exactly 12 bits, composed a follows: · The Control Bit (Ctl) changes between 0 and 1 each time a button is pressed. The receiver can use this information to decide whether a button has been pressed and held only once or has been pressed several times in succession. · The Device Address (Addr) consists of five bits, with the most significant bit being transmitted first. Some standard device addresses are `1' for a television set and `5' for a video recorder. The Device Address allows several different remote controls to be used in the same room. · The Data Region (Dat) consists of six bits for up to 64 different buttons. The number buttons (0­9) generate the codes `0' through `9'. Here again the most significant bit is transmitted first. Listing 1 shows the actual software decoder program in Visual Basic. The routine `RC5' receives the data. Here the PORT.DLL from the book PC Interfaces under Windows is used for all accesses to the serial interface and for timing control. (PORT.DLL can be downloaded free of charge from the Elektor
IC3

D5

G

T1 C2

1-250010 010052-1

D1

Figure 2. Printed circuit board layout and component layout for the IR transceiver (board not available ready-made).

COMPONENTS LIST
Resistors: R1,R2,R5 = 4k7 R3 = 100k R4 = 470 R6 = 27k R7 = 1k R8 = 22 P1 = 2k5 preset Capacitors: C1 = 4µF7 25V radial C2 = 100nF C3 = 10nF

C4 = 22nF C5 = 1µF 25V radial Semiconductors: D1,D2,D3,D6,D7 = 1N4148 D4,D5 = IR-LED, e.g. LD271 T1,T2 = BC547 T3 = BC337 IC1 = 78L05 IC2 = 555 IC3 = TSOP1836, SFH506-36 Miscellaneous: K1 = 9-way Sub-D socket (female), angled pins, PCB mount

64

Elektor Electronics

(C) ELEKTOR

ROTKELE )C(

1/2002

COMPUTER
Listing 1
Receiving and displaying RC5 data
Dim Ctr Dim Adr Dim Dat Sub RC5Error() Ctr = -1 Adr = -1 Dat = -1 End Sub Function RC5Bit() As Integer TIMEINITUS If CTS = 0 Then While ((TIMEREADUS < 500) And (CTS = 0)) Wend If TIMEREADUS > 499 Then RC5Error DELAYUS 444 If CTS = 0 Then RC5Error RC5Bit = 0 Else While ((TIMEREADUS < 500) And (CTS = 1)) Wend If TIMEREADUS > 499 Then RC5Error DELAYUS 444 If CTS = 1 Then RC5Error RC5Bit = 1 End If End Function Sub RC5() Ctr = 0 Adr = 0 Dat = 0 Startbit = False REALTIME True TIMEINIT While Not Startbit While (CTS = 1) And (TIMEREAD < 500) Wend Startbit = True DELAYUS 444 If CTS = 1 Then Startbit = False DELAYUS 888 If CTS = 0 Then Startbit = False DELAYUS 888 If CTS = 1 Then Startbit = False Adr = Startbit If TIMEREAD > 499 Then Startbit = True Wend DELAYUS 888 Ctr = RC5Bit Adr = 0 For N = 1 To 5 DELAYUS 888 Adr = Adr * 2 Adr = Adr + RC5Bit Next N Dat = 0 For N = 1 To 6 DELAYUS 888 Dat = Dat * 2 Dat = Dat + RC5Bit Next N REALTIME (False) End Sub Private Sub Form_Load() OPENCOM "COM2" DTR 1 RTS 1 End Sub Private Sub Form_Unload(Cancel As Integer) CLOSECOM End Sub Private Sub Timer1_Timer() RC5 Text1.Text = Str$(Ctr) + " " + Str$(Adr) + " " + Str$(Dat) End Sub

Electronics website; see the note at the end of the article.) This task is relatively time-critical and requires the use of REALTIME=True. This

routine initially waits for a low level, which acts as a start pulse. In order to prevent the PC from hanging in an infinite loop if no signal is present, a

timeout condition is built in. If no signal has been received after 500 ms, the program terminates with an error message. Infrared controls are always subject to

Listing 2
Loading pictures for a slide show
Private Sub RC5 If Dat <> If Dat = If Dat = If Dat = If Dat = If Dat = If Dat = If Dat = If Dat = If Dat = End If Dat_old = End Sub Timer1_Timer() Dat_old Then 1 Then Picture1.Picture 2 Then Picture1.Picture 3 Then Picture1.Picture 4 Then Picture1.Picture 5 Then Picture1.Picture 6 Then Picture1.Picture 7 Then Picture1.Picture 8 Then Picture1.Picture 9 Then Picture1.Picture Dat

= = = = = = = = =

LoadPicture("D:\Homepage\Bast11.jpg") LoadPicture("D:\Homepage\Bast21.jpg") LoadPicture("D:\Homepage\Bast31.jpg") LoadPicture("D:\Homepage\Bast41.jpg") LoadPicture("D:\Homepage\Bast51.jpg") LoadPicture("D:\Homepage\Bast61.jpg") LoadPicture("D:\Homepage\Bast71.jpg") LoadPicture("D:\Homepage\Bast81.jpg") LoadPicture("D:\Homepage\Bast91.jpg")

1/2002

Elektor Electronics

65

COMPUTER
interference from other light sources. Fluorescent lamps, which generate rapidly flickering light, are typical interference sources. The RC5 reception routine thus checks the start sequence of the received signal to verify that it is correct. If the signal departs from the expected pulse sequence, an interference pulse must be involved. In this case, the routine waits for the next start sequence. This makes it possible to securely receive RC5 signals, even in an environment with a relatively high level of interference. After the start sequence, the individual bits are read by the routine `RC5bit'. If a 0 level is read at the start of the routine, this should represent a 0 bit. Next, the routine waits for the signal level to change. After half the pulse width (444 µs), a new query is made to see whether the same level is still present. If this is not the case, an error is detected and all data read up to this point are
Start Ctrl Address Data

1

0

0

1

0

1

0

0

0

1

1

1

010052- 12

Figure 3. Sample RC5 signal with address `5' and button `7' pressed.

Figure 4. Outputting RC5 data.

guish usable data from unusable data. You can use this program to familiarise yourself with the individual codes of your own remote control unit. This can form the basis for later control applications in which the PC replaces a remote control unit. Complete lists of the commonly used codes can be found on the Internet.

load pictures from the hard disk. The fact that this program supports only nine pictures may come as a relief to those of you who have suffered through seemingly endless slide shows, but there is nothing to prevent this number from being increased. For example, you could use the `+' and `­` buttons to control the slide sequence.
(010052-1)

PC remote control
Another useful application is remote control of the PC. For example, you could control your own slide show using a remote control unit. Listing 2 shows a program segment with the modified timer routine. Here nine different button codes are evaluated to

Figure 5. A slide show on the PC monitor.

overwritten with the value ­1. After slightly more than 444 µs, the routine `RC5bit' returns the value of the bit that was read. The calling routine (`RC5') evaluates this bit and waits 444 µs before again calling `RC5bit'. In this manner, any subsequent level change that may be present is skipped. This is proper, since the next valid change is only expected to take place after 1.776 ms. Signal reception is controlled by a timer in the VB program. All received data are displayed in a text window. Figure 4 shows the screen output of the received data for a remote control unit with device address `5' (video recorder) and button `7' pressed. If no signal is received, a suitable error message is displayed with Ctl = ­1 and Addr = ­1. In an operational version of the program, the error information would not be displayed but would instead be used to distin-

In next month's issue, the software for a RC5 transmitter using a PC and the IR transceiver circuit board will be described. These can be used to control a video recorder and other devices using a PC and to transfer serial data between two PCs via the infrared link.

Download note
The PORT.DLL used in this article, as well as the program listings and the printed circuit board layout, can be downloaded free of charge from the Elektor Electronics website at www.elektor-electronics.co.uk. On the home page, you can find the download pages by clicking on the `Free Downloads' button and then the month in which the article in question was published. The software files can also be obtained from the home page of the author: http://home.t-online.de/home/B.Kainka

Reference:
B. Kainka, PC Interfaces under Windows, Elektor Electronics (Publishing), Dorchester (ISBN 0 905705 65 3

66

Elektor Electronics

1/2002