3
\$\begingroup\$

I was reading this article today about interfacing a microcontroller with a 4-wire resistive touch screen, and found myself a little bit confused.

The article suggested this could be done by using four digital i/o pins and two ADC inputs. Two of the four touch screen interface wires are for the X-axis and two are for the Y-axis. The pairs are operated on independently (e.g. the other pair is tristated by the microcontroller).

The operation performed by the microcontroller on each pair is to apply Vcc to one wire and apply Gnd to the other. The wire to which Gnd is applied is also connected to an ADC input on the microcontroller, and the voltage read is proportional to the position being touched along that axis.

What I don't understand is why the ADC would ever read anything but 0V since the microcontroller is driving that wire to Gnd. How does this work?

Here is the schematic from the article for reference:

enter image description here

\$\endgroup\$
2
\$\begingroup\$

I think the reading is taken from the other axis. So if you want to read the X axis you apply power/ground to the X wires and read the ADC connected to Y.
If you notice in the code snippet it says power is applied to X axis but reading is taken from CH0 (RA0) and named result_y (I think the diagram may have RC0 and RC3 connections mixed up though):

//Set PORTA To Inputs/High Impedance
TRISAbits.TRISA0 = 1;
TRISAbits.TRISA1 = 1;

//Set Lower 2 Bits to High Impedance
TRISCbits.TRISC0 = 1;
TRISCbits.TRISC1 = 1;
//Set Higher 2 Bits to Output
TRISCbits.TRISC2 = 0;
TRISCbits.TRISC3 = 0;

PORTCbits.RC0 = 0;
PORTCbits.RC1 = 0;
//Provide Ground To X-axis Of Touch Screen
PORTCbits.RC2 = 0;
//Provide Power To X-axis Of Touch Screen
PORTCbits.RC3 = 1;

// configure A/D convertor
OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & 
ADC_8ANA_0REF,ADC_CH0 & ADC_INT_OFF );

Delay10TCYx( 5 ); // Delay for 50TCY
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for completion
result_y = ReadADC(); // Read result
CloseADC();
\$\endgroup\$
1
\$\begingroup\$

Oli Glaser is right.

The article suggests to use 4 analog pins and 2 digital output pins to send current through the touchscreen. On most recent PICs you can set pins as digital output and analog input, and switching between the two modes is as simple as changing the TRIS registers.

So depending on your microcontroller you can probably use 4 pins instead of 6 for this task.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.