Unable to make the Touch Panel TFT Library work

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

Unable to make the Touch Panel TFT Library work

#1 Post by Toley » 15 Apr 2011 00:38

Hello everyone, I want to make the Touch Panel TFT Library work alone (I need it in a project of my own).
For my test I use a PIC32MX4 MMB. The touch panel work perfectly with the examples or with a Visual TFT project.
But I'm unable to make it work alone. There is surely something I don't understand or don't do correctly to make the library work. Here is the simplest code I can see to test the Touch Panel, the TFT itself is not initialized I just want to test the Touch Screen.

Code: Select all

// 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

// Global variables
unsigned int Xcoord, Ycoord;

void main() {
  char txt[12];

  AD1PCFG = 0xFFFF;
  PCFG12_bit = 0;
  PCFG13_bit = 0;

  UART2_Init(115200);
  ADC1_Init();

  TP_TFT_Init(320, 240, 13, 12);                      // Initialize touch panel
  TP_TFT_Set_ADC_Threshold(1000);                     // Set touch panel ADC threshold

  TP_TFT_Set_Calibration_Consts(76, 907, 77, 915);    // Set calibration constants
  
  while(1) {

  if (TP_TFT_Press_Detect()) {
    // After a PRESS is detected read X-Y and convert it to Display dimensions space
    UART2_Write_Text("Press Detected\r\n");           // This work
    
    if (TP_TFT_Get_Coordinates(&Xcoord, &Ycoord) == 0) { // This don't
         WordToStr(Xcoord,txt);
         UART2_Write_Text(txt);
         UART2_Write_Text("\r\n");
         WordToStr(Ycoord,txt);
         UART2_Write_Text(txt);
         UART2_Write_Text("\r\n");
     }
    }
   delay_ms(500);
  }
}
The TP_TFT_Press_Detect() function is working but no values are returned from the TP_TFT_Get_Coordinates(&Xcoord, &Ycoord) function. I have carefully check the examples and the generated code from Visual TFT and I believe this is the only code needed for the library to work.

Please help me understand how the Touch Panel TFT Library is working. Thank you.
Serge T.
Learning is an endeless process but it must start somewhere!

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: Unable to make the Touch Panel TFT Library work

#2 Post by tihomir.losic » 21 Apr 2011 12:46

Hello Serge,

please, try this code:

Code: Select all

// TFT display connections
char TFT_DataPort at LATE;
sbit TFT_WR at LATD13_bit;
sbit TFT_RD at LATD12_bit;
sbit TFT_CS at LATC3_bit;
sbit TFT_RS at LATB15_bit;
sbit TFT_RST at LATC1_bit;

char TFT_DataPort_Direction at TRISE;

sbit TFT_WR_Direction at TRISD13_bit;
sbit TFT_RD_Direction at TRISD12_bit;
sbit TFT_CS_Direction at TRISC3_bit;
sbit TFT_RS_Direction at TRISB15_bit;
sbit TFT_RST_Direction at TRISC1_bit;
// End of TFT display connections

// 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

// Global variables
unsigned int Xcoord, Ycoord;

void main() {
  char txt[2];

  AD1PCFG = 0xFFFF;
  PCFG12_bit = 0;
  PCFG13_bit = 0;

  TFT_Init(320,240);
  UART1_Init(115200);
  ADC1_Init();

  TP_TFT_Init(320, 240, 13, 12);                      // Initialize touch panel
  TP_TFT_Set_ADC_Threshold(1000);                     // Set touch panel ADC threshold

  TP_TFT_Set_Calibration_Consts(76, 907, 77, 915);    // Set calibration constants

  UART1_Write_Text("Start");
  while(1) {

  if (TP_TFT_Press_Detect()) {
    // After a PRESS is detected read X-Y and convert it to Display dimensions space
    UART1_Write_Text("Press Detected\r\n");           // This work

    if (TP_TFT_Get_Coordinates(&Xcoord, &Ycoord) == 0) { // This don't
         WordToStr(Xcoord,txt);
         UART1_Write_Text(txt);
         UART1_Write_Text("\r\n");
         WordToStr(Ycoord,txt);
         UART1_Write_Text(txt);
         UART1_Write_Text("\r\n");
     }
    }
   delay_ms(300);
  }
}
Also, you need to keep your finger for about 0.5 second in order to receive x and y coordinate.

For any additional advice, feel free to contact me.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

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

Re: Unable to make the Touch Panel TFT Library work

#3 Post by Toley » 22 Apr 2011 00:06

Thank you Losic Tihomir it work fine even my first code work.
Also, you need to keep your finger for about 0.5 second in order to receive x and y coordinate.
This is the most important thing to do! Is there a way to make it respond faster?
Serge T.
Learning is an endeless process but it must start somewhere!

seulater
Posts: 74
Joined: 19 Jan 2011 15:14

Re: Unable to make the Touch Panel TFT Library work

#4 Post by seulater » 24 Apr 2011 05:09

WordToStr(Xcoord,txt);
UART1_Write_Text(txt);
UART1_Write_Text("\r\n");
WordToStr(Ycoord,txt);
UART1_Write_Text(txt);
UART1_Write_Text("\r\n");

all could be done with one statement, if ME would use printf.

printf("%u:%u\r\n",Xcoord,Ycoord);

or

printf("X=%u : Y=%u\r\n");

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

Re: Unable to make the Touch Panel TFT Library work

#5 Post by Toley » 25 Apr 2011 04:23

Hi seulater
In another post you wrote
I wrote my own printf lib, will be posting that if anyone wants it.
Is your library can do the one line command?

I'm interested to test your library.
Serge T.
Learning is an endeless process but it must start somewhere!

seulater
Posts: 74
Joined: 19 Jan 2011 15:14

Re: Unable to make the Touch Panel TFT Library work

#6 Post by seulater » 25 Apr 2011 10:02

yes, but i am also trying to convince ME that it is very important for them to have this built in too.
Over the weekend i gave op on ME. I was trying to get Free RTOS running in ME as whats the point of all having all this speed on the PIC32 when you don't have an RTOS environment. It really pointless IMHO.

Way back when i used to do everything in straight line code (I.E. without an RTOS), and it all seemed normal at the time. Writing line of code by line of code. waiting on while loops and if then else's. being tied up for one even to happen while needing to be doing something else at the same time and trying to manage it with irq timers so it could all to look seamless. Then i found out about RTOS's and i have NEVER looked back. Now i can have multiple things all going on at the same time and it has allowed me to write things quicker and made all my devices run smoother. I have tried to convert the Free RTOS over to ME , but there is just way to many issues i found with porting it over that i just did not feel like dealing with. So i will wait for it to mature and hopefully with others saying the same things as me will force their hand to make these improvements. Like i said in the past and will continue to say. I think ME can be one of the BEST compilers out there. But they need to follow some of the ways others popular compilers do things so they can be more compatible when it comes to importing C code.

Post Reply

Return to “mikroC PRO for PIC32 General”