Touchscreen interfering with analog input on 4D Systems display - Page 1
Forum section: electronics / beginners

author: ProAce
author_rank: Contributor
timestamp: April 01, 2016, 07:57:15 am
content: 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:#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);wendendif// 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 requiredhndl := 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:26gfx_BGcolour(0x63C8) ;gfx_Cls() ;// 4Dbutton1 1.0 generated 1.4.2016 8:23:52img_ClearAttributes(hndl, i4Dbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this onceimg_Show(hndl, i4Dbutton1); // show button, only do this onceimg_SetWord(hndl, i4Dbutton1, IMAGE_INDEX, state); // where state is 0 for up and 1 for downimg_Show(hndl,i4Dbutton1) ;// Userled1 1.0 generated 1.4.2016 8:31:48img_Show(hndl,iUserled1) ; // show initialy, if requiredimg_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:41txt_FontID(FONT3) ;txt_FGcolour(WHITE) ;txt_BGcolour(BLACK) ;gfx_MoveTo(0 , 0) ;print(Voltage) ;sys_SetTimer(TIMER0, 1000);repeatstate := 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) ;endifif(sys_GetTimer(TIMER0)== 0)getAnalog();sys_SetTimer(TIMER0, 1000);endifforeverendfuncfunc getAnalog()//read AIVsteps := pin_Read(PA1) ;getVoltage(Vsteps);endfuncfunc getVoltage(var reading) //Direct Voltagevar nsteps;var Vref;var Nsteps;var Factor;var Result;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/Nstepsflt_ITOF(nsteps, reading); //Convert the integer 'reading' to a float 'nsteps'flt_MUL(Result, nsteps, Factor);//Float multiplication, Result = nsteps * Factorflt_PRINT(Result, "%.4f");Voltage := flt_FTOI(Result);endfunc

author: danadak
author_rank: Super Contributor
timestamp: April 01, 2016, 11:16:59 am
content: Is this a layout issue, or capacitive coupling in a cable ?What is the A/D input connected to ? Is it floating or terminated ina known source impedance ?Regards, Dana.

author: ProAce
author_rank: Contributor
timestamp: April 01, 2016, 11:52:11 am
content: Input is floating. It is possible they have a layout issue idk.

author: Kilrah
author_rank: Unknown
timestamp: April 01, 2016, 12:06:13 pm
content: Did you actually connect the voltage you want to measure yet? If yes, what's the output impedance of that?

author: ProAce
author_rank: Contributor
timestamp: April 04, 2016, 06:33:59 am
content: Interesting. When I connect the voltage it doesn't interfere. It only does when it's floating. Can someone please explain that.

author: Brumby
author_rank: Unknown
timestamp: April 04, 2016, 07:29:35 am
content: 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.

author: Kilrah
author_rank: Unknown
timestamp: April 04, 2016, 07:39:12 am
content: Quote from: ProAce on April 04, 2016, 06:33:59 amPerfectly 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.

author: ProAce
author_rank: Contributor
timestamp: April 04, 2016, 07:49:00 am
content: Now that you've explained it, it makes sense. Thanks.

author: ProAce
author_rank: Contributor
timestamp: April 04, 2016, 07:57:28 am
content: Quote from: Brumby on April 04, 2016, 07:29:35 amIs it possible it's 1Mohm?

author: Brumby
author_rank: Unknown
timestamp: April 04, 2016, 12:20:51 pm
content: 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....

author: ProAce
author_rank: Contributor
timestamp: April 04, 2016, 12:34:22 pm
content: Quote from: Brumby on April 04, 2016, 12:20:51 pmWhat is the correct way to measure it? I guess it isn't ohmmeter?

author: Brumby
author_rank: Unknown
timestamp: April 04, 2016, 02:25:31 pm
content: That's not the sort of thing that's easy to measure. It's the sort of thing you look up on a datasheet.