I didn't actually calibrate it in the program, I calibrated it on the desk with a PicKit and MPLAB.
You could comment out the lines which do the math on the raw value. Then the touch buffers will contain your raw value. e.g:
Code:
// The following figure is the result (rxd1 & rxd2) inverted (4096-) - the offset (measured) * the range
Touch_Buffer[1][Touch_Counter] = 4096-(rxd1<<5) + (rxd2>>3);
// if(Touch_Buffer[1][Touch_Counter]<Ymin){Touch_Buffer[1][Touch_Counter] = 0;}
// else{Touch_Buffer[1][Touch_Counter] -= Ymin; Touch_Buffer[1][Touch_Counter] *= Yrange;}
// if(Touch_Buffer[1][Touch_Counter]>239) Touch_Buffer[1][Touch_Counter] = 239;
...
and
...
// The following figure is the result (rxd1 & rxd2) - the offset (measured) * the range
Touch_Buffer[0][Touch_Counter] = ((rxd1<<5) + (rxd2>>3));
// if(Touch_Buffer[0][Touch_Counter]<Xmin){Touch_Buffer[0][Touch_Counter] = 0;}
// else{Touch_Buffer[0][Touch_Counter] -= Xmin; Touch_Buffer[0][Touch_Counter] *= Xrange;}
// if(Touch_Buffer[0][Touch_Counter]>319) Touch_Buffer[0][Touch_Counter] = 319;
Once I did that, I just ran that program on my hardware with my PicKit, then touched the corner and then paused the program. Once the program is paused I can check the Touch Buffer in the Watch Window and see the raw values. If you don't use a PicKit (or other hardware capable of debugging within MPLAB) then you will have to write a program to calibrate it within your hardware.
If your screen resolution is different to 320 * 240, then change it on the last line on each block of the above code. e.g:
Code:
if(Touch_Buffer[1][Touch_Counter]>239) Touch_Buffer[1][Touch_Counter] = 63;
...
and
...
if(Touch_Buffer[0][Touch_Counter]>319) Touch_Buffer[0][Touch_Counter] = 127;
You only need the calibration values of each extreme of the screen. e.g. you need 0,0 and 127,63 but not 0,63 and not 127,0.
Once you have found out the raw coordinates of each corner of your screen, you can substitute those values with the values I have used in the header file.
You only need to change these:
Code:
// These are measured calibration values
// Place your own measured calibration values here
#define Xmin 320
#define Xmax 3744
#define Ymin 352
#define Ymax 3792
#define Xrange 0.093458 // =(num of x pixels/(Xmax-Xmin))
#define Yrange 0.069768 // =(num of y pixels/(Ymax-Ymin))
//
For Xrange and Yrange, you can calculate them based on your measured values and your screen resolution.
For example, to calculate mine I used:
Xrange = num of x pixels on screen/(Xmax-Xmin)
Xrange = 320/(3744-320)
Xrange = 0.093458
I hope that answers your questions, and I hope you use MPLAB and a PicKit
