Touch Panel

Status
Not open for further replies.

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:
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;
}
Thanks
 
As far as I know, resistive touchscreens are non linear. And they also have 'dift' which is why so many touchscreen controllers have a 'calibration mode'. I'm afraid its been a while since I did any touch screen stuff...

The code looks good as it just reads the ADC for both X and Y. If I were you, I'd knock up a test routine that displays dots on the lcd, telling you where to press with stylus. Like in an order, diagonally from top left to bottom right, then store the values/read them off/keep them in a PC prog and draw a graph. Measured results are far better than predicted ones

Sorry if this doesn't hlep you much.

Blueteeth
 
Thanks, that is the information that I was looking for. I just wanted to make sure that I was reading the X and Y correctly.
 
Not knowing your clock speed, your acquisition delay may be too short. It would be a good idea to use the built in acquisition time.

Mike.
 
Thanks all, I have got it working now, including the calibration routine. The suggestion from Blueteeth to plot pixels where the touchpanel was reading really helped. Now to design my menu.
 
woot! good man. Glad to hear someone has had some success.

I'm forever writing little test routines to work things out, it sometimes seems like a waste of time, but it allows one to measure things for specific applications, as in your case, finding out just what the resistances are and how they change. In fact I've got about 20 mim PIC boards (8-18pin) for doing just that.

Good luck with the menu

Blueteeth
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…