Issue
114 January 2000
Reach
Out and Touch
Designing
a Resistive Touchscreen
Development
Notes
I
began this project by first locating the touchscreen-interface
chips. I then needed a quick and dirty means of testing
their functionality, which I did using a Basic Stamp
II device with a serial LCD attached. It was a simple
matter to interface the chips to the Stamp, and then
use the interactive Stamp-development environment to
debug the chip interfaces.
Of
course, a $50 Basic Stamp is not a good solution for
a production product. The production hardware was designed
around a lower cost PIC, the 16C622. I intended to discard
the Stamp code and write the production code in C. However,
I had heard about a compiler for the Stamp BASIC, and
decided to give it a try. The results were good and
enabled me to use most of the stamp code with little
modification. Ive since used this approach (successfully)
on other projects.
The
compiler is the PIC BASIC Pro (PBP). It is available
from microEngineering Labs for about $250.
Firmware
Description
Firmware
for the 4-wire Burr-Brown design is available on the
Circuit Cellar web site (the 5-wire firmware
is nearly identical). The PICs job is to sense
a touch event, and if detected, send out a data packet
containing the location of the touch. The PIC should
continue to send out this information as long as a touch
is detected and send a special packet at the end when
the touch has gone away.
The
PIC sends a five-byte data packet to communicate the
x/y touch coordinates to the host processor
(see Figure 8). The first byte in the five-byte header
always has its most significant bit set to one. The
other four bytes always have their most significant
bits set to zero to allow the receiver to synchronize
to the packet. The first byte is either a $C0 or $80,
depending on whether the touch is active ($C0) or a
touch-up event has occurred ($80).
|

(Click
here to enlarge)
|
Figure
8This is the message format used for
circuits in Figures 3, 4, and 6. A simple five-byte
data packet is used to transmit the touch coordinates
from the touchscreen controller to the host system.
|
The
four bytes that follow hold the x and y
coordinate values, with 14 bits allowed. Because we
digitize to 12-bit resolution, bits 12 and 13 are zero
filled.
The
firmware was written as a state machine, as shown in
Figure 9. On powerup, the code enters State 0, where
it initializes the data direction registers and blinks
the LED three times. A transition to State 1 follows,
where the code continuously scans the touchscreen, looking
for a touch.
|

(Click
here to enlarge)
|
Figure
9In this flow diagram for figures 3,
4, and 6, the controller continuously scans the
touchscreen, detects the touch, and sends out a
five-byte data packet. |
When
a touch is detected, a transition to State 2 occurs,
where the controller sends out a five-byte data packet,
and turns on the LED. While in State 2, the controller
continues to scan the touchscreen and sends out a new
data packet each as long as a touch is detected. If
a touch is not detected, a transition to State 3 occurs,
where a final data packet is sent with the header byte
set to $80 indicating a touch-up event, the LED is turned
off, and a transition back to State 1 is initiated.
A
low-level subroutine called Convert is used to talk
directly to the touchscreen controller chip. The routine
is similar for both 4- and 5-wire chips. Convert passes
a variable called channel, which contains a 0 or 1.
This variable controls whether we read the x
or y channel of the device. The 12-bit result
comes back in a 16-bit word named ADC.
Convert
is called by a higher level subroutine named Read_Glass.
This routine determines if a touch has occurred and
sets a flag called touch to indicate such. A touch is
determined to have occurred if the result of a Convert
operation is above a certain noise threshold. When Convert
is called and no touch has occurred, a value near zero
is returned.
Wrapping
it Up
Well,
there you have it. Youve seen four different means
of interfacing a resistive touchscreen to your system.
The Burr-Brown chips offer high accuracy, off-the-shelf
solutions to both 4- and 5-wire glass types. My roll-your-own
PIC interface is a minimal parts count design and is
best suited to low-accuracy applications. The TriTech
chip offers a unique solution in that it involves no
firmware. Those of you whose favorite programming language
is solder will appreciate that.