EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: ProAce on April 01, 2016, 07:57:15 am

Title: Touchscreen interfering with analog input on 4D Systems display
Post by: ProAce on April 01, 2016, 07:57:15 am
When I use an analog input on a uLCD-35DT with touch enabled and I press the screen the analog values rise (if pin not connected to around 1V). If I release it, it works properly(shows zero). Has anyone got an idea or any experience as to why this is? I'm using the latest driver and loader. Here is my test code:
Code: [Select]
#platform "uLCD-35DT"

// Program Skeleton 1.2 generated 31.3.2016 14:36:58

#inherit "4DGL_16bitColours.fnc"

#inherit "VisualConst.inc"

#inherit "visi testConst.inc"

#inherit "ledDigitsDisplay.inc"

var Voltage := 0;
var Vsteps := 0;
var state;

func main()
//  var hstrings ; // Handle to access uSD strings, uncomment if required
//  var hFontx ;   // Handle to access uSD fonts, uncomment if required and change n to font number
//  Uncomment the following if uSD images, fonts or strings used.

    putstr("Mounting...\n");
    if (!(file_Mount()))
        while(!(file_Mount()))
            putstr("Drive not mounted...");
            pause(200);
            gfx_Cls();
            pause(200);
        wend
    endif
//    gfx_TransparentColour(0x0020);    // uncomment if transparency required
//    gfx_Transparency(ON);             // uncomment if transparency required

