The iRX 2.1 PIC Development Board

...[back]
...[fab home]


The iRX 2.1 as "Digital Glue"

At the MIT Media Lab, we constantly explore new metaphors for interconnecting the physical world and the digital realm. We monitor heart rates for affective computing, display the latest stock quotes for individuals, create new sensors for electronic tags, and build LEGO toys that respond to voice commands. Each of these activities binds some physical process or action to a corresponding digital expression.

To simplify this process of binding "atoms" to "bits," the Personal Information Architecture group has created a simple interface device named the "iRX 2.1." It's a circuit card measuring 1.25" × 3" with an RS-232 serial port, a visible LED, an infrared LED, and a infrared detector. At the heart of the board is the PIC16F84, a wonderful little microcontroller made by MicroChip Technologies, Inc. The PIC16F84 features thirteen general I/O ports, instruction cycle times of 250 nSec. (2.5 MIPS!) and an efficient RISC-like instruction set. The iRX 2.1 uses five of the PIC's I/O ports, and makes the remaining eight ports available on a connector. The total cost of the iRX2 is under $20 US when built in modest quantities.


About this Document

This document is written for anyone who wants to develop an application using the iRX 2.1

  • Section 2 gives some examples of interfaces you could build using the iRX 2.1 and the an overview of the development process.
  • Section 3 is a "Guided Tour" of the inputs, outputs, and important components on the iRX 2.1.
  • Section 4 gives you all the information you'll need to build your own iRX 2.1 boards, including a detailed Bill of Materials and pointers to suppliers and fabrication services.
  • Section 5 details the process of designing, programming, and debugging firmware for the iRX 2.1 board.
  • Appendix A is full of pointers to related information, including WEB links and vendor addresses.

1.1 Acknowledgments

The author would like to thank the following people.

Fred Martin and members of Mitch Resnick's group introduced me to PIC chips and IR emitters / detectors. The original design of the iRX was based on a board designed and built by Fred.

Pushpinder Singh and the MIT Robotics and Electronic Cooperative kept things moving. Push volunteered many of his hours to help our group program PICs. Push's design for a PIC-based "chord keyboard" helped shape the design of the iRX.

Randy Sargent provided great piles of software tools (PIC simulator, Gerber to Postscript), code examples, and general inspiration.

Encouragement and help from members of the Personal Information Architecture--especially from professor Mike Hawley, colleagues Maria Redin, Steve Gray, Manish Tuteja and John Underkoffler--have made this a fun project.

Matt Debski converted the original iRX 2.1 documentation from Frame into HTML and convinced me that maintaining the HTML version is the way to go. And I haven't looked back...


Typical Applications for the iRX 2.1

The iRX 2.1 can be used as a basis for a variety of interface tasks. Some scenarios in which the iRX 2.1 could be handy include:

  • A serial "TV Remote" interface. The PIC can be programmed to convert between serial data and the "Sony IR" remote protocol, allowing your computer to control your stereo system, and allowing you to control your computer with a TV Remote control.
  • An autonomous weather station. The PIC measures temperature (a thermocouple and a simple dual-slope A/D circuit), wind speed (counting pulses on a tachometer) and direction (4 bit shaft encoder), transmits the data over the serial port to a wireless modem. (Or you can use the pin-compatible PIC16C71 with built-in A/D.)
  • Ultrasonic Ranging device (see Microchip application note AN597). The PIC is sufficiently fast to generate outgoing pulses and measure the results accurately.
  • A MIDI <=> Serial interface converter. The PIC can be programmed to behave as a dual UART with baud rate conversion with buffering. The addition a photo-isolator and a few resistors is all that's required to make a complete interface.

Developing on the iRX 2.1: an overview

What you get out of the iRX2.1 depends mostly on what you put into it. It's unlikely that there will be any "pre-canned" configurations that exactly suit your needs--you will generally need to add custom hardware on the board and create a PIC program specifically for your application.

Figure 1. Typical Development Process

