CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

TFT touch panel calibration

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

TFT touch panel calibration
PostPosted: Mon Oct 31, 2011 2:17 pm     Reply with quote

Hello!

I have a 4.3" TFT display with resistive touch screen and SSD1963 controller connected to a PIC24HJ256GP206.

Everything is working perfectly with graphics etc but I cannot think of a way to calibrate the touch screen.

The display resolution is 480x272 pixels.
The ADC readings is 0-580 for X and 0-360 for Y.

I need a formula to fit the ADC readings linearly in the display resolution.

I tried:
Code:

    touchX=touchX/1.20833;
    touchY=touchY/1.32352;


Because 580/480=1.20833 for X
and 360/272=1.32352 for Y.

This limits the ADC readings to the max X,Y resolution but
it does not relate to the actual coordinates of the display.

Any ideas?

Thanks!
_________________
George.
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Tue Nov 01, 2011 6:21 am     Reply with quote

I don't understand what "actual coordinates of the display" means. With your division calculations, you've already got inputs on a 0-480 and 0-272 scale. What else do you need?
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Nov 01, 2011 8:50 am     Reply with quote

I mean that the "X 100" reading on the ADC does not correspond to PIXEL X 100
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Tue Nov 01, 2011 9:22 am     Reply with quote

It is impossible for us to help without knowing something about what is really happening.
Now, you say the ADC reading is 0-580, for X, but the first thing is where is 0 actually read?. Left edge of screen, right edge of screen?.
The same applies for Y.
Then is it really 0-580, or are you just guessing at the 0, with 580 being the max, but without data for the min?.

The normal way to calibrate a touch screen, is to display points at four known co-ordinates near the corners. Then take ADC readings as each of these points is touched. So (for example), display a cross at X=10, Y=10 (display coordinates) and read the ADC at this point. Then do the same at X=470, Y=10, then X=10, Y=370, and finally X=470, Y=370.

You then have four coordinate pairs giving the ADC readings for these points. Calling them in order, x1, y1, x2, y2 etc.. The maths is then:
Deltax=(x4+x2)-(x1+x3)/2
Deltay=(y4+y3)-(y1+y2)/2
offsetx=(x1+x3)/2
offsety=(y1+y2)/2

Position from a new adc reading x,y then becomes:

(((x-offsetx)*460)/Deltax)+10
Key thing to note, is that this can be done in signed int32 maths, rather than float maths - much faster, because the multiplication is performed first.
Note also that this will handle what I suspect is happening to you. Two things may apply:
1) '0', may not be the actual edge of the display. ADC readings may be something like 20 to 580, not 0 to 580.
2) '0', may not (likely) be the bottom left....


Best Wishes
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Nov 01, 2011 10:15 am     Reply with quote

Thanks for all this info!

X0,Y0 is left top edge.
The actual ADC readings are 98-685 for X and 159-520 for Y.

I just subtract 98 from the X reading and 159 from the Y reading
to make my readings start from 0.
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Tue Nov 01, 2011 10:21 am     Reply with quote

So you need:

touchY=360-(touchY/1.32352);

To make the screen coordinates agree.

Best Wishes
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Fri Nov 04, 2011 5:31 pm     Reply with quote

Ttelmah wrote:


Position from a new adc reading x,y then becomes:

(((x-offsetx)*460)/Deltax)+10



What is 460? Do you mean 480?
Remember that the display resolution is 480x272 pixels.

I tried the method you suggested, it surely works, but again the results are not linear. The accuracy is limited to some part of the display around the center.
The problem is that the touch panel does not give linear results.
For example if you touch the panel at X10,Y10 and you drag across X axis to X400, Y10 the Y ADC reading will not stay constant. It will start at 180 end finish to 160.

Does this affect your code?

Also, I have set all variables for the math as unsigned int32.
Is this a problem?

Thanks!
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Sat Nov 05, 2011 2:52 am     Reply with quote

No, I mean 460.
Remember this was based on calibrating from points at +10, and +470 in X, not the edges of the screen.

Seriously, have you checked what the impedance specification of the touch screen output is?. I'd guess it is quite high. Hence would require a buffer amplifier....

Best Wishes
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Sat Nov 05, 2011 8:27 am     Reply with quote

I found the problem!

I was using pull down resistors on the 2 analog inputs.
This made the reading non linear.

Your method works perfectly!

Thank you very much! Very Happy
_________________
George.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group