View previous topic :: View next topic |
Author |
Message |
georpo
Joined: 18 Nov 2008 Posts: 278 Location: Athens, Greece.
|
TFT touch panel calibration |
Posted: Mon Oct 31, 2011 2:17 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Tue Nov 01, 2011 6:21 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
georpo
Joined: 18 Nov 2008 Posts: 278 Location: Athens, Greece.
|
|
Posted: Tue Nov 01, 2011 8:50 am |
|
|
I mean that the "X 100" reading on the ADC does not correspond to PIXEL X 100 _________________ George. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19363
|
|
Posted: Tue Nov 01, 2011 9:22 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
georpo
Joined: 18 Nov 2008 Posts: 278 Location: Athens, Greece.
|
|
Posted: Tue Nov 01, 2011 10:15 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19363
|
|
Posted: Tue Nov 01, 2011 10:21 am |
|
|
So you need:
touchY=360-(touchY/1.32352);
To make the screen coordinates agree.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
georpo
Joined: 18 Nov 2008 Posts: 278 Location: Athens, Greece.
|
|
Posted: Fri Nov 04, 2011 5:31 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19363
|
|
Posted: Sat Nov 05, 2011 2:52 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
georpo
Joined: 18 Nov 2008 Posts: 278 Location: Athens, Greece.
|
|
Posted: Sat Nov 05, 2011 8:27 am |
|
|
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](images/smiles/icon_biggrin.gif) _________________ George. |
|
![](templates/subSilver/images/spacer.gif) |
|