superbrew
Member
Hello, I am trying to figure out how to use a 4-wire resistive touchscreen in my project. I am having some trouble with a nonlinearity in my readings from the panel. For example if I touch the bottom left corner I get an X reading of ~100 and a Y reading of ~100. If I touch the bottom right, I get an X reading of ~400 (which is what I expected), but a Y reading closer to 200. I am thinking that if I move horizontally across the screen the Y value should not change that much. I am also having a similar problem with the opposite axis. I would like to know if my method of driving the screen is correct method before I try to devise some sort of compensation routine. Here is the code that I am using:
Thanks
Code:
int GetX(void) {
unsigned int result;
//reading X
TRISA = 0b11111010;
PORTAbits.RA0 = 0;
PORTAbits.RA2 = 1;
SetChanADC( ADC_CH3 );
Delay1KTCYx(1);
ConvertADC();
while( BusyADC() );
result = ReadADC();
return result;
}
int GetY(void) {
unsigned int result;
//reading Y
TRISA = 0b11110101;
PORTAbits.RA1 = 0;
PORTAbits.RA3 = 1;
Delay1KTCYx(1);
SetChanADC( ADC_CH2 );
Delay1KTCYx(1);
ConvertADC();
while( BusyADC() );
result = ReadADC();
return result;
}