4 Wire resistive touch screen, Need help


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    Quote Originally Posted by Megahertz View Post
    1) Can you please explain how is "Start reading average pressure value" routine is working. Upto now I have only encountered putting 5v on y+ or x+ and corresponding y- or x- to be 0v. What is 5v @ y+ and 0v and x- doing?
    This application note will help you understand better what is going on.
    http://www.eetasia.com/ARTICLES/2004...URCES=DOWNLOAD

    Before you start reading the touchscreen coordinates, you need to know if the screen has been touched. By having 5V at Y+ and 0V at X- you monitor if the screen was touched. The setup is as follows

    Name:  Touchscreen01.JPG
Views: 7210
Size:  41.4 KB

    And the code is

    Code:
    START:
    
        '################ START READING AVERAGE PRESSURE VALUE ################    
    
        TRISA = %00001001           ' Set Y+ (portA.2, AN2) and X- (portA.1, AN1) as outputs 
                                    ' and Y- (portA.3, AN3) and X+ (portA.0, AN0) as inputs 
        
        low PORTA.1                 ' Set X- = 0V    
        high PORTA.2                ' Set Y+ = 5V     
        ADCON0 = %00000001          ' Bits(5-2): 0000=AN0. Start sampling at X+   
        pauseus 10        
        ADCON0.1 = 1                ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                    ' then begins conversion         
        
        GOSUB CONVERSION_ROUTINE    ' Obtain value for A/D conversion resolution
        PRESSURE_XP = RESOLUTION    ' Obtain PRESSURE_XP from X+ sampling, X- = 0V, and Y+ = 5V  
        
        ADCON0 = %00001101          ' Bits(5-2): 0011=AN3. Start sampling at Y-   
        pauseus 10        
        ADCON0.1 = 1                ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                    ' then begins conversion         
    
        GOSUB CONVERSION_ROUTINE    ' Obtain value for A/D conversion resolution
        PRESSURE_YM = RESOLUTION    ' Obtain PRESSURE_YM from Y- sampling, X- = 0V, and Y+ = 5V 
    
        IF (PRESSURE_XP > 24) AND (PRESSURE_YM < 1000) THEN         ' THE TOUCHSCREEN HAVE BEEN TOUCHED         
            GOSUB READ_COORDINATES
            gosub CONVERT_TO_PIXELS 
        ENDIF      
    
        LCDOUT $FE, 1                                                       ' Clear LCD                               
        LCDOUT $FE,2,"X=",DEC5 X_VALUE,", Y=",DEC5 Y_VALUE                  ' DISPLAYS A/D CONVERSION VALUES            
        LCDOUT $FE,$C0,"P1=",DEC4 PRESSURE_XP,", P2=",DEC4 PRESSURE_YM   
        
        GOTO START
    If the screen is not touched then the reading for PRESSURE_XP is going to be very close to zero and the reading for PRESSURE_YM is going to be very close to 1024, remember it is a 10-bit ADC. The screen has been touched when the following condition has been met

    Code:
        IF (PRESSURE_XP > 24) AND (PRESSURE_YM < 1000) THEN         ' THE TOUCHSCREEN HAVE BEEN TOUCHED
    To read the X,Y coordinates you need the following setup.

    Name:  Touchscreen02.JPG
