Resistive Touch Issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Resistive Touch Issue

2,150 Views
anujtanksali
Contributor II

Hello,
Am using iMXRT1064 with Emwin library and 7" resistive touch screen. I am using a custom ADC driver to read x and y values.

// points p0,p1,p2 x and y pixels
int touchRefValX[3] = {40,760,400};
int touchRefValY[3] = {24,240,456};
// ADC x and y values at above points
int touchSampleValX[3] = {2552,1504,1954};
int touchSampleValY[3] = {2295,1923,1803};

the range of ADC values for x and y are always in around 1400 counts to 2500 counts.For 12 bit range should be 0-4096.
// init
GUI_TOUCH_CalcCoefficients(3, &touchRefValX[0], &touchRefValY[0], &touchSampleValX[0], &touchSampleValY[0], 800, 480);
GUI_TOUCH_EnableCalibration(1);

//read touch
pressed = get_adc(&touchX,&touchY)
if(pressed == TRUE){
touchState.Pressed = TRUE;
touchState.x = touchX;
touchState.y = touchY;
GUI_TOUCH_StoreStateEx(&touchState);
prevState = pressed;
}
else if(prevState != pressed){
touchState.x = -1;
touchState.y = -1;
touchState.Pressed = FALSE;
prevState = pressed;
GUI_TOUCH_StoreStateEx(&touchState);
}
I get the pressed and un-pressed but actual touch it does not work as expected. i don't get the events as expected.
What am i doing wrong? Any sample code with similar configuration would be helpful.

Thanks & Regards
Anuj

Labels (1)
0 Kudos
10 Replies

533 Views
paulocabral
Contributor I

Hello @anujtanksali, how are you?

I'm facing the same problem to work with resistive touch using IMXRT ADC, did you solve you problem and does it possible you share with me this part of the code for i try to implement in my project?

I'm was reading this https://www.nxp.com/docs/en/user-guide/UM03001.pdf, and try to implement that part on page 636.

Thanks a lot

 

0 Kudos

2,130 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi anujtanksali,

   RT1064 ADC reference voltage is 3.3V, so your 12bit ADC max data 4095 is the 3.3V.

   Do you test your resistive touch related pins, you can test the voltage, then convert it to the ADC data, whether it is the same as the ADC readout data?

   Please check the X and Y voltage, and calculate it, just used to check the ADC readout data is simliar to your calculate data.

Any updated information, please kindly let me know.

Best Regards,

Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

 

0 Kudos

2,114 Views
anujtanksali
Contributor II

Hello,

I will see if i can measure the voltages and compare with the read counts.

I am getting ADC count range as 2500-1500. If i Touch LCD at RIGHT most position i get around 2500 and similarly LEFT most LCD Touch position gives me around 1500 counts. Note these are X counts

Touch at LCD TOP position gives me Y as 2300 ADC counts and touch at BOTTOM position gives me 

1780 ADC counts.

This range should be in 0-4096 counts as using 12 bit internal ADC of iMXRT1064. Am getting around 1000 counts only. As the LCD resolution is 800x480 the reduced ADC count range could will be an issue.

As the Touch resistive pins are to be used as GPIO as well as ADC i have initially configured then as GPIO and then for ADC reading I configure the pin as input 

Please see steps below

1) Set the X+ as High and X- as zero

2) Set the Y- and Y+ as GPIO inputs.

3) Read Y+ as below 

touchAdcChannelConfigStruct.channelNumber = 4;

// Trigger the conversion start.
TCH_ADC_SetChannelConfig(&touchAdcChannelConfigStruct);

// Wait for conversion complete. if TRUE conversion is complete.
while (0U == TCH_ADC_GetChannelStatusFlags())
{

}
// Read the value if conversion is complete.
adcVal = TCH_ADC_GetChannelConversionValue();

4) Set Y+ as High

5) Set X- and X+ as GPIO inputs

6) Read X+ as below

touchAdcChannelConfigStruct.channelNumber = 3;

// Trigger the conversion start.
TCH_ADC_SetChannelConfig(&touchAdcChannelConfigStruct);

// Wait for conversion complete. if TRUE conversion is complete.
while (0U == TCH_ADC_GetChannelStatusFlags())
{

}
// Read the value if conversion is complete.
adcVal = TCH_ADC_GetChannelConversionValue();

7) So i get the ADC X and ADC Y counts as above

Please let me know your thoughts on the same. 

 Thanks

Regards

Anuj

 

0 Kudos

2,098 Views
anujtanksali
Contributor II

Hello,

Adding to above reply.

my latest emwin related code is as below,

uint16_t touchX = 0;
uint16_t touchY = 0;
uint8_t pressed = FALSE;
static uint8_t prevState = FALSE;


// Call the function to get the raw values of x,y
pressed = Touch_getPositionRaw(&touchX, &touchY);

