An incremental optical encoder is nothing more than a slotted
disk and infrared (IR) emitter-detector pairs. Disk
rotation results in IR pulses which must be handled; pulse
counting, timing and quadrature yields the disk's angular position,
velocity and direction respectively. The photo on the left
illustrates a PC based ISA bus card solution that automatically
handles encoder pulses and yields disk measurements.
There are many instances when rotation angle, velocity and direction must be accurately measured. Examples include robot odometry, XYZ (lead screw) table motion measurements, telescope lateral and longitudinal positioning and knob inputs.
PC based solutions are attractive because of event-driving; through software, angle feedback can be used to improve navigation or positioning.
The ISA bus provides you an easy interface to build your PC quadrature card upon. Your card will plug into your PC's motherboard much like a modem or sound card does. Although commercial PC bus based cards cost hundreds of dollars, this tutorial will show you how you can prototype one for less than $50US, in an afternoon.
This tutorial is broken down as follows:
| PART DESCRIPTION | VENDOR | PART | PRICE (1999) | QTY | |
| PC BUS PROTOTYPING CARD | JAMECO | 21531 | 17.95 | 1 | |
| 28 PIN WIREWRAP SOCKET | JAMECO | ??? | ??? | 1 | |
| LS7266 QUADRATURE IC | SEE BELOW | 1 | |||
| 74HC138 3-8 DECODER | JAMECO | 45330 | 0.45 | 1 | |
| 8-ROW HEADER | JAMECO | 1 | |||
| JUMPER SHORTING BLOCK | JAMECO | 22023 | 0.19 | 2 | |
| 16-PIN WIREWRAP SOCKET | JAMECO | 37436 | 0.95 | 1 | |
| INCREMENTAL ENCODER | SEE BELOW | ||||
| HEADERS | DIGIKEY | ||||
| HOUSING | DIGIKEY | ||||
| CRIMPS | DIGIKEY | WM2200-ND | |||
Headers, housings and crimps were used for quick and professional looking connections. Example Digikey part numbers are WM4002-ND (headers), WM2002-ND (housings), WM2200-ND (crimps) and WM2312-ND for crimp tool. Of course, you can choose to wirewrap/solder your circuit without these parts.
The heart of this card is the 7266 quadrature IC, a 24-bit encoder to microprocessor interface chip, costing approximately $16. There are two main suppliers: the manufacturer, LSI and US Digital.
Readers may be familiar with the more widely available Hewlett-Packard/Agilent's HCTL-2000 chips. However the 7266 has distinct advantages; the 7266 provides 24-bits of resolution, can handle two encoders and is competitively priced.
To test your PC Quadrature Card, you will need an incremental optical encoder. The one featured in the introductory photo above, is the US Digital ???. You can hack a $5 ubiquitous serial PC mouse as shown in ??? for a cheap source of encoders.
7266Schematic060500.pdf is the Acrobat file of the same schematic. You will need Adobe's free Acrobat reader to view it.
The schematic is relatively straight-forward. One possible (and common) confusing point with ISA bus circuits is the use of the prefix "A". An ISA card has a component and solder side, often called "A" and "B" respectively. There are 62 edge tabs: 31 on the component side (A1-to-A31) and 31 on the solder side (B1-to-B31). However, address lines often use the prefix "A" too. On the PC there are 20 address lines (A0-to-A19).
To avoid this prefix confusion, this tutorial uses the lower case "a" to refer to the component side's 31 edge tabs. For example a11 is the AEN pin. "b" refers to the solder side's 31 edge tabs. For example b13 identifies the /WR pin. The schematic above includes the ISA 62 pinout for referencing connections to other components, namely the 74138 and 7266.
Encoder-to-Card Tethering:
You will need to tether your incremental optical encoder to your ISA card. Typical quadrature-capable encoders have 4 or 5 pins. The figure below shows a commerical encoder (US quarter shown for scale) and 5-pin pinout diagram. A complete tutorial on hacking a mouse for a cheap source of encoders also exists on the Boondog website.
The 7266 can handle encoder index pulses, but to simply illustrate its quadrature and pulse reading capabilities, the index pin is not used in this tutorial.
The encoder uses a conventional 0.1" pin spacing. A standard 4-pin housing, header and ribbon cable are used to tether the encoder to the ISA prototyping card. The housing and headers provide quick connect/disconnect of your encoder as seen in the photo below.
Shorting Block and Address Decoding:
The circuit's 8-position double row header and shorting block are used for address decoding. Like modem or sound cards for example, your Quadrature encoder card will plug into an ISA slot on your PC's motherboard. To distinguish your card from the others, requires it to have a unique address. The shorting block is used for this purpose.
The shorting block allows you to choose one of a possible eight addresses, as shown on Table 2:
| ROW POSITION | HEX VALUE | DECIMAL VALUE |
| 1 | 200 | 512 |
| 2 | 220 | 544 |
| 3 | 240 | 576 |
| 4 | 260 | 608 |
| 5 | 280 | 640 |
| 6 | 2A0 | 672 |
| 7 | 2C0 | 704 |
| 8 | 2E0 | 736 |
For example, placing the shorting block on row 4, assigns your card an address of 260h (or 608d). The suffixes h and d refer to hex and decimal representations respectively. The Turbo C example, given in the section below, illustrates card reading and/or writing using this address.
The 74138 is a 3-to-8 decoder. The ISA pins a24, a25 and a26 serve as its three inputs and depending on their values, will yield one 8 possible outputs. This output will be used to enable 7266 quadrature chip reading and/or writing.
For example, the card address, 608d is 1001100000 binary:
which results in a24, a25 and a26 to be 0, 1 and 1 respectively. These 3 values feed into the 74138's A, B and C inputs thus selecting the 74138's Y3 output:
In addition, for Y3 to go active low, the 74138's /G2A, /G2B and G1 must 0, 0 and 1 respectively. 608d already sets /G2B and G1 to 0 and 1 respectively, as seen by its binary representation figure above. The 74138's G1 pin is connected to ISA bus pin a11 (AEN). AEN = 0 whenever the expansion bus is called. This happens whenever an outportb(608, someValue) or inportb(608) is invoked in Turbo C. In QuickBasic, AEN = 0 when out(608, someValue) or inp(608) is executed.
Programming your card involves one, intialization; two, transfering the 7266's counters (CNTR) to the output latch (OL); and three, reading the encoder value.
init() performs card initialization, such as
counter reset (EFLAG_RESET, BP_RESETB)
and both clock rate (and quadrature
resolution assignments, as per the 7266 spec sheet.
Variable definitions (see the#define's) are found
Final Words
Commerical encoders can be expensive and overkill for your
rotation measurements. This tutorial showed how you can
disassemble a $5.00 serial mouse for two encoder disks and four
emitter-detector pairs to protoboard your own encoders in
an afternoon or two.
Some "big picture" applications include measuring: mobot wheel position and speeds, inverted pendulum angles, telescope pointing, and XYZ-table positioning.
Click here to return to Main Page
Click here to email me