Page 1 of 1

Touchscreen Library modification

Posted: Thu Jan 17, 2008 10:40 pm
by Tom Estes
I tested the touchscreen library on hardware that needed to have the ADC ports connected differently from the library default. One can change the ports by defines but the library won't work with these defines different from the default. The reason is the ADC references are fixed and therefore refer to the wrong TS plate connection if the ports are changed. I "fixed" (for my purposes) the module by changing the ADC.Read lines in the subs below (I would have highlighted the changes with color but couldn't figure out how to do that within the code block!).

Code: Select all

{
********************************************************************************
* Name    : PenPressure (PUBLIC)                                               *
* Purpose : Returns a value between 0-255 indicating pen pressure.             *
*         : Testing this value will allow a sensible value for                 *
*         : Pen_Down_Threshold to be calculated.                               *
********************************************************************************
}
Public Function PenPressure() As Byte
    Input(TS_X1)                                 // X1 is input 
    Input(TS_X2)                                 // X2 is input 
    Output(TS_Y1)                                // Y1 is output 
    Output(TS_Y2)                                // Y2 is output 
    TS_Y1 = 1                                    // Both Y plates high
    TS_Y2 = 1                               
    DelayUS(Pen_Down_DelayUS)
    PenPressure = ADC.Read(BitOf(TS_X2,false)) >> 2             // Read ADC  
    Input(TS_Y1)                                 // Y1 is input - power save 
    Input(TS_Y2)                                 // Y2 is input - power save
End Function

 {
********************************************************************************
* Name    : ReadX (PRIVATE)                                                    *
* Purpose :                                                                    *
********************************************************************************
}
Function ReadX() As Word
    DelayMS(Read_XY_DelayMS)                     // Stabilise
    Result = Max(ADC.Read(BitOf(TS_X1,false)), ADC.Read(BitOf(TS_X2,false)))   // Read X co-ordinate
End Function     
{
********************************************************************************
* Name    : ReadY (PRIVATE)                                                    *
* Purpose :                                                                    *
********************************************************************************
}
Function ReadY() As Word
    DelayMS(Read_XY_DelayMS)                     // Stabilise
    Result = Max(ADC.Read(BitOf(TS_Y1,false)), ADC.Read(BitOf(TS_Y2,false)))   // Read Y co-ordinate
End Function     
{
{
Using BitOf will work for AN0 through AN3 on most PICs but it gets much more complicated after that. ANx references don't always match port bit locations. I frankly couldn't come up with a good solution for those....
I welcome any solutions, although the above fixed my short term port issues. It may be more trouble than it's worth. If one wants to use the library-use it with the default ports and remove the capability to change the ports altogether.

Otherwise the Touchscreen library worked as advertised.....

Thanks Steven

Tom

Posted: Thu Jan 17, 2008 11:20 pm
by Steven
Thanks for your comments Tom. The defines are not ment for swapping which ADC ports are used - these are hard coded as you rightly identify and as noted in the comment section at the top of the module. The defines are for assigning the right port pins for these ADC channels, in case any PICs do not follow the default of AN0 on PortA.0 etc...
I agree, it would be good to get a general way of assigning ADC channels and if anyone has any bright ideas, it would be good to hear. Good to hear that it works OK otherwise.

Steve

Posted: Fri Jan 18, 2008 3:11 pm
by Tom Estes
I misunderstood the reason for the port defines. Your instructions are perfectly clear. All too often when I see defines I assume they will work for any possibility-will have to be more careful.

That said, I too would like to see a way of assigning ADC channels via defines (or otherwise). I spent several hours trying to come up with a universal solution but ran out of ideas.

Thanks for the module, I've several upcoming projects where using Touchscreen will come in handy. By the way I'm using it on a KS0108 based 128x64 GLCD.

Tom

Posted: Fri Jan 18, 2008 5:25 pm
by Steven
OK, great - it would be good to see what you do with the touchscreens when you start your projects.

Kind regards,

Steve