if(pressed == TRUE){

// Set the parameters to send to emwin.
touchState.Pressed = TRUE;

// Set the values;
touchState.x = touchX;
touchState.y = touchY;
// Store the pressed state for emwin to process.
GUI_TOUCH_StoreStateEx(&touchState);
prevState = pressed;
}
else if(prevState != pressed){

prevState = pressed;
touchState.Pressed = FALSE;
// Store the unpressed state for emwin to process.
GUI_TOUCH_StoreStateEx(&touchState);
}

Please let me know if any issues.

Thanks

Regards,

Anuj

0 Kudos

2,136 Views
anujtanksali
Contributor II

Hello,

I was able to debug and found out that i don't get release events always. if i get the release event it works as expected.

I mostly get the CLICKED EVENT and MOVE OUT EVENT.

Please let me know if my above code to check touch is correct?

Regards,

Anuj

0 Kudos

2,066 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi anujtanksali,

   Do you mean, when you select the project as the release version instead of the debug version, then it works?

   Release version can get the correct touch, but debug mode can't get the correct touch event?

   If yes, you need to check the optimization in the project options, any difference between your debug and release?

 

Wish it helps you!

If you still have questions about it, please kindly let me know!

Best Regards,

Kerry

-------------------------------------------------------------------------------

Note:

- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored

Please open a new thread and refer to the closed one, if you have a related question at a later point in time.

-----------------------------------------------------------------------------

0 Kudos

2,051 Views
anujtanksali
Contributor II

Hi @kerryzhou ,

I meant i don't get the release events always when i press the LCD. As am using Emwin library i pass the raw ADC touchx and touchy to emwin by using  GUI_TOUCH_StoreStateEx(&touchState); as show above in my code. It is expected that i get the the WM_NOTIFICATION_CLICKED event from Emwin library when i press the LCD and WM_NOTIFICATION_RELEASED event from Emwin library when i release the LCD. 

The latest development in this regard is below,

I re-calibrated the LCD multiple times using standard 9 point calibration and increased the size of the widgets due to which there is improvement and i get the WM_NOTIFICATION_CLICKED and WM_NOTIFICATION_RELEASED events.

But it does not always work 100% of the time. I think it has to do with the default calibration points which are passed to Emwin to calibrate the Touch.

below are the points used

// Pixel coordinates

int touchRefValX[9] = {40,400,760,40,400,760,40,400,760};
int touchRefValY[9] = {24,24,24,240,240,240,456,456,456};

// ADC values

int touchSampleValX[9] = {2561,1958,1531,2561,1961,1531,2564,1959,1526};
int touchSampleValY[9] = {2308,2304,2305,1970,1966,1955,1772,1764,1764};

The above points are applied using emwin api's below

// Set the calibration coefficients.
GUI_TOUCH_CalcCoefficients(9, &touchRefValX[0], &touchRefValY[0], &touchSampleValX[0], &touchSampleValY[0], 800, 480);

// Enable use of above calibration coefficients.
GUI_TOUCH_EnableCalibration(TRUE);

Attached is the excel containing the log of ADC x and y values. using the values in excel average x and y are taken for each point and used for GUI_TOUCH_CalcCoefficients.

Please let me know if any inputs.

Thanks

Regards

Anuj

 

 

 

 

 

0 Kudos

2,035 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi anujtanksali,

   About the emwin based issue, I think you need to check with the Segger side:

https://www.segger.com/support/technical-support/

   You can check with the Segger emwin engineer, what the detail data the emwin touch API needed, then you can check the RT chip, whether the RT ADC can get the correct ADC value.

   We can divide your question into two parts, one is the RT ADC, whether the RT can get the correct touch ADC value. Another is the emwin question, this type question you need to check with the segger side, as the emwin is the Segger product.

 

Wish it helps you!

If you still have questions about it, please kindly let me know!

Best Regards,

Kerry

-------------------------------------------------------------------------------

Note:

- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored

Please open a new thread and refer to the closed one, if you have a related question at a later point in time.

-----------------------------------------------------------------------------

0 Kudos

2,025 Views
anujtanksali
Contributor II

Hello @kerryzhou ,

Thanks for the reply.

The ADC seems to be giving the reading correct as i checked this with setting a touchscreen related pin to high and reading the ADC value. I get around 4070 counts which is near to 4096 and as expected as ADC is 12bit.

Regarding Emwin we are using the library version and so not have a license and i think the support link shared above only supports those with a valid emwin license.

I have posted the same issue on emwin forum but did not get any concrete reply.

Its related to calibration only i think. 

Thanks

Regards,

Anuj

 

 

 

 

0 Kudos

2,019 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi anujtanksali,

    Thanks for the information about the RT ADC result. From your test result, the RT ADC should be correct.

   About the emwin, it doesn't matter, you can try to create the case. As I know the segger forum should also have the support engineer. Please wait the reply patiently from the segger side.

 

Wish it helps you!

If you still have questions about it, please kindly let me know!

Best Regards,

Kerry

-------------------------------------------------------------------------------

Note:

- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored

Please open a new thread and refer to the closed one, if you have a related question at a later point in time.

-----------------------------------------------------------------------------

0 Kudos