Difference between revisions of "Resistive Touchscreen"

From Mech
Jump to navigationJump to search
 
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Overview ==
NOTE: THIS INFORMATION PERTAINS TO ACCELEROMETER'S AND IS BEING USED HERE AS A PLACEMARKER. IT WILL BE REMOVED SHORTLY AND REPLACED WITH USEFUL SCHOLARLY INFORMATION VERY SOON.


[[image:Bergquist hand ball balancing.jpg|[[A small Bergquist resistive touchscreen]]|right]]


Resistive touchscreens are useful for measuring the position of an object on top of them, or as an interesting user interface feature. The [http://www.bergquistcompany.com/touchscreens.cfm Bergquist] company sells them in a variety of sizes, ranging from 3.5 to 23 inches diagonal.


The 12.1 inch version was used in the [[Ball Balancing Challenge]] project. Its [http://www.bergquistcompany.com/to_technical_specs.cfm specifications] can be found on the Bergquist website. The screens are transparent and are meant to be installed over an LCD display; however, they are also useful in a horizontal orientation (as in the "Ball Balancing Challenge" project) for sensing the position of an object resting above.


According to the technical specifications, the activation force for this touch screen is 50g. From experience, activation is more reliable with a heavier weight. The area of contact may also play a role in activation; metal balls rolling on the screen produced a slightly noisy signal which needed to be filtered for reliable use in a real-time system.
[[image:mems accelerometer.png|right]]


<br clear=all>
Accelerometers measure linear acceleration and also gravity; the two are indistinguishable. Thus they unavoidably function as tilt sensors as well. Inexpensive 1, 2, and 3-axis accelerometers are available which are constructed with MEMS techniques.
MEMS gyroscopes are also available, for measuring angular velocity, but are more expensive.


== Implementation ==


A resistive touchscreen is essentially a large variable resistor. When a potential is put across two opposite sides of the touch screen, an output voltage can be read that is proportional to the touching distance between the activated sides. The Bergqist screen is a 5-wire resistive screen; its connections consist of four wires going to each of the corners (upper left, upper right, lower left, lower right) and one that goes to the surface. A potential across two opposite sides of the screen results in a gradient across the screen in that direction. When the surface is pushed in at a certain point, it forms a circuit, the output voltage of which can be read as an analog input into a PIC chip.
<br clear=all>


There are several ways to read a 5-wire resistive touchscreen. In the "Ball Balancing Challenge" project, the voltage gradient in one direction was created by placing +5 volts on two adjacent corners (for example the upper right and upper left) and grounding the other two. The position in the vertical direction was then read as proportional to the voltage on the middle (surface) wire.
[[Image:carrier.jpg|right]]


Of course, this method only allows for the reading of one axis of the screen at a time. In order to read both the X and Y positions of the touchscreen, it is possible to use an interrupt service routine to switch rapidly between X and Y readings. For example, the +5V side can be switched between X and Y positions by alternating the voltage between the upper left (UL) and upper right (UR) corners and the upper left and lower left (LL) corners. Correspondingly, grounding will be switched between the lower left and lower right (LR) corners, and the upper right and lower right corners. This results in a type of square wave output on the screen wire, with its voltage representing the vertical and horizontal positions alternatively.


The voltage gradient in both the X and Y directions is linearly distributed from +5V to ground. Because the touch screens are typically rectangular, it may be necessary to multiply one of the readings by the screen's aspect ratio in order to create an equal coordinate system.
The LIS2L02AS4-TR accelerometer gives you a choice of +/-2g or +/-6g full scale. It needs only a single +5V supply. Its bandwidth is from DC to 1.5KHz. The output is usually low-pass filtered in applications which do not need the full 1.5KHz bandwidth, using an external capacitor.


[[Image:Touchscreen.JPG|left|thumb|Touchscreen|200px]]
The chip is available only in a surface-mount SO-24 package. Fortunately an adapter socket (Digikey A322-ND) can be used to give the chip convenient DIP-24 legs.
[[Image:Touchscreenribbon.JPG|right|thumb|Touchscreen cable for output|200px]]


<br clear=all>
<br clear=all>


== Circuit ==
[[Image:somesoldered.jpg|right]]
Soldering the chip into the adapter socket is a little challenging. Here are some tricks that make it easier. The more of these you can take advantage of, the easier it will be.


The voltage switching described above must be accomplished quickly and precisely (so as to avoid a shortage). One way to accomplish this is to permanently power opposite corners with +5V and ground, and then switch the other two according to an ISR. The alternating PIC output signal is sent to one of the corners, and the other one gets its opposite signal through an inverter. The inverter ensures that only one axis of the touch screen is activated at a time.


* Use a very fine pointed soldering iron and fine solder.
* Apply a bead of liquid flux to the pads, which will make the solder flow in between the pin and the pad enthusiastically.
* Tape the chip down onto its socket adapter.
* Have a magnifying lens or loupe available.
* Know which pins are not used.


[[Image:Touchscreen-circuit-diagram.JPG|center|thumb|Touchscreen Circuit Diagram|600px]]


The last point is especially useful. Start with pin 1 which is NC (Not Connected), so that even if you get a solder blob connecting pins 1 & 2 that's ok. If the other pins are all aligned with their pads, pin 1's solder will now hold them there. If not, melt pin 1's solder and adjust.


== Software ==


This code will power the touchscreen and take readings of the x and y axes. It might be a good idea when reading this code to put the touchscreen reading into an interrupt service routine so the screen can be read regardless of what else is going on.
[[Image:chip.gif|right]]


<pre>


/*
Now solder only the other pins that are in use, as shown in red on the diagram. Solder one or two on the opposite edge as well, for mechanical stability.
touchscreen.c
Reads the touchscreen individually as two axes.
PIC powers either the Upper Left (Y-axis reading) or the Lower Right (X-axis reading) and grounds what it doesn't power.
Output reading is the value on that axis.
Upper Left (UL) corner is PIN_C1, and Lower Left (LR) corner is always its inverse.
Upper Right (UR) corner is always high, and lower right (LL) is always ground, its inverse.
Peak voltage: Top reading voltage=4V and bottom reading voltage=1.2V
Reading is 0V when nothing is touching the screen.


*/


#include <18f4520.h>
Pins marked "reserved" should not be solder-blobbed to their neighbors because we don't know what they connect to inside the chip. Reserved is not the same thing as NC.
#DEVICE ADC=8 // set ADC to 8 bit accuracy
#fuses HS,NOLVP,NOWDT,NOPROTECT, CCP2B3 // CCP2B3 moves PWM2 output to pin 36 (RB3) rather than pin 16 (RC1)
#device icd=true
#use delay(clock=20000000)




int yread,xread,m,j=0;
<br clear=all>

[[Image:circuit.gif|right]]
void main() {
for (j=0;j<3;j++){
output_d(0b11111111);
delay_ms(250);
output_d(0);
delay_ms(250);
}
output_high(PIN_C1); //Start with UL high, LR low ***THESE WILL CHANGE***
output_high(PIN_C0); //This is the pin for UR. It will be run through an inverter for LL
//the bottom left corner. ***THESE ARE PERMANENT***
setup_adc_ports(AN0_TO_AN2); // Enable analog inputs; choices run from just AN0, up to AN0_TO_AN11
setup_adc(ADC_CLOCK_INTERNAL); // the range selected has to start with AN0
while (TRUE) {
//Touchscreen reading, looks at the touchscreen readings
if (m==0) {
output_high(PIN_C1); //UL goes high, thus LR goes low; y-axis can be read
set_adc_channel(0);
delay_us(10);
yread = read_adc(); //Read y axis
m++;
}
else {
output_low(PIN_C1); //UL goes low, thus LR goes high; x-axis can be read
set_adc_channel(0);
delay_us(10);
xread = read_adc(); //Read x axis
m=0;
}
}
}


</pre>


Use a supply shunt near the chip (1uF) from +5 to ground). Use low-pass filter capacitors on the outputs (called Cload in the diagram). The output impedance of the chip is 110Kohm, so a 0.1uF capacitor gives a low pass time constant of ~10mS.




Tie ST, PD low, and FS low for +/-2g full scale operation. The output voltage ranges 0-5V, well matched to PIC inputs. 2.5V is the output when acceleration is zero and and the chip is horizontal (not tilted.)


== External Links ==


[http://www.bergquistcompany.com/to_flexibility.cfm Bergquist Resistive Touchscreen Reference] <br>
The circuit shows some optional buffer amplifiers to produce a low impedance output.

Latest revision as of 01:05, 21 March 2008

Overview

A small Bergquist resistive touchscreen

Resistive touchscreens are useful for measuring the position of an object on top of them, or as an interesting user interface feature. The Bergquist company sells them in a variety of sizes, ranging from 3.5 to 23 inches diagonal.

The 12.1 inch version was used in the Ball Balancing Challenge project. Its specifications can be found on the Bergquist website. The screens are transparent and are meant to be installed over an LCD display; however, they are also useful in a horizontal orientation (as in the "Ball Balancing Challenge" project) for sensing the position of an object resting above.

According to the technical specifications, the activation force for this touch screen is 50g. From experience, activation is more reliable with a heavier weight. The area of contact may also play a role in activation; metal balls rolling on the screen produced a slightly noisy signal which needed to be filtered for reliable use in a real-time system.


Implementation

A resistive touchscreen is essentially a large variable resistor. When a potential is put across two opposite sides of the touch screen, an output voltage can be read that is proportional to the touching distance between the activated sides. The Bergqist screen is a 5-wire resistive screen; its connections consist of four wires going to each of the corners (upper left, upper right, lower left, lower right) and one that goes to the surface. A potential across two opposite sides of the screen results in a gradient across the screen in that direction. When the surface is pushed in at a certain point, it forms a circuit, the output voltage of which can be read as an analog input into a PIC chip.

There are several ways to read a 5-wire resistive touchscreen. In the "Ball Balancing Challenge" project, the voltage gradient in one direction was created by placing +5 volts on two adjacent corners (for example the upper right and upper left) and grounding the other two. The position in the vertical direction was then read as proportional to the voltage on the middle (surface) wire.

Of course, this method only allows for the reading of one axis of the screen at a time. In order to read both the X and Y positions of the touchscreen, it is possible to use an interrupt service routine to switch rapidly between X and Y readings. For example, the +5V side can be switched between X and Y positions by alternating the voltage between the upper left (UL) and upper right (UR) corners and the upper left and lower left (LL) corners. Correspondingly, grounding will be switched between the lower left and lower right (LR) corners, and the upper right and lower right corners. This results in a type of square wave output on the screen wire, with its voltage representing the vertical and horizontal positions alternatively.

The voltage gradient in both the X and Y directions is linearly distributed from +5V to ground. Because the touch screens are typically rectangular, it may be necessary to multiply one of the readings by the screen's aspect ratio in order to create an equal coordinate system.

Touchscreen
Touchscreen cable for output


Circuit

The voltage switching described above must be accomplished quickly and precisely (so as to avoid a shortage). One way to accomplish this is to permanently power opposite corners with +5V and ground, and then switch the other two according to an ISR. The alternating PIC output signal is sent to one of the corners, and the other one gets its opposite signal through an inverter. The inverter ensures that only one axis of the touch screen is activated at a time.


Touchscreen Circuit Diagram


Software

This code will power the touchscreen and take readings of the x and y axes. It might be a good idea when reading this code to put the touchscreen reading into an interrupt service routine so the screen can be read regardless of what else is going on.


/*
touchscreen.c 
Reads the touchscreen individually as two axes. 
PIC powers either the Upper Left (Y-axis reading) or the Lower Right (X-axis reading) and grounds what it doesn't power.
Output reading is the value on that axis.
Upper Left (UL) corner is PIN_C1, and Lower Left (LR) corner is always its inverse.
Upper Right (UR) corner is always high, and lower right (LL) is always ground, its inverse.
Peak voltage: Top reading voltage=4V and bottom reading voltage=1.2V
Reading is 0V when nothing is touching the screen.

*/

#include <18f4520.h>
#DEVICE ADC=8                      // set ADC to 8 bit accuracy
#fuses HS,NOLVP,NOWDT,NOPROTECT, CCP2B3      // CCP2B3 moves PWM2 output to pin 36 (RB3) rather than pin 16 (RC1)
#device icd=true
#use delay(clock=20000000)


int yread,xread,m,j=0;

void main() {
   for (j=0;j<3;j++){
      output_d(0b11111111);
      delay_ms(250);
      output_d(0);
      delay_ms(250);
   }
   output_high(PIN_C1);          //Start with UL high, LR low ***THESE WILL CHANGE***
   output_high(PIN_C0);          //This is the pin for UR. It will be run through an inverter for LL
                                 //the bottom left corner. ***THESE ARE PERMANENT***
  
   setup_adc_ports(AN0_TO_AN2);        // Enable analog inputs; choices run from just AN0, up to AN0_TO_AN11
   setup_adc(ADC_CLOCK_INTERNAL);      // the range selected has to start with AN0
  
 
   while (TRUE) {
         //Touchscreen reading, looks at the touchscreen readings
         if (m==0) {
            output_high(PIN_C1);       //UL goes high, thus LR goes low; y-axis can be read
            set_adc_channel(0);
            delay_us(10);          
            yread = read_adc();       //Read y axis           
            m++;
         }
         else {
            output_low(PIN_C1);        //UL goes low, thus LR goes high; x-axis can be read
            set_adc_channel(0);
            delay_us(10);          
            xread = read_adc();       //Read x axis
            m=0;
         }               
   }
}



External Links

Bergquist Resistive Touchscreen Reference