Views: 4568
Size:  30.2 KB

    And the code is

    Code:
    '****************************************************************
    '*         READ X AND Y VALUES SUBROUTINE                       *
    '**************************************************************** 
    READ_COORDINATES:
        ' PORTA.0 (AN0) -> X+
        ' PORTA.1 (AN1) -> X-
        ' PORTA.2 (AN2) -> Y+
        ' PORTA.3 (AN3) -> Y-
    
        '################ READ AVERAGE X-VALUE ################
    
        TRISA = %00000011                   ' Set X+ (portA.0, AN0) and X- (portA.1, AN1) as inputs 
                                            ' and Y+ (portA.2, AN2) and Y- (portA.3, AN3) as outputs 
    
        low PORTA.3                         ' Set Y- = 0V    
        high PORTA.2                        ' Set Y+ = 5V      
        ADCON0 = %00000001                  ' Bits(5-2): 0000=AN0. Start sampling at X+    
        pauseus 10        
        ADCON0.1 = 1                        ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                            ' then begins conversion         
        GOSUB CONVERSION_ROUTINE            ' Obtain value for A/D conversion resolution  
        X_VALUE = RESOLUTION                ' Obtain X_VALUE from X+ sampling, Y- = 0V, and Y+ = 5V  
      
        ADCON0 = %00000101                  ' Bits(5-2): 0001=AN1. Start sampling at X-    
        pauseus 10        
        ADCON0.1 = 1                        ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                            ' then begins conversion          
        GOSUB CONVERSION_ROUTINE            ' Obtain value for A/D conversion resolution   
        X_VALUE = (X_VALUE + RESOLUTION)      ' Obtain X_VALUE from X- sampling, Y- = 0V, and Y+ = 5V  
        
        '################ READ AVERAGE Y-VALUE ################    
    
        TRISA = %00001100                   ' Set X+ (portA.0, AN0) and X- (portA.1, AN1) as outputs 
                                            ' and Y+ (portA.2, AN2) and Y- (portA.3, AN3) as inputs 
    
        low PORTA.1                         ' Set X- = 0V    
        high PORTA.0                        ' Set X+ = 5V      
        ADCON0 = %00001001                  ' Bits(5-2): 0010=AN2. Start sampling at Y+    
        pauseus 10        
        ADCON0.1 = 1                        ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                            ' then begins conversion         
        GOSUB CONVERSION_ROUTINE            ' Obtain value for A/D conversion resolution
        Y_VALUE = RESOLUTION                ' Obtain Y_VALUE from Y+ sampling, X- = 0V, and X+ = 5V    
      
        ADCON0 = %00001101                  ' Bits(5-2): 0011=AN3. Start sampling at Y-    
        pauseus 10        
        ADCON0.1 = 1                        ' Stops or continues sampling depending on ADCON2 bits(5-3), 
                                            ' then begins conversion         
        GOSUB CONVERSION_ROUTINE            ' Obtain value for A/D conversion resolution
        Y_VALUE = (Y_VALUE + RESOLUTION)      ' Obtain Y_VALUE from Y- sampling, X- = 0V, and X+ = 5V 
       
    
    RETURN
    
    '****************************************************************
    '*         CONVERSION SUBROUTINE                                *
    '**************************************************************** 
    CONVERSION_ROUTINE:
        REPEAT          ' Wait until conversion is finished. When finished ADCON0.1 will be =0        
            PAUSEUS 10
            CONV_STATUS = ADCON0.1    
        UNTIL CONV_STATUS = 0
        
        RESOLUTION.BYTE0 = ADRESL : RESOLUTION.BYTE1 = ADRESH       ' READ A/D CONVERSION VALUE
    
    RETURN
    For the final routine "CONVERT_TO_PIXELS" the constants Ax, Bx, Ay, and By should be found experimentally. They will vary depending on the resolution of the LCD screen. One thing to remember is that the relation of the 4-wire touchscreen readings and the corresponding LCD pixels behaves almost linearly.

    Code:
    '****************************************************************
    '*         CONVERT_TO_PIXELS ROUTINE                            *
    '**************************************************************** 
    CONVERT_TO_PIXELS:
    
         'Ax, Bx, Ay, and By should be found experimentally
        X_VALUE = Ax * X_VALUE + Bx    
        Y_VALUE = Ay * Y_VALUE + By
    RETURN
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    nevermind, read code few more times...

    Robert
    Last edited by Demon; - 7th February 2012 at 01:27.

  3. #3
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    Makes much more sense now. Thanks a lot for all the info.

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    I can't see why you'd use an interrupt for a touch screen,
    and if there is a valid reason I'd like to know what it is.

    Why not follow the way 2D games work?

    1) Draw current frame to screen,

    2) Check for user input,

    3) act on user input, and apply any movement/calculations for next frame,

    4) goto step one.

    It would seem if you're using an interrupt, and your program is in the middle of step 3
    while receiving new input you are complicating things.
    Last edited by Art; - 16th February 2012 at 16:02.

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 4 Wire resistive touch screen, Need help

    Quote Originally Posted by Art View Post
    I can't see why you'd use an interrupt for a touch screen,
    and if there is a valid reason I'd like to know what it is.

    Why not follow the way 2D games work?

    1) Draw current frame to screen,

    2) Check for user input,

    3) act on user input, and apply any movement/calculations for next frame,

    4) goto step one.

    It would seem if you're using an interrupt, and your program is in the middle of step 3
    while receiving new input you are complicating things.
    No, there is no interrupt in the program I posted.

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts