• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

touchscreen simulation

Status
Not open for further replies.

xsystemxr

New Member
HI,

im using Mikroc compiler 8.2 with PIC16F877A and Proteus7.5 to simulate touch screen using a model i download form the internet.

OSRAM Touch Screen Pictiva OLED display Proteus VSM Model

The problem is that the touchscreen model is with built-in AD7843 (touchscreen controller), i triad to write code to communicate with the AD7843 using SPI, but unfortunately there is no any response except the PENIRQ is activated and then could not be use any more.

according to the datasheet of AD7843 and the document with the touch screen proteus model , you need to send 0X98 to get the X component and send 0XD8 for the Y component.

the function of the code i wrote is to get the coordinate once there is an interrupt coming from the PENIRQ (active low) and never come back again, after testing and trying, i think that maybe my problem is SPI i think i dont know how to use it.

Code:
----------------------------------------------------------------------------------------------
Code:
unsigned short x=0,y=0,ax=0,ay=0,bx=0,by=0,flag=0; 
//float gx=0.0,gy=0.0,mx=0.0,my=0.0; 
void interrupt() 
{ 
     //Spi_Init_Advanced(MASTER_OSC_DIV4, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, HIGH_2_LOW); 
     Spi_Init(); 
     PORTB.F1=0;       //for chip select 
     Spi_Write(0x98);  //for x readign 
     spi_read(0); 
     Spi_Write(0xD8);  //for y reading 
     y=spi_read(0); 

     INTCON.INTF=0;    // resetting the interrupt 
     OPTION_REG=0; 
     PORTB.F1=1;       //disable the chip select after getting x and y 
     flag=1;           //flag to indicate that a touch occur 


} 

//unsigned short xx(unsigned short x) 
//{return ((x*gx)+mx);} 

//unsigned short yy(unsigned short y) 
//{return ((y*gy)+my);} 

void main() 
{ 
     TRISC &= 0x14; 
     TRISB &= 0x01; 

     PORTB.F1=1; 
      
     Glcd_Init(&PORTB,2,3,4,5,7,6,&PORTD); 

     Glcd_Circle(15, 7, 2, 2);      // a small circule to touched 
     flag=0;                        //falg initiating 
     INTCON.INTE=1;                 //enable external interrupt (RB0) 
     INTCON.GIE=1; 
     OPTION_REG=0; 


     while(1)                   //setting ax and ay if the falge is set 
     { 
       if(flag) 
       { 
        ax=x; 
        ay=y; 
        break; 
       } 

     } 

     Glcd_Circle(111, 55, 2, 2);       // another small circule to touched 
     flag=0;                           //flag initiating 
      
     while(1)                         //setting bx and by if the falge is set 
     { 
       if(flag) 
       { 
        bx=x; 
        by=y; 
        break; 
        

       } 
     } 

     glcd_rectangle(31,15,95,47,2);  // to indicate that both circuls received 
                                     //  a touch
-------------------------------------------------------------------------------------------------


the problem is the rectangle never be drawn.

please help me, i need to get this done. :confused: :(

oh, by theway the my proteus schematic is in the link below.


RapidShare: Easy Filehosting

Thank you in advance.

Ramzi,
 

DirtyLude

Well-Known Member
I think you need to get more familiar with the datasheet.

Using PENIRQ is a pain. It's a single shot interrupt, it doesn't just enable everytime you touch the screen, and it also goes up and down on it's own during data transmission, so you have to disable your interrupt routine while sending/receiving, or you'll get a load of crazy interrupts. In order to enable PENIRQ you need to send it a standard three byte control packet, (1 byte command, 2 byte read) with the PENIRQ control bits set to 000, like you have done in the interrupt routine. I'm assuming you are doing this somewhere in initialization as well, or PENIRQ doesn't work.

I did a write up on the TSC2046, which is essentially the same chip, just a hardware update, but the same control scheme.

http://www.electro-tech-online.com/threads/tsc2046-controller-and-nds-touchscreen.92141/

Are you able to see graphed logic levels in Proteus, because using a logic analyzer really made quick work decoding how this chip works?
 

xsystemxr

New Member
touchscreen

I think you need to get more familiar with the datasheet.

Using PENIRQ is a pain. It's a single shot interrupt, it doesn't just enable everytime you touch the screen, and it also goes up and down on it's own during data transmission, so you have to disable your interrupt routine while sending/receiving, or you'll get a load of crazy interrupts. In order to enable PENIRQ you need to send it a standard three byte control packet, (1 byte command, 2 byte read) with the PENIRQ control bits set to 000, like you have done in the interrupt routine. I'm assuming you are doing this somewhere in initialization as well, or PENIRQ doesn't work.

I did a write up on the TSC2046, which is essentially the same chip, just a hardware update, but the same control scheme.

http://www.electro-tech-online.com/threads/tsc2046-controller-and-nds-touchscreen.92141/

Are you able to see graphed logic levels in Proteus, because using a logic analyzer really made quick work decoding how this chip works?

Thanks for your replay.

I never thought about using logic analyzer, that a nice idea.
nothing is shown in the logic analyzer.

in your experience what do i have to change in the code to make things right.

by theway you have done a great job with TSC246.

thank you again...
 
Last edited:

DirtyLude

Well-Known Member
I don't program PICs, so I don't know your code well enough, but:

1. Send a dummy command to initialize the chip and set the PENIRQ to active in the initialization area of your code, or PENIRQ won't do anything.
2. You'll need to find some way to disable the ISR while sending/receiving data, or your interrupt routine will just go nuts.


EDIT:

Oh, right. It's also a three byte control packet. You are doing a SPI write and a single read for both X and Y. You need to write the command and 2 reads to get the data. Then you need to move the data around, since it doesn't land directly on a byte boundary. I tried to decode your command codes, use differential reading, rather than single ended.
 
Last edited:
Status
Not open for further replies.

EE World Online Articles

Loading
Top