The good news is that PIC has a simple instruction set, a relatively straightforward architecture and several decent software development tools. If you plan to develop an application for the iRX 2.1, you must be prepared to tackle the following:

  • You will need one or more iRX 2.1 boards. Section 4 gives you information on how to fabricate PC boards and purchase the required components to build your own boards.
  • The "default" configuration of the iRX 2.1 includes a red LED, an infrared LED, and an infrared demodulator / detector. You'll need to decide what additional hardware, if any, you must add to the iRX 2.1 for your application. Section 5 discusses the features and differences among the I/O pins of the PIC16F84.
  • You will need to know fundamentals of the PIC architecture. Appendix A has a pointer to the Microchip home page from which you can fetch full data sheets, application notes and numerous source code examples.
  • You will need a PIC C compiler or assembler. In general, it's much easier and faster to program in C. However, if your application requires critical timing or squeezing every last cycle out of the PIC, you may need to write your application in assembly code. [Editor's Note: In many cases, you can still write most of your program in C and incorporate time-critical sections of code written in assembly using the #asm construct.] Section 5 describes a PIC C compiler and an assembler.
  • Once you have written your application in assembly language or in C, you will need to "burn" it into a PIC. Section 5 describes an inexpensive but effective PIC programmer that plugs into the parallel port of a PC running DOS (or a DOS window under Windows).
  • After programming your PIC, you will almost certainly need to debug your application. While there are several PIC software simulators available (Section 5), any real-time application is best debugged with an oscilloscope or a logic analyzer. Section 5 offers some tips on debugging techniques.


3.0: A Guided Tour

Figure 2 is an illustration showing the layout of the components of the iRX 2.1, Figure 3 is the schematic. The rest of this section discusses the major components in detail.

3.1 Layout of the iRX 2.1

Figure 2. iRX 2.1 Layout

