Touch Panel TFT Library

Beta Testing discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Touch Panel TFT Library

#1 Post by Toley » 05 Feb 2011 16:17

I'm using a PIC32MX4 Multimedia Board and I want to try the Touch Panel TFT Library. I know the display on that board don't have the same controller than the others so the TFT Library will not work but the Touch Panel should work.

Here is my simple test code :

Code: Select all

sbit LED at LATA0_bit;
sbit LED_dir at TRISA0_bit;

// Touch Panel module connections
sbit DriveX_Left at LATB13_bit;
sbit DriveX_Right at LATB11_bit;
sbit DriveY_Up at LATB12_bit;
sbit DriveY_Down at LATB10_bit;
sbit DriveX_Left_Direction at TRISB13_bit;
sbit DriveX_Right_Direction at TRISB11_bit;
sbit DriveY_Up_Direction at TRISB12_bit;
sbit DriveY_Down_Direction at TRISB10_bit;
// End Touch Panel module connections

void main()
{
 char txt[12];
 char valid;
 unsigned int x_coord,y_coord;
 
 JTAGEN_bit = 0;
 AD1PCFG = 0xCFFF;              // AN12-13 analog

 LED_dir = 0;
 LATA = 0xFFFF;

 UART2_Init(115200);
 UART2_Write_Text("Test Touch Screen PIC32\r\n");

 ADC1_Init();                   // Initalize ADC module
 TP_TFT_Init(320, 240, 13, 12); // Initialize touch panel
 TP_TFT_Set_ADC_Threshold(900);    // Set touch panel ADC threshold

 while(1)
 {
  if (TP_TFT_Press_Detect())
  {
   if (TP_TFT_Get_Coordinates(&x_coord, &y_coord) == 0)
    {
     WordToStr(x_coord, txt);
     UART2_Write_Text("X Coordinate = ");
     UART2_Write_Text(txt);
     UART2_Write_Text("\r\n");
     WordToStr(y_coord, txt);
     UART2_Write_Text("Y Coordinate = ");
     UART2_Write_Text(txt);
     UART2_Write_Text("\r\n");
    }
   LED = ~LED;
   delay_ms(300);
  }
 }
}
TP_TFT_Press_Detect() works fine cause my LED toggle each time I touch the display but x_coord and y_coord don't return anything.

Am I using the library correctly ? Is there something I missed ? I have followed the exemple.

Thank you for any help.
Serge T.
Learning is an endeless process but it must start somewhere!

User avatar
marko.ziv
mikroElektronika team
Posts: 530
Joined: 06 Dec 2007 10:11
Contact:

Re: Touch Panel TFT Library

#2 Post by marko.ziv » 05 Feb 2011 21:14

Toley wrote:I know the display on that board don't have the same controller than the others so the TFT Library will not work but the Touch Panel should work.
Actually, PIC32MX4 Multimedia Board uses the same TFT and controller as LV32MX v6, so both TFT and Touch Panel should work with PIC32 compilers libraries.
Toley wrote: Here is my simple test code :

Code: Select all

...
TP_TFT_Press_Detect() works fine cause my LED toggle each time I touch the display but x_coord and y_coord don't return anything.

Am I using the library correctly ? Is there something I missed ? I have followed the exemple.
Thank you for any help.
Glancing at your code, hardware connections look OK. What you are "missing" is to set calibration constants
for Touch Panel. Use this small procedure to calibrate:

Code: Select all

void Calibrate() {
  TFT_Set_Pen(CL_WHITE, 3);
  TFT_Line(315, 1, 319, 1);
  TFT_Line(310, 10, 319, 1);
  TFT_Line(319, 5, 319, 1);

  TP_TFT_Calibrate_Min();                      // Calibration of bottom left corner
  Delay_ms(500);

  TFT_Set_Pen(CL_BLACK, 3);
  TFT_Line(315, 1, 319, 1);
  TFT_Line(310, 10, 319, 1);
  TFT_Line(319, 5, 319, 1);

  TFT_Set_Pen(CL_WHITE, 3);
  TFT_Line(0, 239, 0, 235);
  TFT_Line(0, 239, 5, 239);
  TFT_Line(0, 239, 10, 229);

  TP_TFT_Calibrate_Max();                      // Calibration of upper right corner
  Delay_ms(500);

  TFT_Set_Pen(CL_BLACK, 3);
  TFT_Line(0, 239, 0, 235);
  TFT_Line(0, 239, 5, 239);
  TFT_Line(0, 239, 10, 229);

  Delay_ms(500);
}
Arrows will point where to press on the TFT to calibrate it correctly. When you remember your X(max & min) and Y(max & min) values
Use

Code: Select all

