Build the Xanadu Zapper!













                               Build the Xanadu Zapper!

                                         by

                                    Scott Coleman

                                  Xanadu Consulting

                      Internet: coleman@f69.n233.z1.fidonet.org

                    FIDOnet: 1:233/69.0 (Xanadu BBS 217/384-2127)

                 Copyright 1990 Scott Coleman. All Rights Reserved.







               The following  is a description of a computer-assisted semi-

          universal infrared learning remote  control project.  It consists

          of a  small, inexpensive  and easy  to build hardware device (the

          Zapper)    which    contains     both     an     IR    (infrared)

          detector/demodulator and  an IR emitter. The Zapper attaches to a

          personal computer via a TTL-level parallel  input/output port and

          is  controlled  by  software  running  on the PC. The Zapper will

          allow your personal computer  to learn  the control  signals sent

          out by  many IR  remote control  devices and duplicate them under

          program control.

               The  information  contained  in  this  document  and  in the

          accompanying  schematic  diagram,  ZAPSCHEM.GIF,  was synthesized

          from various sources, including  Usenet,  magazine  articles, and

          component  data  sheets.  It  is  not a "complete" project in the

          sense that it does not include a step-by-step cookbook recipe for

          constructing  an  exact  replica  of  my Xanadu Zapper prototype.

          Realizing that not everyone in the universe owns an IBM AT clone,

          I  have  opted  instead  for  a  more  general description of the

          hardware, software, and interfacing  considerations.  My  hope is

          that this  document will  serve as a good starting point for your

          own experimentation in the realm  of  IR  control.  Feel  free to

          distribute this  document to  anyone who  might be interested. If

          you do distribute it to others, I ask  that you  do NOT  charge a

          fee of any kind.

               For  more  detailed  information  on  how IR remote controls

          work, I refer  you  to  two  excellent  articles  on  the subject

          written  by   Steve  Ciarcia  which  appeared  in  Byte  magazine

          ("Ciarcia's Circuit Cellar," February and March, 1987).













               The uses for the Xanadu  Zapper  are  limited  only  by your

          imagination and  your IR equipped devices. My purpose in building

          the Zapper was to allow a  computer to  control several different

          VCRs  via  their  IR  control links, allowing easy frame-by-frame

          analysis of research subjects  recorded on  videotape. Because of

          its  semi-universal  nature,  however,  the Zapper is by no means

          limited to this task. Among other things, the Zapper can  be used

          to:



               o  Control  a  VCR  for use in automatically taping computer

               graphics output.



               o Control two VCRs  for use  in editing  and dubbing between

               decks.



               o Control a CD player for a computer-controlled jukebox.



               o  Work   in  conjunction   with  an  IR-equipped  cable  TV

               descrambling box to record  multiple  programs  on different

               channels while you're away.



               o  Use  the  hand-held  remote  control  from your TV set to

               control your computer (which in turn can control  some other

               device).



               o Anything else you can dream up.



               I refer  to the Xanadu Zapper as "semi-universal" because it

          will work  only with  remote control  devices which  operate at a

          40kHz IR  carrier frequency. Fortunately, quite a few IR equipped

          devices fall into this category, among  them Sony  video products

          (e.g. KV1397R  TV, SL-HF900  VCR), JVC  video products (HR-S5000U

          VCR) and Panasonic Industrial video (AG-1960 VCR).

               For those of you  who are  unfamiliar with  IR communication

          and IR  remote controls,  the next section is a brief overview of

          what we're trying to  accomplish. The  more advanced  readers may

          wish to  skip ahead  to the circuit description section. For more

          detailed information, I refer  you to  the articles  mentioned on

          the first page of this document.





                        A Brief Overview of IR Communication



               Many of today's consumer electronic devices (e.g. TVs, VCRs,

          CD  players,  etc.)  are  equipped  with  small  hand-held remote

          controls.  These  remotes  are  nothing  more than small wireless

          keypads which, when a  button on  the remote  is pressed,  send a

          coded signal to a receiver unit inside the VCR. The signal may be

          ultrasonic, radio frequency, or IR  light.  IR  remotes  are very

          popular because of their limited range (line-of-sight only) which

          reduces interference with other  remote controlled  devices (e.g.

          your neighbor's  TV set). Since this project involves duplication

          of IR control signals, we'll limit  our discussion  to remotes of

          this type.











               IR remotes  generate a  stream of  IR light  pulses which is

          amplitude  modulated  to  produce  the  encoded  signal.  The VCR

          contains circuitry  which will  detect and demodulate this signal

          to recover the  original  signal  specifying  the  command  to be

          performed  (e.g.  PLAY  or  POWER  ON).  The specifics of how the

          signals are encoded varies from manufacturer to manufacturer, and

          sometimes from  model to  model. This variation is the reason why

          (with few exceptions) the remote from your VCR  doesn't work with

          your TV  and vice versa. Fortunately for us, the computer doesn't

          need to be able  to "understand"  the IR  signals in  order to be

          able to  learn and  reproduce them, so the variations in encoding

          schemes won't affect us.







                                 Circuit Description



               The circuit is very simple. Even I, a software type  with no

          electrical engineering  background, was  able to build it and get

          it working. It requires only a few components (see parts  list at

          the end  of this  document) and should cost less than $30. Almost

          everything you need to build the  Zapper  can  be  found  at your

          local  Radio  Shack.  (Note  that  I  am not a Tandy employee nor

          affiliated with them in any way, but I do live  in an  area which

          is sorely lacking in retail outlets which stock electronic parts.

          For me, it is either RS or mail  order.) The  circuit consists of

          two  main  sections:  an  IR  receiver and an IR transmitter. The

          receiver portion is made up of precisely one  component: a Sharp-

          made GP1U52X  IR detector  module sold by Radio Shack. In a small

          rectangular package less than  one cubic  inch in  size Sharp has

          stuffed  an  IR  detector,  an  amplifier, a limiter, a band-pass

          filter, a demodulator, an integrator, and  a comparator.  Hook it

          up to  a 5V power source, and it produces a TTL-level demodulated

          version of the IR signals it  detects.  It  also  rejects  any IR

          source not modulated at 40kHz to reduce interference from ambient

          light or other sources. The output of the detector module  can be

          fed directly  into a  binary input  line on a computer's parallel

          input port. The computer "learns" the IR signals by sampling this

          input line and storing the serial data as it comes in through the

          port.



               The transmitter is only  slightly more  complicated than the

          receiver. Borrowing  from the  circuit provided on the data sheet

          that RS includes with  the IR  detector module,  I built  a 40kHz

          oscillator around  a 555  timer chip.  The output  of the circuit

          drives an IR LED, flashing it on and  off at  approximately 40kHz

          (the  exact  frequency  is  adjustable  via  a trimmer resistor),

          producing the IR carrier  signal.  The  carrier  is  modulated by

          connecting a  binary output  line from a computer's parallel port

          to the reset input on the 555 chip. Raising the output line  to a

          logic 1  TTL level  enables the  carrier generation; lowering the

          line to logic 0 disables it.

















                             Interfacing Considerations



               Your computer must be equipped with a TTL-level parallel I/O

          port in  order to  control the  Zapper. Back in the early days of

          personal computing,  many  micros  came  with  a  general purpose

          parallel  I/O  port  as  standard equipment. These days, however,

          computer manufacturers seem to be moving  away from  this sort of

          thing, so  you'll more  than likely have to make do with whatever

          I/O capability you have. Machines which  use digital  switch type

          joysticks, such as the Atari 800 or the Commodore 64, may be able

          to  control  the  Zapper  via  a  joystick  port.  Typically, the

          joystick port  is read through a PIA chip which can be programmed

          to act either as an input or as an output  port. Note:  this does

          not apply to systems which use analog type joysticks, such as the

          IBM PC or the Apple II.

               Another  workable  solution  is  to  use  a  Centronics-type

          parallel  printer  port.  These  ports have both input and output

          lines which operate at TTL signal levels. On machines which allow

          two  or  more  printer  ports  to  coexist,  it is a good idea to

          install a second printer port so  that  you  won't  have  to swap

          cables every time you want to use the Zapper or the printer.

               A third  alternative is  an add-on parallel interface board.

          These are  often  designed  specifically  for  use  in real-world

          interfacing/control  or  in  data  acquisition  applications, and

          generally have 16 or  more  binary  inputs/outputs,  and possibly

          some analog  inputs/outputs as  well. These tend to be expensive,

          however, and are definitely overkill for the Zapper project's I/O

          requirements.

               With the  addition of  the appropriate line level conversion

          circuitry, it would also be possible to use a serial port instead

          of   a   parallel   port.   This  complicates  the  power  supply

          requirements, however, as most commercially available line driver

          chips require both +12V and -12V in addition to +5V.

               Once  you  have  the  circuit  assembled (see next section),

          you'll need to select one input line and one output  line for use

          by the Zapper. Connect the output line from the port to the point

          labeled IREN in the schematic, and connect the input line  on the

          port to the point labeled IRDO on the schematic.

         





                                Building the Circuit



               In  addition  to  the  basic  circuit,  you'll  need a power

          supply, a project case, and some means for  connecting the Zapper

          to the  computer (as  outlined above). Since the details of these

          will vary from situation to situation, I'll be purposely vague on

          these points  and concentrate  most of  my attention on the basic

          circuitry. The examples I will give pertain to  my own prototype,

          which  was  designed  to  work  with  an  IBM AT clone's parallel

          printer port. While the  details will  differ for  other types of

          computers, the general principles will apply equally well to all.













               First, select  some sort of power supply. I happened to have

          one of those black  box  9VDC  transformer  power  supplies lying

          around, so  I used that in conjunction with a 7805 regulator chip

          as my +5VDC power source. This may not be the best choice, but it

          seems to  do the job. Of course, you can easily construct a power

          supply from a transformer, rectifier, some filter capacitors, and

          the 5V  regulator chip, but you'll need a case big enough so that

          everything will fit. Once you've decided upon a power supply, you

          can decide just how much circuit board real estate you'll need to

          accommodate all the components.  For my  prototype, I  designed a

          printed circuit  board (using  the "do  it yourself" PC board kit

          available at - you guessed it  -  Radio  Shack),  but  this isn't

          necessary;  a  perfboard  will  do  just  fine. Radio Shack sells

          several project case +  perfboard combinations.  Since I  used an

          external power  supply, everything fit comfortably onto a 2" x 3"

          circuit board.





                                 Tuning the Circuit



               The only potentially difficult part of  the assembly process

          is tuning  the circuit so that it flashes the IR LED at 40kHz. If

          you have an  oscilloscope  or  a  frequency  counter  handy, this

          should be  a piece of cake. If you don't have access to either of

          these, I'm afraid you're in  for  a  period  of  trial  and error

          experimentation. Since  I don't  have either an oscilloscope or a

          frequency counter at home, I was  forced to  do it  the hard way.

          Here's the procedure I used:



               Using the  standard formulas for calculating the oscillation

          frequency  of  a  555  timer  in  astable  multivibrator  mode, I

          determined  that   R2  (the   trim  pot)  needed  to  be  set  to

          approximately 37797.8 ohms in  order  to  achieve  an oscillation

          frequency  of  40kHz.  I  mocked  up  the circuit on a solderless

          breadboard, and connected it to the  computer. I  removed R2 from

          the  circuit,  and,  using  an  ohmmeter,  I  set  R2 as close to

          37.7978K as  I  could  get  it,  then  replaced  it  back  in the

          breadboarded  circuit.  I  then  wrote  a  program  (a simplified

          version of that described  in the  software section  below) which

          sampled the  output of  the IR  detector module  at about 100kHz,

          stored the  sampled data  in memory,  and then  played the signal

          back  by  toggling  the  IR  enable  line to the Zapper. I took a

          remote control  which I  knew operated  with a  40kHz carrier (in

          this case,  for a  Sony VCR), aimed the remote at the IR detector

          module, and pressed  the  power  button  on  the  remote.  I then

          started the  sampling process. Once the IR signal from the remote

          had  been  stored  in  memory,  I  aimed  the  IR  LED  from  the

          breadboarded  Zapper  in  the  general  direction  of the VCR and

          repeatedly played the signal back, adjusting  the trim  pot until

          the signal  from the  Zapper was  turning the power to the VCR on

          and off. Because I had pre-set  the trim  pot to  the approximate

          value necessary,  I only  had to  adjust the trim pot slightly to

          get the Zapper working.













               Clearly, the above procedure  can  require  a  lot  of time,

          patience, and  a little  bit of luck. There are many variables to

          keep track of: the carrier frequency emitted by the remote you're

          using (if it's not 40kHz it won't work); the distance from the IR

          LED on the Zapper to the detector in  the VCR  (too far  away and

          the VCR  will "see"  nothing, too  close and  the VCR  will get a

          distorted signal); and, of course, proper wiring of  the circuit.

          In most cases, your time would be better spent in hunting down an

          oscilloscope or frequency counter to  borrow  for  a  few minutes

          than to  go through the trial and error procedure I have outlined

          above. I leave the choice to you.



               Once  your  circuit  is  properly  tuned,  you're  ready  to

          assemble it  permanently on  its circuit  board and install it in

          its case. When laying out the  components, keep  the following in

          mind:



               o The  IR LED  must project out through the case so that its

               light can be seen by the VCR.



               o A "window" must be cut  in the  case directly  above where

               the IR  detector module  is to  be mounted, so that IR light

               from remotes can be  sampled. This  can be  as simple  as an

               uncovered rectangular  hole, or the hole can be covered with

               a small piece of smoked plexiglas to keep  out the  dust and

               ambient  light  while  still  allowing IR light to enter the

               case.



               o  Jacks  for  the  computer  and   power  supply   must  be

               accommodated.



               o You'll  probably want to mount a power switch somewhere on

               the case, as well.



          My prototype has the IR LED projecting through the front,  a DB25

          connector on  the right hand side (which connects to the computer

          via a detachable cable), and a power jack on the back. On the top

          are the  power switch and the window (plain old hole version) for

          the IR detector.

               After you've put everything together, you're  ready to start

          working on the driver software.





                               Software Considerations



               In an effort to keep this document as general as possible, I

          have not included any actual code. Instead, I am including enough

          information  to  allow  interested  hackers  to  roll  their own,

          customized to their individual needs and goals.



               I wrote a program called  ER  ("Expensive  Remote")  for use

          with my  Xanadu Zapper prototype. It is a mouse-driven, graphics-

          based program which samples IR signals, displays them graphically

          on  the  screen,  stores  them,  and  reproduces them. Adding the











          capability to plot a graph of the incoming  IR signal  served two

          functions: it  allowed me  to easily edit the stored signals (see

          below), and it  allowed  visual  verification  that  the receiver

          portion of  my circuit  was functioning  properly. Minimally, the

          program  must  perform  three  functions:  data   sampling,  data

          reproduction, and  data storage.  We'll examine  each of these in

          turn.



               In order to be able to recreate the IR signals, the computer

          must first  be able to "see" what they look like. This is done by

          sampling  the  status  of  the  IR  detector  module  at  regular

          intervals  and   at  an   appropriate  frequency.  I  sampled  at

          approximately  100kHz,  which  is  more  than  twice  the maximum

          possible  signal   frequency  of   40kHz.  This  is  higher  than

          necessary  but  turned  out   to  be   quite  convenient   in  my

          circumstances.

               The  actual  sampling  procedure  is  straightforward.  Each

          sample consists of one  port input  operation, one  memory store,

          and  associated  housekeeping  (bumping a pointer, decrementing a

          count). The following pseudocode outlines the  sampling procedure

          which  will  sample  the  output  of  the  IR detector at regular

          intervals and store the data into byte array P:





          for count = 1 to num_samples do {

               input byte from port

               save byte to memory location pointed to by P

               increment P to point to next address

               wait /* make sure samples occur at precise intervals */

               }







               Sending a signal to the VCR is equally straightforward - the

          sampling process  is simply  reversed. Using the same data buffer

          in which the bits representing the sampled IR  signal are stored,

          the software  sequentially reads a byte from the buffer and sends

          it out the parallel port, making certain that the significant bit

          in the  sampled data  "lines up"  with the bit in the output port

          which controls  the  Zapper's  IR  emitter  circuit  (e.g.  in my

          prototype, the input line corresponds to bit 7 of the input port,

          but bit 0 of the output port controls my IR emitter; thus, I have

          to shift my input data to the right before sending it out again).

          The following pseudocode accomplishes the send:















          set count = number of bytes in output buffer

          set P = address of first byte in output buffer

          for count = 1 to #bytes_to_send do {

               fetch byte pointed to by P

               increment pointer P

               output byte through port

               wait  /* make sure output data is evenly spaced */

               }







          If the sending is clocked at  the  same  frequency  at  which the

          sampling  occurred,  a  reasonably  accurate  reproduction of the

          original IR signal will be produced.



               The  best  sampling/sending  method  involves  the   use  of

          precision  timing  hardware.  For  example,  the  IBM  AT  has  a

          programmable timer  chip  built  onto  the  motherboard  which is

          capable  of   generating  an   interrupt  to  the  CPU  at  user-

          programmable time intervals. By  programming  the  timer  chip to

          generate  interrupts  at  the  desired frequency, and providing a

          suitable interrupt service routine, the input line can be sampled

          at precise intervals with very little programming effort, and the

          sampled signals can be sent out  the  port  at  exactly  the same

          rate.   Other   systems   have  similar  methods  for  generating

          interrupts  at  precise  intervals.  If  such   precision  timing

          hardware is  not available  on your PC, the task becomes somewhat

          more difficult. In this case, sampling the data will involve some

          tight  assembly   level  coding  which  takes  into  account  the

          processor's clock speed, the effects of system interrupts, cycles

          stolen  by  memory  refresh,  DMA,  other system components (e.g.

          graphics coprocessors), etc. Of  course,  therein  lies  the real

          fun!





                     Storage Requirements and Data Compression.



               On  most  microcomputers,  it  is impossible to input only a

          single bit from an  I/O  port.  More  often,  the  processor will

          fetch data  from the port 8, 16, or 32 bits at a time. Thus, each

          sample  of  the  IR  detector's  output   will  consist   of  one

          significant bit  and at  least 7  "don't care"  bits. In order to

          sample as quickly as possible, the sampling code will likely have

          to store  the entire byte input from the port as a unit. Although

          it  is  certainly  possible  (at  least  on  some  of  the faster

          machines) to  perform all  the bit twiddling necessary to get the

          single bit we're after  and  store  it  efficiently  in  the time

          between samples,  it's not really necessary. Since the IR signals

          are generally  of  short  duration,  0.5  second  of  sampling is

          usually enough  to capture  more than  one complete message. At 1

          byte per sample and 100000 samples  per second,  that's about 50K

          bytes. The  extraction of  the significant bit can be done later,

          which greatly simplifies the sampling code.

               The problem  with this  scheme comes  in when  one wishes to











          store the  signals (say in a disk file) for later recall and use.

          At 50K per IR signal and each remote  capable of  producing 30-60

          different  signals,   the  storage   requirements  add  up  fast.

          Fortunately, 7 of every  8 bits  is garbage  (assuming 8-bit port

          I/O),  and  can  be  discarded.  The remaining bits can be packed

          together,  resulting   in   an   8-fold   reduction   in  storage

          requirements. Of  course, either  the signal data will need to be

          expanded again before the send routine can make use of it, or the

          send routine outlined above would have to be modified to make use

          of the new data format.

               Further reduction in storage requirements may be realized by

          judicious editing  of the  stored IR signals. If you sample an IR

          signal for 0.5 seconds and plot a graph of the  signal over time,

          you'll  see  that  the  signal  does  not appear just once but is

          instead repeated several times throughout the sampling period. In

          order  to  reproduce  the  signal,  only  one complete message is

          required  as  your  software  can  repeat  it  as  many  times as

          necessary. In my Expensive Remote program, I added just this sort

          of data plotting and editing capability  which allows  me to chop

          out all the excess signal (by pointing and clicking with a mouse)

          and save only the required minimum signal. The additional savings

          realized  by  cutting  out  the  excess  signal  data  will  vary

          depending upon how long each individual  message from  the remote

          lasts.





                                   Closing Remarks



               Well, there you have it. I have tried very hard to be clear,

          concise, and complete in my description  of the  Xanadu Zapper; I

          hope that I have succeeded. I welcome your comments, corrections,

          and  (constructive)  criticisms,  as  well  as   any  unique  and

          interesting uses  you may come up with for the Zapper. Should you

          wish to get in touch with  me, my  email addresses  appear at the

          beginning of  this report.  I hope  you have as much fun building

          and using the Zapper as I did. Good luck, and happy zapping!







                                     Parts List



          C1 - 470 pF capacitor

          C2 - 0.01 uF capacitor

          LED1 - SEP8703-1 IR LED (RS 276-143; the emitter from the 276-142

          emitter-detector pair also seems to work)

          R1 - 1K resistor, 1/4 watt

          R2 -  50K multi-turn trimmer resistor (note: a multi-turn trimmer

          is recommended to make tuning the circuit easier.)

          R3 - 150 ohm resistor, 1/4 watt

          GP1U52X IR detector module (RS 276-137)

          Miscellaneous (perfboard, project  case,  power  supply, mounting

          hardware, connectors, cable to computer, etc.)





Comments

Popular posts from this blog

BOTTOM LIVE script

Evidence supporting quantum information processing in animals

ARMIES OF CHAOS