AN2376 PSoC 1 - Interface to Four-Wire Resistive Touchscreen.pdf

AN2376
PSoC® 1 – Interface to Four-Wire Resistive Touchscreen
Author: Svyatoslav Paliy, Andrij Bilynskyy
Associated Project: Yes
Associated Part Family: CY8C24x94
Software Version: PSoC ® Designer™ 5.4 CP1
Related Application Notes: None
Abstract
AN2376 shows how PSoC 1 can be used to control a resistive touchscreen, and read (x,y) positions of single
touches as well as touch pressure. It describes the essential mathematics in detail, and includes a method for
calibrating a touchscreen to a display. A project is included that passes touchscreen readings to a PC through a USB
HID interface.
Contents
Introduction
Introduction .......................................................................1
Construction of Resistive Touchscreens ...........................2
Resistive Touchscreen Measurement Method ..................2
PSoC Implementation .......................................................5
Power Consumption (Pen Interrupt) ..................................7
Touchscreen Calibration ...................................................8
Appendix A: Hardware Setup (Not Actual Size) ..............11
Appendix B: Board Bill of Materials .................................12
Appendix C: Touchscreen Controller PC Test Application13
Appendix D: Three-Points Calibration Procedure ............14
Appendix E: Capacitive Touchscreens as Alternative to
Resistive Touchscreens ..................................................16
About the Author .............................................................17
About the Author .............................................................17
Document History ............................................................18
Touchscreen interfaces are effective in many information
appliances, in personal digital assistants (PDAs), and as
generic pointing devices for instrumentation and control
applications. This application note describes resistive types
of touchscreens. Their construction is simple, their cost is
low, and their operation is well understood by users. The
only concern is that the resistive layers can be damaged by
very sharp objects. This document considers the basic
principles of how resistive touchscreens work and how to
best convert these analog inputs into usable digital data
using a PSoC.
When developing more complex touch-assisted projects;
there is often a need for additional peripheral units, such as
operational and instrument amplifiers, filters, timers, digital
logic circuits, AD and DA convertors. As a general rule,
implementation of these extra peripherals brings in
additional difficulties: space for new components, additional
attention during production of a printed circuit board, power
consumption increase. All of these factors can significantly
affect the project price and development cycle.
PSoC has made many engineers’ dreams come true; that is,
to have all their project needs covered in one chip.
www.cypress.com
Document No. 001-15228 Rev. *D
1
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
Construction of Resistive
Touchscreens
Resistive touchscreens are constructed as shown in
Figure 1. They consist of two top transparent glass or acrylic
panels and a bottom transparent insulating panel. Both top
panels are coated with electrically conductive layers. These
layers have uniform resistance made from indium tin oxide
(ITO). The panels are separated by invisible non-conducting
spacers.
Figure 1. Resistive Touchscreen Construction
Transparent
Conductor (ITO)
Bottom Side
YP
The conductive bars are located on the opposite edges of
the panel. The layer has uniform resistance; that is, the
voltage applied to the layer produces a linear gradient
across this layer. Both layers are orthogonal to each other,
and voltage gradients in layers are orthogonal, too. In an
equivalent circuit of a resistive touchscreen, we can offer
conductive layers as resistors between the conductive bars
in the corresponding layers. When we press a touchscreen,
we get a connection between the resistive layers. In a
circuit, we offer this connection as a resistor, too. Equivalent
circuits for touched and untouched touchscreens are shown
in Figure 2.
Figure 2. Touchscreen Equivalent Circuits
Transparent
Conductor (ITO)
Top Side
YP
YP
RY+
RY+
YM
YN
YN
RY-
Conductive Bar
(Silver Ink)
RY-
XN
Rtouch
Rx-
XN
Rx-
XM
Rx+
XP
Untouched
Rx+
XP
Touched
XP
Insulating
Material
(Glass)
The top layer panel is flexible and the bottom layer panel is
rigid. Pressing the flexible top sheet creates an electrical
contact between the resistive layers, essentially closing a
switch in the circuit. The four electrical wires are connected
to conductive bars.
Resistive Touchscreen Measurement
Method
A touch can be defined by three parameters. The first and
second parameters are X-position and Y-position. The third
parameter relates to “touch pressure” and allows the
touchscreen to differentiate between finger and stylus
contacts.
www.cypress.com
To measure a 4-wire touch sensor, a VCC voltage is applied
to a conductive bar on one of the layers while the other
conductive bar on the same layer is grounded, see
Figure 3a. In this powered layer we have a linear voltage
gradient (0.. VCC). One of the conductive bars in the other
layer is connected to an ADC through large impedance. The
ADC reference is set to VCC, which makes the ADC range
(0..max ADC value). When the screen is touched, the ADC
reading corresponds to the position on one of the axes.
To obtain the second coordinate, the other layer must be
powered and read by the ADC. VCC, GND, Analog hi-Z, and
ADC input are switched between the two layers, as shown in
the Y-position measurement in Figure 3. The second ADC
reading corresponds to the position on the other axis.
Finally, to obtain the touch pressure, we take two
measurements of the cross-layer resistance. VCC is applied
to a conductive bar on one of the layers while a conductive
bar on the other layer is grounded. We measure the
voltages on the unconnected bars, shown in depictions c
and d in Figure 3.
Document No. 001-15228 Rev. *D
2
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
Figure 3. Various Parameter Measurements
Vcc
Analog hi-Z
Analog hi-Z
YP
Rx+
ADC
Vref=VCC
XN
XP
Vcc
YP
Touch
Screen
Ry+
Touch
Screen
Rx+
XN
GND
XP
Rx-
ADC
Vref=VCC
Ry+
Rx-
Rtouch
Analog hi-Z
Rtouch
YN
YN
Ry-
RyAnalog hi-Z
PSoC
a) X-position Measurement
GND
PSoC
b) Y-position Measurement
Analog hi-Z
Current (when touched)
YP
Analog hi-Z
Current (when touched)
Vcc
YP
Touch
Screen
ADC
Vref=VCC
Ry+
Rx+
XN
XP
Touch
Screen
Ry+
Rx+
XN
GND
XP
RxRtouch
Vcc
GND
ADC
Vref=VCC
RxRtouch
YN
YN
Ry-
RyAnalog
hi-Z
Analog hi-Z
c) Touch pressure Z1
Measurement
PSoC
Now it’s possible to develop a mathematical equation to
calculate the cross-layer resistance, from our ADC results X,
Y, Z1, Z2 (see Figure 3).
From Figure 3a, you can write:
d) Touch pressure Z2
Measurement
PSoC
By analogy from Figure 3b:
Ry −
Ry −
Y
=
=
ADmax R y − + R y + R y _ plate
Equation 2
V
V
X
= in = in =
ADmax V ref Vcc
iR x −
Rx−
=
=
i (R x − + R x + ) R x − + R x +
Rx−
R x _ plate
Where,
Ry_plate = Ry-+Ry+
– Y-plate resistant
From Figure 3c:
Rx −
Z1
=
ADmax Rx − + Rtouch + R y +
Equation 1
Where,
Equation 3
And from Figure 3d:
X = ADC value when ADC input voltage is equal Vin
ADC_resolution
ADmax=2
–- Maximum ADC value + 1
Rx − + Rtouch
Z2
=
ADmax Rx − + Rtouch + R y +
Vref – Reference ADC voltage, for measurements using Vref
= Vcc
Equation 4
Rx_plate = Rx-+Rx+ – X-plate resistance
www.cypress.com
Document No. 001-15228 Rev. *D
3
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
You can then obtain the cross-layer resistance that represents touch pressure, from Equations 1, 3, and 4:
Rtouch = Rx _ plate ⋅
X
2
ADC _ resolution
 Z2