TP_TFT_Set_Calibration_Consts(x_min, x_max, y_min, y_max);
to avoid calibration procedure each time you reset your device.
Hope this helps,

Best Regards

Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Re: Touch Panel TFT Library

#3 Post by Toley » 05 Feb 2011 23:58

Thank you very much marko for the quick (saturday) answer.
Actually, PIC32MX4 Multimedia Board uses the same TFT and controller as LV32MX v6, so both TFT and Touch Panel should work with PIC32 compilers libraries.
This is very nice the example for the LV32MX board work with the PIC32MX LCD :D .

But the touch screen don't seems to work :( . I have added your Calibrate routine to the example and it don't works.

I also noticed at line 97 of the example TP_TFT_Init(320, 240, 0, 1); // Initialize touch panel
I believe it should be TP_TFT_Init(320, 240, 13, 12); // Initialize touch panel
But it don't work either.

I will continue to investigate and keep you informed.
Serge T.
Learning is an endeless process but it must start somewhere!

User avatar
marko.ziv
mikroElektronika team
Posts: 530
Joined: 06 Dec 2007 10:11
Contact:

Re: Touch Panel TFT Library

#4 Post by marko.ziv » 07 Feb 2011 09:21

Hello,
Toley wrote:I also noticed at line 97 of the example TP_TFT_Init(320, 240, 0, 1); // Initialize touch panel
I believe it should be TP_TFT_Init(320, 240, 13, 12); // Initialize touch panel
You are correct MX4 uses AN13 & AN12 lines so it should be:

Code: Select all

  ADC1_Init();
  TFT_Set_Active(SetIndex,WriteCommand,WriteData);
  TFT_Init(320, 240);

  TP_TFT_Init(320, 240, 13, 12);                                  // Initialize touch panel
  TP_TFT_Set_ADC_Threshold(1000);                              // Set touch panel ADC threshold
The example you were looking in compiler is example of TFT functionality, and TP_TFT_Init was left in the example by mistake.
Release version of PIC32 compiler will have both examples covered TFT & TFT+TP, as well as various examples for mikroMMB for PIC32 Board,
PIC32MX4 MultiMedia Board and MultiMedia Board for PIC32MX7.
In attachment to this post i am sending you hex file to load to your PIC32MX4 MultiMedia Board.
It's a simple demonstration of touch panel functionality.
If you persist to have problems contact our Support Desk
http://www.mikroe.com/esupport/

Best Regards
Attachments
MX4_text.rar
(24.81 KiB) Downloaded 396 times

Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Re: Touch Panel TFT Library

#5 Post by Toley » 08 Feb 2011 01:53

Thank you marko this code works very well.

I have a simple suggestion for you and your development team. I have already worked on a TFT Library of my own and I quickly noticed that the WriteData is by far the most used when loading pictures. In this part of code taken from the TFT example :

Code: Select all

void SetIndex(unsigned short index) {
  TFT_RS = 0;
  PMDIN = index;
  PMPWaitBusy();
}

void WriteCommand( unsigned short cmd ) {
  TFT_RS = 1;
  PMDIN = cmd;
  PMPWaitBusy();
}

void WriteData(unsigned int _data) {
  TFT_RS = 1;
  PMDIN = _data;
  PMPWaitBusy();
}
Simply by assuring TFT_RS is always egal to 1 when exiting a function, can save you to set it in the WriteData function like this :

Code: Select all

void SetIndex(unsigned short index) {
  TFT_RS = 0;
  PMDIN = index;
  PMPWaitBusy();
  TFT_RS = 1;       // TFT_RS is egal to 1 on exit
}

void WriteCommand( unsigned short cmd ) {
  TFT_RS = 1;
  PMDIN = cmd;
  PMPWaitBusy();    // TFT_RS is egal to 1 on exit
}

void WriteData(unsigned int _data) {
  PMDIN = _data;   // No need to set TFT_RS in the most used function
  PMPWaitBusy();
}
You could be surprised how much time can be saved only by removing a simple line in the WriteData function. For my experience, I speed up from 10% to 20% in loading a complete image. Don't forget for a 320x240 image, this function is called 76800 times!!!

I also tend to believe putting directly while(PMMODEbits.BUSY); in the WriteData function instead of calling it from the PMPWaitBusy() can save some extra time but I did not try this one.

I hope those simple tough can help you enhance the actual library. It's not a big problem with the fast PIC32 but with smaller MCU, every saved cycle is important when working with TFT displays.
Serge T.
Learning is an endeless process but it must start somewhere!

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Touch Panel TFT Library

#6 Post by zristic » 08 Feb 2011 09:53

Thanks for this useful tip!
We are planning to revise the example templates + drivers so we will take this very seriously into account.

Post Reply

Return to “mikroC PRO for PIC32 Beta Testing”