[Editor's Note: There's been a small modification to the layout of the board since this photo was taken: the IR Emitter, the IR Detector, and the Red LED are in a densely-spaced row on 0.1" centers. Using this new arrangement, you can replace these parts with a 7-pin header in order to move them off the board or to substitute other components altogether.]

3.2 iRX 2.1 Schematic

Figure 3. iRX 2.1 Schematic (Rev B)

3.3 Component Descriptions

3.3.1 J1-DC Power Jack

The iRX 2.1 requires a nominal 9V DC power supply. Jack J1 accepts a 2.1 mm plug, such as you might find on a "wall wart" transformer with center pin V+, outer sleeve ground.

[Editor's Note: Although the iRX 2.1 is designed for a nominal 9V DC, it appears that it will work with any DC or AC source, 7.5V to 12V.] You may also find it useful to wire a 9V battery clip to a 2.1 mm plug and use a battery as your power source.

3.3.2 J2-RJ-11 / RS232 Jack

J2 is an RJ-11 jack, which accepts a standard telephone-style "modular" plug. (The RJ-11 standard implies using four conductors in a jack wide enough to hold six.) Following is a picture of the RJ-11 jack, viewed from its opening.

Figure 4. J2 Pinout

Digi-Key and other suppliers sell DB-9 and DB-25 connectors with an RJ-11 jack mounted in the top. Use a DB-9 for plugging into a PC or a DB-25 for a workstation (or any "real" RS-232 port). Note that the standard RJ-11 telephone cable has an inherent "twist" in the wiring, so pin 1 at one end of the wire connects to pin 4 at the other, thus effectively giving you "null modem" wiring. In setting up a DB-9 or DB-25 connector, you would make the following connections.

Figure 5. DB-9 and DB-25 connections

3.3.3 J4-I/O Header

The iRX 2.1 board "hardwires" five of the PIC's 13 I/O pins: serial input, serial output, Red LED, IR LED, and IR input. The remaining eight I/O pins are brought out on J4 as follows:

Figure 7. J4-I/O Header Pinout

Note that J4 is a 20 pin header. Pin 1 and 2 are connected to ground, pins 3 and 4 are tied to +5V. Of the remaining pins, the "even" pins (6, 8, 10 ... 20) are tied directly to the PIC I/O ports in the order shown above. The "odd" pins are wired to corresponding "pullup / pulldown" through-holes on the PC board. Opposite the PU/PD holes are a row of ground and power through-holes on the PC board (not shown in J4, but clearly visible on the circuit board.)

The arrangement of J4 and the corresponding PU/PD holes makes it easy to connect push-button sensors and/or LED directly to the PIC.

For example, to implement a push-button sensor on RB6, you would connect the switch between J4 pin 19 (PU/PD) and J4 pin 20 (RB6). You would connect a wire from PU/PD directly to the corresponding ground hole on the board (0.30" away). The PIC itself provides an internal pullup resistor, so when the switch is opened, RB6 will be pulled high. When the switch is closed, RB6 will be pulled to ground.

To connect an LED to RB7, you'd connect the LED between J4-18 and J4-17. You'd also connect a 220W resistor between the PU/PD through-hole and the corresponding +5V through hole (0.40" away). With this arrangement, the LED would be off when RB7 was high, and on when RB7 is programmed low.


4.0 How to build an iRX 2.1

Since you can't simply go to Radio Shack and purchase an iRX 2.1 (yet), this section details the steps to build complete iRX 2.1 boards. Be warned: an outside firm will charge about as much to make one printed circuit board as to make 100. When possible, pool your orders to make as many as possible at once.

4.1 Fabricate the Printed Circuit board

4.1.1 Choosing a PC Fabrication House

There are many companies that will fabricate PC boards directly from machine-readable design files. There is a list of fabrication houses, which is only guaranteed to be accurate at the moment this was written.

4.1.2 The design files

Once you choose a PC fabrication house, you'll need to send them the design files from which they'll make the circuit boards. Most of them have a modem dial-up line and a BBS to which you can upload the files, some of them have an FTP or WEB based connection. PC fab houses universally accept DOS format files with "eight dot three" file names.

The design files are available online here. You'll need to send these files to your PC fabrication house, using whatever form of communication the fab house wants. You will typically send them the single "ZIP" file that bundles these files together.

Table 1
File name Description
irx21.gtl Gerber format: Top ("component") side traces
irx21.gbl Gerber format, Bottom ("solder") side traces
irx21.gts Gerber format, Top side solder mask
irx21.gbs Gerber format, Bottom side solder mask
irx21.gto Gerber format: Top side silk screen
irx21.gko Gerber format, Board outline
irx21.apt Aperture list for the Gerber files
irx21.txt NC drill file
irx21.drr "Drill report" (indicates drill sizes) for NC drill file
readme.txt Your name, contact information, list of file names, etc..

You'll send the fab house the ZIP file and a purchase order. Some weeks later, they'll send you completed (but unstuffed) boards. If you are using an outside service to assemble the boards (see below), you can ask the fab house deliver the boards directly to the assembly shop.

4.2 Buying the components

All of the components, with the exception of the infrared detector and the printed circuit board itself, are available from Digi-Key, a mail-order electronics part supplier. While Digi-Key is not always the cheapest, they have a large selection, take telephone credit card orders, and will get you your parts the next day via FedEx. If you have more time than money on your hands, you can probably shop around and get a better price on some of the parts shown here.

Following is a list of all the components for the iRX 2.1. When possible, we've shown Digi-Key's part numbers and prices (as of Sep. 1998).
Table 2. Bill of Materials
quan Ref Digi-Key Part# Description unit ext
1---na- Printed Circuit Board 3.503.50
1J1CP-002A +9V DC Jack 0.2540.254
1J2A9031 AMP RJ-11 low profile jack (6 position, 6 contacts) 0.44500.4450
1--ED3318 18 pin DIP socket 0.52540.5254
1U1NJM78L05A 78L05 +5V voltage regulator 0.180.18
1U2PIC16F84-10/P PIC16F84 processor 3.993.99
1U3MAX233 Maxim MAX233CPP or Sipex SP233ACP RS-232 level converter 3.603.60
1U4-na- Sharp IS1U20 Infrared Demodulator 2.502.50
1L1LT1061 Infrared LED [note 4] 0.2160.216
1L2LT1078 Red LED [note 5] 0.100.10
3D11N5817CT 1N5817 Schottky diode 0.280.84
1Y1X906 10MHz ceramic resonator with built-in capacitors 0.4680.468
2C1, C2P6224 22uF electrolytic capacitor [16V or greater] 0.060.12
1C31210PHCT .01uF ceramic capacitor 0.08290.0829
2R1, R2100QBK 100 ohm 1/8W resistor 0.01940.0388
1R310KQBK 10K ohm 1/8W resistor 0.01940.0194
1--CP-004A 2.1 mm DC Plug 0.430.43
1--BS6I-HD 9V battery cable [note 6] 0.280.28
1--P145 9V battery [note 6] 1.731.73
1--T402 9V DC adaptor ("wall wart") 2.1 mm plug [note 6] *3.71*3.71
1--H164x-07**** RJ-12 phone cable *1.10*1.10
1--046-0003 RJ11 to DB9F adaptor *3.30*3.30
TOTAL: $19.32

Notes:

[Note 1] Prices shown are approximate, taken when possible from Digi-Key Sep 1998 catalog and assuming 100 unit pricing. Prices preceded with `*' aren't counted in the total.

[Note 4] The LT1061 infrared LED listed has a 40 degree viewing angle. Almost any other infrared LED may be substituted, depending on the application. Narrower viewing angles will give you a longer on-axis projection distance, but will require more accurate aiming. Note also that if your application doesn't require IR, you can substitute another visible LED here (e.g. green)

[Note 5] Almost any visible LED will suffice for L2--the LT1078 shown is inexpensive and bright.

[Note 6] Power can come from a 9V battery or an unregulated 9V DC "wall wart."

4.3 Stuffing the Boards

You may either solder the components to the circuit board yourself or send them to an outside service for assembly--it all comes down to a trade-off between time, money and patience.

4.3.1 Stuffing the boards yourself

If you stuff the boards yourself, there are a few points to keep in mind:

  • To keep components from falling out while you're soldering others, work from the "shortest" to the "tallest" components in several stages. First, solder the lowest components [resistors (R1-3) and diode (D1)], then [ceramic resonator (Y1), small capacitor (C3), voltage regulator (U1), the MAX233 (U3), DIP socket (U4), and the LED (L1-2)], then [DC Jack (J1) and the headers (J3, J4)], and finally the tallest components [IR detector (U4), the electrolytic caps (C1-2), and the modular jack (J3)].
  • Don't overheat the sensitive components with the soldering iron: the voltage regulator (U1), the IR detector (U4), and the MAX233 (U3).
  • Using the silk screen as a guide, observe the correct polarity on the diodes (D1 ***), electrolytic capacitors (C1-2), the LEDs (L1, L2). Make sure all the Ux components are inserted correctly.
  • Bend the leads on L1 and L2 with a right-angle bend so they face the same direction as the IR detector (U4). Bend the LEDs' leads before inserting them into the board, and make sure that you get the polarity right when you bend them.

4.3.2 Sending the boards out for assembly

You can find a list of companies that stuff circuit boards listed along with the fabrication houses. Expect to pay on the order of $4-$8 per board for stuffing.

4.3.3 Big Fat Note

Mea Culpa. The Rev A version of the iRX 2.1 board omitted a connection on the MAX233 level converter (U2). In order for serial output to run correctly, you must add a jumper between pin 12 and pin 17 of U2.

5.0 Developing your iRX 2.1 application

The steps towards creating your PIC application are straightforward and have been outlined in Section 2.0 In this section, we jump into the details.

5.1 Not all I/O Ports are created Equal

The PIC16F84 has thirteen ports: RA0 - RA4 and RB0 - RB7. Of these, the iRX 2.1 "reserves" RB1 - RB5 for serial and optical inputs and outputs. (Note: you can still use RB2 - RB4 if you're willing to give up optical inputs and outputs; see Section 3.3.5 for details.) Some ports have particular traits that may make them more or less suited for your particular application. The following table summarizes the differences; for the full scoop, consult the Microchip data sheets.

Table 3. Summary of I/O ports on PIC16F84
Port Traits
all Unless noted, all ports support TTL levels, are bi-directional under program control
RA0
RA1
RA2
RA3
RA4 Schmitt Trigger input, Open collector output, can be programmed to be input to TMR0 clock
RB* All B ports have a programmable internal pull-up on input
RB0 Can be selected at INT source, can wake PIC from a sleep
RB1 Reserved for serial output on iRX 2.1
RB2 Reserved for Red LED output on iRX 2.1
RB3 Reserved for IR LED output in iRX 2.1
RB4 Reserved for IR Detector input in iRX 2.1, can be programmed for interrupt on change
RB5 Reserved for serial input on iRX 2.1, can be programmed for interrupt on change
RB6 Serial programming clock, can be programmed for interrupt on change
RB7 Serial programming data, can be programmed for interrupt on change

The iRX 2.1 board leaves Port A entirely untouched. This was a conscious decision, making it possible to substitute other 18-pin PIC chips, such as the PIC16C71. The PIC16C71 isn't an EEPROM device, but it does have a four-channel A/D converter.

5.2 C versus Assembly code

Whenever possible, program in C instead of in assembly language. You'll find the development and maintenance of firmware programs to be much faster and easier. However, there are some times when you may feel the urge to program in assembly:

  • Time critical applications, where you must be able to account for every cycle. In general, you can't rely on what code the C compiler will generate nor what run-time support code will be run in the course of execution.
  • Code critical applications. The C compiler can't assume much about the state of ports and registers, so it generates some extra code in the name of saving and restoring state.

First, resist the urge. Look at the C code listings, see if you can simply recast your code to avoid the need for assembly code. If you still must write in assembly code, write the bulk of the code in C and use #asm statements for the time or space critical sections. Refer to the C Compiler documentation for more information.

5.3 PIC C Compilers

We use PCM, a C compiler for the PIC by Custom Computer Services. PCM isn't perfect, but it has improved steadily over the last few years. At this point, PCM is fairly robust and generates surprisingly tight code (especially when you use the built-in functions). And for $99 for a single license or $50/user for a site license, it's a good deal. Contact and purchasing info can be found in Appendix A.

5.4 PIC Assemblers

We use MPASM, the free PIC assembler from Microchip. It's a DOS-only application, but has proven to be robust and reliable. Randy Sargent also has a free Unix-based PIC assembler named picasm. See Appendix A for where to find them.

5.5 PIC Simulators

A PIC simulator can simplify debugging in cases where real-time I/O isn't an issue. One popular simulator is MPSIM, available for free from Microchip.

5.6 Burning your program into the PIC

We use the PICSTART PLUS programmer from Microchip (also available through Digi-Key). The programmer plugs into the serial port of a PC and is driven by the MPASM program (supplied with the programmer).

5.7 Configuring the PIC

Before the PIC can run at all, you must program (at least once) the "configuration fuses" for the PIC. Make sure the fuses are set as follows when running MPASM:

Table 4. Configuration fuses for the PIC16F84
FuseDescription
Oscillator Selection For the iRX 2.1 board, always program to "HS"
Watch Dog Timer Enable Enable iff your application uses the Watch Dog Timer
Power-upTimer Enable Enable for the iRX 2.1 (makes more reliable startup)
Code Protection Generally DISABLE unless you're paranoid about your code.

5.8 Debugging Tips and Programming Techniques

Following is a random collection of tips, techniques, art and lore. Your mileage may vary. Press down while turning. Void where prohibited.

5.8.1 First principals

When you power on the card and things don't work, check the following in this order:

  • Do you measure a clean five volts between +5V and GND? A convenient place to measure is the two test points at the LED end of the iRX board. If you don't see five volts, check that the PIC chip inserted properly--the "dimple" (indicating pin 1) should be pointing towards R3 (the 10K ohm resistor).
  • Is the PIC's oscillator running? Look between ground and pin 15 on the PIC using a 10x probe. (The impedance of a 1x probe is sufficiently small to kill the oscillations.) If you don't see a 10MHz waveform, did you remember to program the PICs fuses for "HS" operation?

5.8.2 Debugging

  • Program all unused I/O pins to be outputs. This way, you can set the state of a particular I/O pin to be TRUE when you enter a routine and FALSE when you leave it. At the very least, this practice, along with an oscilloscope, can give you confirmation that a particular piece of code is being executed.
  • Make the board do something visible or audible at startup. In the case of the iRX 2.1, consider turning on the Red LED for a good 500 mSec or longer after completing the initialization sequence and before starting the main program. This can save you lots of time in the heat of battle.
  • If you're using the RTCC to generate regular interrupts, set an unused output pin to TRUE when entering the interrupts routine and FALSE when leaving it. Monitor the pin with an oscilliscope: the distance between pulses tells you the rate at which you're getting interrupts and the width of the pulses tells you the percentage time you're spending in the interrupts. Are you getting interrupts at the rate you expect? Does the duration of the interrupt exceed the desired interrupt period?

5.8.3 Power Consumption

  • Putting the PIC into SLEEP mode reduces its current draw from a nominal 5 mA down to about 5 uA. You can wake from a sleep either from a Watch Dog Timer interrupt or from an external interrupt (ports RB0 or RB4-7). This savings is especially significant if you're running the iRX 2.1 off a battery.

    Note, however, that the MAX233 RS232 interface chip draws a significant amount of current. If your application doesn't require serial I/O, you may omit the MAX233 chip when you assemble the board.


Appendix A: Resources

Here are pointers and references that you might find useful when working with the iRX 2.1.

  • Printed Circuit Board "gerber files" are available in this directory. See Section 4 for more information.
  • A random assortment of firmware files are available in the firmware directory. Please feel free to submit additional files to for inclusion by sending e-mail to the author.
  • Home page of Microchip, manufacturer of all PICs, including the PIC16C84. Data sheets, application notes, source code examples, PIC assemblers and pointers to other PIC-related pages can be found here.
  • DIGI-KEY has an excellent on-line catalog, with live database queries for part numbers, pricing and availability. And you can order as late as 6:30 pm (Eastern time) and have the parts at 10AM the next day.
  • Info on the PIC C compiler by Custom Computer Services can be found here.
  • Home page of MAXIM, the manufacturer of the MAX233 RS-232 converter. Data sheets can be found here. An alternate source for the MAX233's can be found at the Sipex web site. Their part number is SP233ACP.

...[back]
...[fab home]
This section brought to you by Robert Poor.