− 1
 Z1

Equation 5
And the other cross-layer resistance, which also represents touch pressure, from Equations 1, 2, and 3:
Rtouch
 2 ADC _ resolution 
Y


= Rx _ plate ⋅ ADC _ resolution 
− 1 − Ry _ plate 1 − ADC _ resolution 
2
Z1
 2



X
Equation 6
Equation 5 requires a known X-plate resistance,
measurements of X-position (X), and two additional
cross-panel measurements (Z1 and Z2) of the touchscreen
Equation 6 requires known X- and Y-plate resistance values
but only allows measurement of Z1. For calculation touch
pressure, you can use one of those equations. In the real
projects, you must have three touchscreen parameters such
as X-position, Y-position, and pressure. To calculate touch
pressure, you can use either of these equations. Equation 6
requires three ADC measurements while Equation 5
requires four. Using Equation 6 is faster, but its arithmetic is
more complicated.
A flowchart for the touchscreen parameter measurement
routine is shown in Figure 4.
Figure 4. General Touchscreen Parameter Measurement
Routine Flowchart
Start
Configure port to
measure touch
pressure
Configure port for
Y - position
Measurement
Measure Z1 and Z 2
Measure Y
Configure port for
X - position
measurement
Measure X and
calculate touch
pressure, P
Configure port for
touch detection
and ensure that
touch screen is still
touched
Return Parameters
www.cypress.com
Document No. 001-15228 Rev. *D
4
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
PSoC Implementation
The PSoC internal structure is very simple (see Figure 5). Pins P0[1], P0[3], P0[5], and P0[7] are used for the touch panel
interface. Signals from the input pins are switched through the analog column input multiplexer to the PGA, and then to the
delta-sigma ADC.
Figure 5. PSoC Configurations for each of the Measurement Diagrams in Figure 3
YN (Strong 0)
YN (Hi-Z analog)
YP (Hi-Z analog)
YP (Strong 1)
XN (Strong 0)
XN (Hi-Z analog)
XP (Strong 1)
XP (Hi-Z analog)
a) X-position Measurement
b) Y-position Measurement
YN (Hi-Z analog)
YN (Hi-Z analog)
YP (Strong 1)
YP (Strong 1)
XN (Strong 0)
XN (Strong 0)
XP (Hi-Z analog)
XP (Hi-Z analog)
c) Touch pressure Z1
d) Touch pressure Z2
measurment
measurment
www.cypress.com
Document No. 001-15228 Rev. *D
5
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
The PSoC-based schematic is also very simple (see Figure 6). The touchscreen is directly connected to the PSoC device
ports. Resistors R1 and R2 are used as pull downs to terminate the PSoC inputs when the plates are not driven.
Figure 6. Device Schematic
YP
XM
+5V
XP
P2[3]
P2[1]
P4[7]
P4[5]
P4[3]
P4[1]
P3[7]
P3[5]
P3[3]
P3[1]
P5[7]
P5[5]
P5[3]
P5[1]
48
47
46
45
44
43
50
49
R3
24R
42
41
40
39
38
37
36
35
34
33
32
31
30
29
P7[7]
P7[0]
P1[0]
P1[2]
P1[4]
P1[6]
Vss
D+
DVdd
19
20
21
22
15
16
17
18
P1[7]
P1[5]
P1[3]
P1[1]
CY 8C24794
P2[2]
P2[0]
P4[6]
P4[4]
P4[2]
P4[0]
P3[6]
P3[4]
P3[2]
P3[0]
P5[6]
P5[4]
P5[2]
P5[0]
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
R2
1M
P0[6]
P0[4]
P0[2]
P0[0]
P2[6]
P2[4]
P2[5]
P2[7]
P0[1]
P0[3]
P0[5]
P0[7]
YM
Vss
Vdd
U1
Touch Scren
56
55
54
53
52
51
R1
1M
R4
24R
+5V
J1
Vdd
-D
+D
Gnd
1
2
3
4
C1
0.1u
USB
To debug this project, measured data is transferred to the PC through the USB interface. The USB HID device class is used to
simplify data transfer to the PC and to avoid writing a separate USB driver for the PC. The PSoC device sends a data packet
to the PC that contains four 16-bit parameters. Table 1 shows the data packet structure. A simple PC application has been
developed for evaluation (Appendix C).
Table 1. Data Packet Structure
Number
Offset in Bytes
Length in Bytes
1
0
2
X touch coordinate
2
2
2
Y touch coordinate
3
4
2
Z1
4
6
2
Z2
www.cypress.com
Parameter Name
Document No. 001-15228 Rev. *D
6
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
Power Consumption (Pen Interrupt)
PSoC devices have very little power consumption in sleep
mode. If a touchscreen has not been touched for a long
period of time, there is no need for operation or
measurement. The touchscreen is allowed into sleep mode
and waits for a pen interrupt, at which time the controller
wakes up and measures the touch parameters.
To use this feature (see Figure 7), apply a voltage to the
touchscreen XP connector through resistors with the
resistance exceeding the maximal cross-panel touchscreen
resistance in the touched mode by four or more times. In the
proposed design, cross-panel touchscreen resistance
values are about 1K. An internal pull-up resistor Rpull up with
a resistance of 5.6 K can be used. The port pin that is
connected to the touchscreen XP connector is configured to
pull-up mode and set to a logic state of high. The port pin
connected to the XN connector is configured as a digital
input and the pin-interrupt is enabled by a falling edge. If the
touchscreen is still untouched, XN holds the logic in a high
state, while if the touchscreen is touched; the voltage of XN
falls to a low logic level and initiates an interrupt that wakes
up the PSoC. A flowchart for the touchscreen controller
performance using sleep mode is shown in Figure 8.
Pull up “ R
pull up
1”
Start
Have
Actions
to Executing?
No
Configure
Ports for Pen
Interrupt Mode
Go to Sleep
Mode
Yes
Execute
Actions
Pen Interrupt
Measure
Touch Screen
Parameters
RETI
Figure 7. Touchscreen Configured for a Waiting Pen
Interrupt
Current (when touched)
Figure 8. General Touchscreen Controller Routine Flowchart
Using Sleep Mode
Wait, Low
Power
Consumption
Vdd
Analog hi-Z
YP
Touch
Screen
XP
XN
Rtouch
YN
Digital In
Interrupt on
falling edge
Strong “0”
PSoC
www.cypress.com
Document No. 001-15228 Rev. *D
7
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
Touchscreen Calibration
In most cases, the touchscreen is mounted over an LCD or
another display. If this is the case, the data measured by the
touchscreen must be translated into true screen
coordinates.
Figure 9 shows some misaligned touchscreen and display
coordinates. This figure also shows that it is possible to
describe each point on the display as PD = [XD,YD] and
each point on the touchscreen as PT = [XT,YT].
The calibration algorithm proposed in this application note
allows eliminating scaling factors and mechanical
misalignment of the touchscreen. The challenge for the
calibration algorithm is to translate the set of coordinates
reported by the touchscreen into a set of coordinates that
accurately represents a point on the display.
Three error factors are presented:

[X D , YD ] = f ([X T , YT ])

Rotation of the touchscreen coordinates relative to the
display coordinates.


Linear shift of the coordinates.
A scaling factor.
Equation 7
dX
LCD
Touch
LCD
Touch
(XD,YD)=(Rcos(α-dα),Rsin(α-dα))
(XD,YD)=(XT+dX,YT+dY)
(XT,YT)=(Rcos(α),Rsin(α))
(XD,YD)
P (X ,Y )
T T
Scale KY
Figure 9. Error Factors
(XD,YD)=(XT*KX,YT*KY)
(XD,YD)
P (X ,Y )
T T
(XD,YD)
P (X ,Y )
T
T
α-dα
dY
Linear shift error
LCD
Touch
α
C
1
1
dα
11
C
Rotation of the touch
screen error
Scale KX
Scaling error
The LCD coordinate XD can be expressed as:
X D = K x R cos(α − dα ) + dX
= K x R cos α cos dα + K x sin α sin dα + dX
= K x X T cos dα + K xYT sin dα + dX
= α x X T + β xYT + dX
Equation 8
YD = K y R sin (α − dα ) + dY
= K y R sin α cos dα − K y cos α sin dα + dY
= K yYT cos dα − K y X T sin dα + dY
= α y X T + β yYT + dY
Equation 9
Where,
αx = Kxcos(dα), βx = Kxsin(dα), αy = –Kysin(dα), and βy = Kycos(dα).
www.cypress.com
Document No. 001-15228 Rev. *D
8
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
From Equations 8 and 9, when there are three independent points (not on one line), you can get the coefficients αx, αy, βx, βy,
dX, and dY. Assuming that (XD1, YD1), (XD2, YD2), and (XD3, YD3) are three independent points selected on the LCD, and
(XT1, YT1), (XT2, YT2), and (XT3, YT3) are the corresponding points on the touchscreen, Equations 8 and 9 can be used to write
Equation 10:
X D1 = α x X T 1 + β xYT 1 + dX
X D 2 = α x X T 2 + β xYT 2 + dX
X D 3 = α x X T 3 + β xYT 3 + dX
YD1 = α y X T 1 + β yYT 1 + dY
YD 2 = α y X T 2 + β yYT 2 + dY
YD 3 = α y X T 3 + β yYT 3 + dY
Equation 10
Or in matrix form:
 X D1 
 αx 


 
 X D 2  = A ×  β x  and
X 
 dX 
 D3 
 
 YD1 
α y 


 
 YD 2  = A ×  β y 
Y 
 dY 
 D3 
 
Where,
 X T 1 YT 1 1


A =  X T 2 YT 2 1


 X T 3 YT 3 1
From Equation 10:
 αx 
 X D1 
 


−1
 β x  = A ×  X D 2  and
 dX 
X 
 
 D3 
α y 
 YD1 
 


−1
 β y  = A ×  YD 2 
 dY 
Y 
 
 D3 
Equation 11
Where,
A-1 is the inverse of matrix A. The three points—(XD1, YD1), (XD2, YD2), and (XD3, YD3)—are selected on the display surface, and
the elements in matrix A are measured from the touchscreen during calibration.
The 3-points calibration’s equations, in a non-matrix form, and source code for it, optimized for 8-bit cores, are described in
Appendix D.
www.cypress.com
Document No. 001-15228 Rev. *D
9
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
For best results, the first sample point must be located at the distance of approximately 10% of the screen size in the upperleft corner. The second and third points must be at a distance of approximately 10% of the screen size from the screen edges
in the center of each side (see Figure 10). For the calibration process, points 1, 2, and 3 must be touched in an ascending
order.
Calibration must be performed before use for each device that contains a touchscreen. There is no need to perform calibration
every time the device is powered on. However, it is prudent to save the calibration parameters in the energy-independent
memory. Every time the device is used after calibration, it reads these coefficients and uses them to calculate the true screen
coordinates.
Figure 10. Calibration Point’s Placement on Screen
In many applications, users may use more than three points in their calibration routines to average or filter the noisy readings
from the touchscreen controller. For calibration with more than three points:
 X D1 


 X D2 
 αx 
 . 
 
 = A ×  β x  and

 . 
 dX 
 . 
 