//  hFontn := file_LoadImageControl("VISITE~1.dan", "VISITE~1.gcn", 1); // Open handle to access uSD fonts, uncomment if required and change n to font number dropping a and c if > 9
//  hstrings := file_Open("VISITE~1.txf", 'r') ; // Open handle to access uSD strings, uncomment if required
    hndl := file_LoadImageControl("VISITE~1.dat", "VISITE~1.gci", 1);



    touch_Set(TOUCH_ENABLE);

    pin_Set(PIN_AN, PA1);

    gfx_Set(SCREEN_MODE,LANDSCAPE) ;

    // Form1 1.1 generated 31.3.2016 14:38:26
    gfx_BGcolour(0x63C8) ;
    gfx_Cls() ;

    // 4Dbutton1 1.0 generated 1.4.2016 8:23:52
    img_ClearAttributes(hndl, i4Dbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
    img_Show(hndl, i4Dbutton1);  // show button, only do this once
    img_SetWord(hndl, i4Dbutton1, IMAGE_INDEX, state); // where state is 0 for up and 1 for down
    img_Show(hndl,i4Dbutton1) ;

    // Userled1 1.0 generated 1.4.2016 8:31:48
    img_Show(hndl,iUserled1) ;  // show initialy, if required
    img_SetWord(hndl, iUserled1, IMAGE_INDEX, 0) ;      // where numx is 0 (Off) or 1 (On)
    img_Show(hndl,iUserled1) ;

    // Strings1 1.1 generated 1.4.2016 9:19:41
    txt_FontID(FONT3) ;
    txt_FGcolour(WHITE) ;
    txt_BGcolour(BLACK) ;
    gfx_MoveTo(0 , 0) ;
    print(Voltage) ;

    sys_SetTimer(TIMER0, 1000);

    repeat
        state := touch_Get(TOUCH_STATUS);
        if(state == TOUCH_PRESSED)
            img_SetWord(hndl, iUserled1, IMAGE_INDEX, 1) ;      // where numx is 0 (Off) or 1 (On)
            img_Show(hndl,iUserled1) ;
        else if(state == TOUCH_RELEASED)
            img_SetWord(hndl, iUserled1, IMAGE_INDEX, 0) ;      // where numx is 0 (Off) or 1 (On)
            img_Show(hndl,iUserled1) ;
        endif
        if(sys_GetTimer(TIMER0)== 0)
            getAnalog();
            sys_SetTimer(TIMER0, 1000);
        endif
    forever
endfunc

func getAnalog()//read AI
    Vsteps := pin_Read(PA1) ;
    getVoltage(Vsteps);
endfunc

func getVoltage(var reading) //Direct Voltage
    var nsteps[2];
    var Vref[2];
    var Nsteps[2];
    var Factor[2];
    var Result[2];

    flt_VAL(Vref, "3.3");           //Convert a string ("3.3") to a float (Vref)
    flt_ITOF(Nsteps, 4095);         //Convert an integer (4095) to a float (Nsteps)
    flt_DIV(Factor, Vref, Nsteps);  //Float divistion, Factor = Vref/Nsteps

    flt_ITOF(nsteps, reading);      //Convert the integer 'reading' to a float 'nsteps'
    flt_MUL(Result, nsteps, Factor);//Float multiplication, Result = nsteps * Factor

    flt_PRINT(Result, "%.4f");
                                           
    Voltage := flt_FTOI(Result);
endfunc

Title: Re: Touchscreen interfering with analog input on 4D Systems display
Post by: danadak on April 01, 2016, 11:16:59 am
Is this a layout issue, or capacitive coupling in a cable ?

What is the A/D input connected to ? Is it floating or terminated in
a known source impedance ?

Regards, Dana.
Title: Re: Touchscreen interfering with analog input on 4D Systems display
Post by: ProAce on April 01, 2016, 11:52:11 am
Input is floating. It is possible they have a layout issue idk.
Title: Re: Touchscreen interfering with analog input on 4D Systems display
Post by: Kilrah on April 01, 2016, 12:06:13 pm
Did you actually connect the voltage you want to measure yet? If yes, what's the output impedance of that?

Title: Re: Touchscreen interfering with analog input on 4D Systems display
Post by: ProAce on April 04, 2016, 06:33:59 am
Interesting. When I connect the voltage it doesn't interfere. It only does when it's floating. Can someone please explain that.  :-//
Title: Re: Touchscreen interfering with analog input on 4D Systems display
Post by: Brumby on April 04, 2016, 07:29:35 am
What's the input impedance of the analog input you're using?

My guess is that it is very high - and when you put your finger on the screen, you're introducing some of that voltage your body is capturing from the mains EMF all around.

Connect the voltage to be measured and you've dropped that impedance on the input pin dramatically - and it's no longer floating.
Title: Re: Touchscreen interfering with analog input on 4D Systems display
Post by: Kilrah on April 04, 2016, 07:39:12 am
Interesting. When I connect the voltage it doesn't interfere. It only does when it's floating. Can someone please explain that.  :-//

Perfectly normal then.

A microcontroller typically only has one actual ADC, the multiple inputs are connected to it through an analog switch.
When you select an input, a current will flow through it to charge or discharge the cap in the ADC's sample-and-hold circuit for its voltage to match the input's one.
Now if you select an unconnected input no current will flow neither in nor out, so the cap will retain its existing voltage. I.e. what you'll measure is simply the voltage of the last selected AND connected input.
Title: Re: Touchscreen interfering with analog input on 4D Systems display
Post by: ProAce on April 04, 2016, 07:49:00 am
Now that you've explained it, it makes sense. Thanks.
Title: Re: Touchscreen interfering with analog input on 4D Systems display
Post by: ProAce on April 04, 2016, 07:57:28 am
What's the input impedance of the analog input you're using?

My guess is that it is very high - and when you put your finger on the screen, you're introducing some of that voltage your body is capturing from the mains EMF all around.

Connect the voltage to be measured and you've dropped that impedance on the input pin dramatically - and it's no longer floating.
Is it possible it's 1Mohm?
Title: Re: Touchscreen interfering with analog input on 4D Systems display
Post by: Brumby on April 04, 2016, 12:20:51 pm
It's possible it could be a whole lot more.

I think I remember the ATmega328 having something like 100M ohm, so if you can find that on an Arduino board....
Title: Re: Touchscreen interfering with analog input on 4D Systems display
Post by: ProAce on April 04, 2016, 12:34:22 pm
It's possible it could be a whole lot more.

I think I remember the ATmega328 having something like 100M ohm, so if you can find that on an Arduino board....
What is the correct way to measure it? I guess it isn't ohmmeter?
Title: Re: Touchscreen interfering with analog input on 4D Systems display
Post by: Brumby on April 04, 2016, 02:25:31 pm
That's not the sort of thing that's easy to measure.  It's the sort of thing you look up on a datasheet.