Infrared Remote Control Receiver for CoCo I/II/III ================================================== All materials in this archive are released to the public domain. Use them at your own risk. Purpose: -------- To allow your CoCo to receive and interpret signals from a Mitsubishi HS-U32 VCR infrared remote control. Use of other models should be possible with changes to the software. Contents of archive: -------------------- REMOTE.DOC -- this file REMOTE.TXT -- 6809 MAC Assembler source file REMOTE.LST -- 6809 MAC Assembler listing file REMOTE.BAS -- BASIC driver program -- POKEs the assembly program into memory and runs it Hardware: --------- This program uses a Radio Shack #276-137 IR detector module (cost: all of $3.49) connected to the right joystick port. Connection requires only three wires: pin 3 of the module (nearest the metal case) to ground (pin 3 on the joystick connector); pin 2 of the module to +5V for power (pin 5 on the joystick connector); and pin 1 of the module to the joystick "fire button" input (pin 4 on the joystick connector). The metal case of the module should be connected to ground also. You can use an RS #274-003 5-pin DIN plug with any CoCo. If you have a CoCo III, you could also use an RS 274-020 6-pin DIN plug. Looking at the back of the plug, at the ends of the pins that you solder to, rotate it so the notch in the body points straight up. Pin 5 (+5V) is the first pin to the left, or counterclockwise, of the notch. Pin 4 (the "fire" button input) is the next, continuing left or counterclockwise. Pin 3 (ground) is the next; it is opposite the notch. The remaining pins are not used in this project. Plug the joystick connector into the right joystick port and turn on your CoCo. Pin 3 of the module and its case should be at ground (0 volts). Pins 1 and 2 should be at about 5 volts. Software: --------- The REMOTE.BAS program simply calls the machine-language routine, interprets the result, and displays the interpretation. Making it do something useful is up to you! Note that the interpretation is based on my model of IR remote. Other Mitsubishi models may assign different functions to some of these codes. Models from other manufacturers will probably use a completely different encoding scheme (see below, "Further Experimentation"). The machine-language routine checks to see that the correct number of bits was received. If not, the USR value is set to zero. No other error checking is done. The program runs at normal CoCo speed (0.895 MHz). It also disables interrupts, so the TIMER function and other interrupt-based functions are disabled. Finally, note that the machine language routine will loop forever if it doesn't get a signal from the joystick button. Also, the BASIC program loops forever. Getting out of the program requires pressing the reset button, or pressing BREAK while the BASIC program is printing. Theory of Operation: -------------------- IR remotes send out bursts of IR light, each burst consisting of a number of on/off pulses. The desired operation ("PLAY", "RECORD", etc.) is encoded by the length and/or spacing of these bursts. (Note: The rate at which on/off pulses occur within a burst is the pulse repetition frequency (PRF). Mitsubishi remotes use a PRF of 33.333 KHz (33,333 per second). This is relatively low; Sony remotes are three times as fast, 100 kHz. The Radio Shack IR detector module is supposed to receive PRFs of 40 kHz, but seems to have no trouble with much higher and lower PRFs. This is probably one reason Radio Shack chose to sell this particular model.) The Radio Shack IR detector module recognizes these IR bursts. It's pin 3 is normally HIGH (5 volts). During an IR burst, it drops LOW (0 volts). Pin 3 is connected to the CoCo joystick "fire button" input, which is normally HIGH when the button isn't pressed and LOW when it is. So the presence or absence of an IR burst is read as joystick button pressed or not pressed. The machine-language routine waits for the joystick button bit to drop low, indicating the start of IR transmission. It then goes into a loop, reading the joystick button and storing it continuously. In order to allow sampling to occur as fast as possible, the data is just stored; no analysis is done yet. The loop exits when the memory (8 kilobytes) allocated for storage is filled. (Note that, since, in the CoCo's design, the joystick button is connected to a keyboard row, use of the keyboard may interfere with reception of IR signals and vice versa.) Then, the 8 kilobytes of stored button states is analyzed down to a few dozen bytes in the run-length table. The first byte in the run-length table is the number of entries. Each following byte is a run-length count. The first following byte is how long the initial "on" burst lasted. The second following byte is how long the first "off" gap lasted. The third following byte is how long the second "on" burst lasted. Lengths of "off" gaps and "on" bursts alternate to the end of the table. Address Contents $7100 N = Size of table $7101 LON1 = length of first "on" burst $7102 LOFF1 = length of first "off" gap $7103 LON2 = length of second "on" burst $7104 LOFF2 = length of second "off" gap ... $7100+N LONN = length of final STOP burst. The routine then checks the size of the table. If N is not 33, there was an error, and the return word is set to zero. If N is 33, the return word has its bits set according to the lengths of the "off" gaps. A gap more than 60 corresponds to a "1" bit; a gap less than 60 to a "0" bit. (Typically, short gaps are about 30 and long gaps around 90 to 100; 60 was chosen as being halfway between.) The word is then returned to BASIC via the USR value. The Mitsubishi word appears to consist of two bytes. The first eight-bit byte is a device code. VCRs have a device code of &HEA (decimal 234). Other devices -- TVs, CD players, etc. -- have different codes. (TVs, for example, are &HE2.) The last bit of the second byte is a unit code. Newer Mitsubishi VCRs have a "VCR A/VCR B" switch. VCR A will only respond to the remote if the last bit is zero; VCR B only if it is one. The top 7 bits of the second word are the actual function codes ("PLAY", "STOP", etc.). These will differ somewhat between models, although the basic functions will probably be the same. So there are at most 128 different function codes. Thus you have at most 128 (7 bits worth) different possible codes for a VCR remote, plus one bit of selection between different VCRs. Further Experimentation: ------------------------ Unfortunately, there are no current standards for the encoding of IR remote control signals. Every manufacturer does it differently. So the REMOTE.BAS program, written for a Mitsubishi remote, will probably be useless with other brands without modification. Fortunately, practical and economic limits have forced manufacturers to do some things the same way. As far as I know, all IR remotes are digital: the IR signal is either on or off, with no other states. Therefore, manufacturers have two basic methods of encoding: burst position modulation (BPM), and burst width modulation (BWM). In BPM, each "on" burst is the same length as all the others. Information is encoded by varying the length of the "off" period from one burst to the next. Mitsubishi uses a simple BPM method: "on" bursts are all about half a millisecond long. A zero bit is indicated by a delay of the same length before the next "on" burst. A one bit is indicated by a delay about 3 times as long. This means that a word with a lot of one bits will take longer to transmit than a word with mostly zero bits. Also, a transmitted word of 16 bits will consist of 17 "on" bursts with the 16 "off" gaps between them, since it is the "off" gaps that carry the 16 bits of information. There will be a total of 33 entries in the run length table. In BWM, the length of the burst itself changes to carry the information. The simplest case is just the mirror-image of the Mitsubishi method, with all "off" gaps the same length, short bursts for "zero," and long bursts for "one." However, more complicated methods are possible and used. For example, some manufacturers use an extremely long burst and long gap at the beginning of a word, with all the following bursts and gaps being shorter. I suppose this allows the receiver to wake up and get ready to receive data before the information-bearing bursts start to come in. Often in these systems, there is a special code for "repeat the previous command," consisting of the long start burst, a gap half as long, and a single short burst. If you hold the "CHANNEL UP" key on one of these remotes, the "CHANNEL UP" code is only sent once, followed by a string of "repeat" codes. If you want to use a non-Mitsubishi remote, you'll have to break the code yourself. There are too many possibilities for me to cover. Change line 220 in the BASIC driver program to "GOSUB 41000" to see the actual run lengths. If the remote has number keys, try numbers that differ by one (e.g., "5" and "6"). Their encoding may differ by just one bit, which may simplify figuring the coding scheme (but don't count on it). Keep in mind that the word length may differ with different manufacturers. Good luck!