X 
 DN 
 YD1 


 YD 2 
α y 
 . 
 
 = A ×  β y  where

 . 
 dY 
 . 
 


Y 
 DN 
 X T 1 YT 1 1


 X T 2 YT 2 1
 . . .

A=
 . . .
 . . 
.

 X Y 1
 TN TN 
Equation 12
To resolve Equation 12, both sides can be multiplied by A’s pseudo-inverse matrix, (AT×A)–1×AT, where AT is A’s transpose
matrix.
 X D1 


 X D1 
 αx 
 . 
 
−1
T
T
 and

×
×
=
×
A
A
A
β
 x
.


 dX 
 . 
 


X 
 DN 
(
www.cypress.com
)
 YD1 


 YD1 
α y 
 . 
 
−1
T
T


=
×
×
×
A
A
A
β
 y
.


 dY 
 . 
 


Y 
 DN 
(
)
Document No. 001-15228 Rev. *D
Equation 13
10
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
Appendix A: Hardware Setup (Not Actual Size)
Top Layer Components
www.cypress.com
Bottom Layer Components
Document No. 001-15228 Rev. *D
Bottom Layer Wires
11
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
Appendix B: Board Bill of Materials
Description
Count
Designator
Manufacturer
Manufacturer Part Number
Digi-Key Part Number
EVALUATION POD FOR
CY8C24X94
1
U1
Cypress
CY3210-24X94
428-1998-ND
Touchscreen
1
-
Bergquist
400426
BER275-ND
Connector
1
J1
Molex Connector
Corporation
52271-0479
WM7954TR-ND
Connector
2
U1 sockets
FCI
95200-301LF
95200-301LF-ND
Resistors (R1, R2)
2
R1, R2
Panasonic - ECG
ERJ-6GEYJ105V
P1.0MATR-ND
Capacitor
1
C1
Kemet
C0805C104M5RACTU
399-1169-2-ND
www.cypress.com
Document No. 001-15228 Rev. *D
12
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
Appendix C: Touchscreen Controller PC Test Application
www.cypress.com
Document No. 001-15228 Rev. *D
13
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
Appendix D: Three-Points Calibration Procedure
The calculation of inverse matrix is very difficult for 8-bit cores. Equation 11 in a non-matrix form:
( X D1 − X D 3 )(YT 2 − YT 3 ) − ( X D 2 − X D 3 )(YT 1 − YT 3 )
( X T 1 − X T 3 )(YT 2 − YT 3 ) − ( X T 2 − X T 3)(YT 1 − YT 3 )
( X − X T 3 )(YD 2 − YD 3 ) − ( X D 2 − X D 3 )(YT 1 − YT 3 )
β x = T1
( X T 1 − X T 3 )(YT 2 − YT 3 ) − ( X T 2 − X T 3)(YT 1 − YT 3 )
αx =
dX =
YT 1 ( X T 3 X D 2 − X T 2 X D 3 ) + YT 2 ( X T 1 X D 3 − X T 3 X D1 ) + YT 3 ( X T 2 X D1 − X T 1 X D 2 )
( X T 1 − X T 3 )(YT 2 − YT 3 ) − ( X T 2 − X T 3 )(YT 1 − YT 3 )
(YD1 − YD 3 )(YT 2 − YT 3 ) − (YD 2 − YD 3 )(YT 1 − YT 3 )
( X T 1 − X T 3 )(YT 2 − YT 3 ) − ( X T 2 − X T 3)(YT 1 − YT 3 )
( X − X T 3 )(YD 2 − YD 3 ) − (YD1 − YD 3 )( X T 2 − X T 3 )
β y = T1
( X T 1 − X T 3 )(YT 2 − YT 3 ) − ( X T 2 − X T 3)(YT 1 − YT 3 )
Y ( X Y − X T 2YD 3 ) + YT 2 ( X T 1YD 3 − X T 3YD1 ) + YT 3 ( X T 2YD1 − X T 1YD 2 )
dY = T 1 T 3 D 2
( X T 1 − X T 3 )(YT 2 − YT 3 ) − ( X T 2 − X T 3 )(YT 1 − YT 3 )
αy =
The right sides of the all expressions contain the same denominator. This can be very useful for integer arithmetic, isolating
the denominator and marking it as a C vector:
C [0] = ( X T 1 − X T 3 )(YT 2 − YT 3 ) − ( X T 2 − X T 3 )(YT 1 − YT 3 )
C [1] = ( X D1 − X D 3 )(YT 2 − YT 3 ) − ( X D 2 − X D 3 )(YT 1 − YT 3 )
C [2] = ( X T 1 − X T 3 )(YD 2 − YD 3 ) − ( X D 2 − X D 3 )(YT 1 − YT 3 )
C [3] = YT 1 ( X T 3 X D 2 − X T 2 X D 3 ) + YT 2 ( X T 1 X D 3 − X T 3 X D1 ) + YT 3 ( X T 2 X D1 − X T 1 X D 2 )
C [4] = (YD1 − YD 3 )(YT 2 − YT 3 ) − (YD 2 − YD 3 )(YT 1 − YT 3 )
C [5] = ( X T 1 − X T 3 )(YD 2 − YD 3 ) − (YD1 − YD 3 )( X T 2 − X T 3 )
C [6] = YT 1 ( X T 3YD 2 − X T 2YD 3 ) + YT 2 ( X T 1YD 3 − X T 3YD1 ) + YT 3 ( X T 2YD1 − X T 1YD 2 )
Now Equations 8 and 9 look like:
C[1] X T + C[2]YT + C[3]
C[0]
C[4] X T + C[5]YT + C[6]
YD =
C[0]
XD =
This method is optimal for 8-bit cores. The following code demonstrates it.
www.cypress.com
Document No. 001-15228 Rev. *D
14
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
// PSoC designer sample code for 3-points calibration procedure.
// Define point type X,Y
typedef struct tPoint{
signed int x;
// signed value by calibration
signed int y;
// rotation or shift can return little neg value
}tPoint;
// Calibration vector C, init it default values
static signed long CIndex[7];
// Global points on touch and display
// Tp – received point on touch
// Dp – calculated point on display
static tPoint Dp, Tp;
// Refresh the display point from the received touch point
void DisplayPointGet(void)
{
Dp.x = (CIndex[1]*Tp.x + CIndex[2]*Tp.y + CIndex[3])/CIndex[0];
Dp.y = (CIndex[4]*Tp.x + CIndex[5]*Tp.y + CIndex[6])/CIndex[0];
}
//
//
//
//
3-point calculate calibration indexes
Input:
Tp - pointer to array of 3 points on touchscreen
Dp - pointer to array of 3 points on display
void CalculateCalibrationConstants(tPoint *Dp, tPoint *Tp)
{
CIndex[0] = (signed long)(Tp->x-(Tp+2)->x)*((Tp+1)->y-(Tp+2)->y)
- (signed long)((Tp+1)->x-(Tp+2)->x)*(Tp->y-(Tp+2)->y);
CIndex[1] = (signed long)(Dp->x-(Dp+2)->x)*((Tp+1)->y-(Tp+2)->y)
- (signed long)((Dp+1)->x-(Dp+2)->x)*(Tp->y-(Tp+2)->y);
CIndex[2] = (signed long)(Tp->x-(Tp+2)->x)*((Dp+1)->x-(Dp+2)->x)
- (signed long)(Dp->x-(Dp+2)->x)*((Tp+1)->x-(Tp+2)->x);
CIndex[3] = (signed long)Tp->y*((signed long)(Tp+2)->x*(Dp+1)->x
-(signed long)(Tp+1)->x*(Dp+2)->x)
+ (signed long)(Tp+1)->y*((signed long)Tp->x*(Dp+2)->x
-(signed long)(Tp+2)->x*Dp->x)
+ (signed long)(Tp+2)->y*((signed long)(Tp+1)->x*Dp->x
-(signed long)Tp->x*(Dp+1)->x);
CIndex[4] = (signed long)(Dp->y-(Dp+2)->y)*((Tp+1)->y-(Tp+2)->y)
long)((Dp+1)->y-(Dp+2)->y)*(Tp->y-(Tp+2)->y);
- (signed
CIndex[5] = (signed long)(Tp->x-(Tp+2)->x)*((Dp+1)->y-(Dp+2)->y)
- (signed long)(Dp->y-(Dp+2)->y)*((Tp+1)->x-(Tp+2)->x);
CIndex[6] = (signed long)Tp->y*((signed long)(Tp+2)->x*(Dp+1)->y
-(signed long)(Tp+1)->x*(Dp+2)->y)
+ (signed long)(Tp+1)->y*((signed long)Tp->x*(Dp+2)->y
-(signed long)(Tp+2)->x*Dp->y)
+ (signed long)(Tp+2)->y*((signed long)(Tp+1)->x*Dp->y
-(signed long)Tp->x*(Dp+1)->y);
}
www.cypress.com
Document No. 001-15228 Rev. *D
15
®
PSoC 1 – Interface to Four-Wire Resistive Touchscreen
Appendix E: Capacitive Touchscreens as Alternative to Resistive Touchscreens
A capacitive touchscreen panel consists of an insulator
such as glass coated with a transparent conductor such as
indium tin oxide (ITO). Because a human body is also an
electrical conductor, touching the surface of the screen
results in a distortion of the screen's electrostatic field
measurable as a change in its capacitance. Different
technologies can be used to determine the location of a
touch. The location is then sent to the controller for
processing. Unlike a resistive touchscreen, you cannot
use a capacitive touchscreen through most types of
electrically insulating materials, such as gloves. You need
a special capacitive stylus, or a special-application glove
with finger tips that generate static electricity. This
disadvantage especially affects capacitive touchscreens’
usability in consumer electronics, such as touch tablet
PCs and capacitive smart phones in cold weather.
In surface capacitance basic technology, only one side of
the insulator is coated with a conductive layer. A small
voltage is applied to the layer, resulting in a uniform
electrostatic field. When a conductor, such as a human
finger, touches an uncoated surface, a capacitor is
dynamically formed. The sensor's controller can determine
the location of a touch indirectly, basing on the change in
the capacitance as measured from the four corners of the
panel. Because it has no moving parts, the controller is
moderately durable but has a limited resolution. It is prone
to false signals from parasitic capacitive couplings, and
needs calibration during manufacturing. It is therefore
most often used in simple applications such as industrial
controls and kiosks.
Projected capacitive touch (PCT) technology is a
capacitive technology that permits more accurate and
flexible operation by etching the conductive layer. An X-Y
grid is formed either by etching a single layer to form a
grid pattern of electrodes, or by etching two separate,
perpendicular layers of a conductive material with parallel
lines or tracks to form a grid (comparable to the pixel grid
found in many LCD displays).
A greater resolution of PCT allows operation without a
direct contact. The conducting layers can be coated with
further protective insulating layers, and operate even
under screen protectors, or behind weather and
vandal-proof glass. PCT is a more robust solution
www.cypress.com
compared to the resistive touch technology because the
PCT layers are made from glass. Depending on the
implementation, an active or passive stylus can be used
instead of or in addition to a finger. This is common with
point-of-sale devices that require a signature capture.
Gloved fingers may or may not be sensed, depending on
the implementation and gain settings. Conductive
smudges and similar interference on the panel surface can
interfere with the performance. Such conductive smudges
come mostly from sticky or sweaty fingertips, especially in
high humidity environments. Collected dust, which
adheres to the screen due to the moisture from fingertips,
can also be a problem. There are two types of PCT: Self
Capacitance and Mutual Capacitance.
A PCT screen consists of an insulator such as glass or
foil, coated with a transparent conductor (Copper, ATO,
Nanocarbon, or ITO). If a finger (which is also a
conductor) touches the surface of the screen, the local
electrostatic field distorts. This distortion can be measured
to obtain the finger coordinates. Nowadays, mutual
capacitive technology is more common than PCT
technology.
In mutual capacitive sensors, there is a capacitor at every
intersection of each row and each column. A 16-by-14
array, for example, has 224 independent capacitors. A
voltage is applied to the rows or columns. Bringing a finger
or conductive stylus close to the surface of the sensor
changes the local electrostatic field, which reduces the
mutual capacitance. The capacitance change at every
individual point on the grid can be measured to accurately
determine the touch location by measuring the voltage in
the other axis. Mutual capacitance allows multi-touch
operation where multiple fingers, palms, or styli can be
accurately tracked at the same time.
Self-capacitance sensors can have the same X-Y grid as
mutual capacitance sensors, but the columns and rows
operate independently. With self-capacitance, the
capacitive load of a finger is measured on each column or
row electrode by a current meter. This method produces a
stronger signal than the mutual capacitive method, but it is
unable to detect accurately more than one finger, which
results in "ghosting", or misplaced location sensing.
Document No. 001-15228 Rev. *D
16
®
PSoC 1 – Interface to Four-wire Resistive Touchscreen
About the Author
Name:
Svyatoslav Paliy
Title:
Engineer
Background:
Svyatoslav Paliy graduated from Lviv
Polytechnic
National
University
(Ukraine) in 2000. His interests include
various aspects of embedded systems
design in addition to Windows and
Linux programming.
Contact:
[email protected]
Name:
Andrij Bilynskyy
Title:
Application Engineer
Background:
Andrij Bilynskyy graduated from Ivan
Franko National University of Lviv in
2003. His interests include SW/HW
electronic design and Embedded OS.
Contact:
[email protected]
www.cypress.com
Document No. 001-15228 Rev. *D
17
®
PSoC 1 – Interface to Four-wire Resistive Touchscreen
Document History
Document Title: PSoC® 1 – Interface to Four-wire Resistive Touchscreen - AN2376
Document Number: 001-15228
Revision
ECN
Orig. of
Change
Submission
Date
Description of Change
**
1063380
XSG
05/11/2007
New application note.
*A
1551303
XSG
10/05/2007
Changed title
*B
3347438
ANBI_UKR
08/18/2011
Project support the latest version PSoC designer
*C
3479341
ANJR_UKR
01/12/2011
Title Updated
Major content update.
*D
4528452
RJVB
10/08/2014
®
Updated Software Version as “PSoC Designer™ 5.4 CP1” in page 1.
Updated attached example project to PD5.4 CP1.
Updated to new template.
Completing Sunset Review.
www.cypress.com
Document No. 001-15228 Rev. *D
18
®
PSoC 1 – Interface to Four-wire Resistive Touchscreen
Worldwide Sales and Design Support
Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find
the office closest to you, visit us at Cypress Locations.
PSoC® Solutions
Products
Automotive
cypress.com/go/automotive
psoc.cypress.com/solutions
Clocks & Buffers
cypress.com/go/clocks
PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP
Interface
cypress.com/go/interface
Lighting & Power Control
cypress.com/go/powerpsoc
cypress.com/go/plc
Memory
cypress.com/go/memory
Optical Navigation Sensors
cypress.com/go/ons
PSoC
cypress.com/go/psoc
Touch Sensing
cypress.com/go/touch
USB Controllers
cypress.com/go/usb
Wireless/RF
cypress.com/go/wireless
Cypress Developer Community
Community | Forums | Blogs | Video
| Training
In March of 2007, Cypress recataloged all of its Application Notes using a new documentation number and revision code. This new documentation
number and revision code (001-xxxxx, beginning with rev. **), located in the footer of the document, will be used in all subsequent revisions.
PSoC is a registered trademark of Cypress Semiconductor Corp. All other trademarks or registered trademarks referenced herein are the property of
their respective owners.
Cypress Semiconductor
198 Champion Court
San Jose, CA 95134-1709
Phone
Fax
Website
: 408-943-2600
: 408-943-4730
: www.cypress.com
© Cypress Semiconductor Corporation, 2007-2014. The information contained herein is subject to change without notice. Cypress Semiconductor
Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any
license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or
safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as
critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The
inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies
Cypress against all charges.
This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide
patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a
personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative
works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress
integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source
Code except as specified above is prohibited without the express written permission of Cypress.
Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the
right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or
use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a
malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress’ product in a life-support systems
application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.
Use may be limited by and subject to the applicable Cypress software license agreement.
www.cypress.com
Document No. 001-15228 Rev. *D
19
Similar pages