Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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

share|improve this question

2 Answers

up vote 2 down vote accepted

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();
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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