touchRead Sensitivity to Noise and solutions with Teensy 3.6

Status
Not open for further replies.

RHormigo

New member
Hi Everybody,

I am open to suggestions and corrections in my limited experience with Teensy... this is mostly a long report for that people that (like myself) has gotten stuck with noise trouble in the touchRead() command. Or for the no Teensy people using the same Freescale Touch Interface TSI inputs in MK66 or similar families this may help too. My goal here is to document my two night experience and some solutions. So a bit of background first, please do not sleep on me...

For a while I have been working in a Teensy science research platform that I will release on the open soon, but I just got the first prototype and was preparing a set of software examples and diagnostics with all the hardware involved. Surprisingly the simplest thing is giving me more trouble.... Just touchRead() noise sensitivity. My test program is just a loop that does this:
void loop() {
Serial.println(touchRead(0));
delay(50);
}

The purpose of this code was just showing how easy it is to use the touch interface, testing that works fine, and show its wire capacitance limits and values for any particular set up.

Now my "noisy" background: most of my work has been done in a Neuroscience state of the art lab either in a third floor exposed to outside with glass and lots of big computers around, or in a 4 level underground EE and mechanical shop facility. Both places are not immune of EMI, on top of that we have big 9 Ts MRI machines next door (100 meters). However, despite of not being in a especially EMI quiet environment, in both of these locations things worked flawlessly, quiet and stable. And it was tested and recorded in action for weeks.... then MF SARS CoV 2 showed up in our lives!

So I moved to work mostly from home and got distracted in other emerging COvid projects for a while, but now still in my apartment just got back to our new TeenScience platform to see how we could address a problem we had in some research that can not afford the long time that TouchRead() needs to run, so I was about to implement a couple ideas, when I realized touchRead() was all over the place, no usable. Numbers were crazy, so I tried the obvious, change ports, board, power supply. I even just left a stand alone new-brand Teensy 3.6 direct to the USB and a short 6" cable in the Touch 0 pin, and still the same. So all this in my apartment, yes a rather tall location 26 floors below me in UWS Manhattan, but not significantly crazy noise sources or nearby RF that I am aware.

So these are some serial plots as reference of how is a clean touch and another subject to initially unknown noise in my home lab. All in the very same stand alone Teensy 3.6 board with a 6" wire:

CleanTouch3.6.png TDefault.png

So after powering everything off in my home lab and next door living room, still the noise is visible in a running plot like above, perhaps a bit less using a small tablet laptop, so I shaped the touch wire in a bit of a loop to capture noise and hunt around :) Only the lab and hallway were noisy, the far bedroom had zero noise. So after some ghost hunting eventually I caught that two Ethernet CAT5e runs to the lab were emitting as crazy. Even with the computers off in the lab the switch in my comm closet near the entrance was on so some signaling was going to the wires. So after I unplugged these Ethernet wires at the source the improvements began, but nowhere close to usable yet. More testing followed to realize the noise was getting via ground, so I tried a few USB GND isolators and got some significant success with the "Adafruit Full-Speed USB Isolator" . Tested with No Ethernet wiring, and with Isolator separately and combined... see next plots. And almost usable now, but not quite the stable I was looking for, so out of ammunition I just shuttled down the comm closet entirely, only out of curiosity as obviously is not practical try to work without network comms, or my family with no Internet :rolleyes: By the way, the isolator proved very useful also for applications that need less influence from the user when touching simultaneously metal or ground (by accident) and the touch pin.

Noise with noEthernet.png Noise Iso.png Noise with noEthernet+gnd iso.png Noise IsoEthernetCommsOff.png

So, I thought this was not realistic to think this interface was going to be working always in low noise conditions, and my apartment can be a relative normal setup (other than being quite high exposed to lots NYC RF)... anyway, so I jumped into the Freescale touch interface (TSI) documentation and drivers in the Teensyduino core to see how to reduce the sensitivity in this interface to EMI / RF. Looking the Block Diagram below, and with no time to trying to understand the internal details, looks to me (help me here) and by intuition only, that the current defined by EXTCHRG acts on the charging speed for the capacitance in the pins, as far CURSW is not activated. If this is very weak RF may have more weight (speculation here). Also the number of scans and rate controlled by NSCN and PS should help filtering and scaling the counter range that is the number you see in touchRead().
In the Teensyduino driver touch.c core file, I noticed there are three constants that drive this: CURRENT (For EXTCHRG), NSCAN (for NSCN), and PRESCALE (for PS) for most modules, but in Teensy 3.6 hides CURRENT?? There was a post of somebody that already played with these parameters, but won't have an effect in CURRENT for Teensy 3.6.
Anyway, in my first experiments I was increasing the current but at he register level where I can manipulate easily in a single line all parameters (including the Oscillator REFCHRG). After I finish all, this can be done nicely or even set a function for setting, only I wonder why CURRENT was hidden for Teensy 3.6. In my application, and noise condition I succeed enough with these settings, so I didn't try any further. I am sure can be improved easier or better adapted to applications that require fading or more linearity.
Original line: TSI0_GENCS = TSI_GENCS_REFCHRG(4) | TSI_GENCS_EXTCHRG(3) | TSI_GENCS_PS(PRESCALE) | TSI_GENCS_NSCN(NSCAN) | TSI_GENCS_TSIEN | TSI_GENCS_EOSF;
Edited Hi Current for
noisy environment line: TSI0_GENCS = TSI_GENCS_REFCHRG(1) | TSI_GENCS_EXTCHRG(7) | TSI_GENCS_PS(7) | TSI_GENCS_NSCN(31) | TSI_GENCS_TSIEN | TSI_GENCS_EOSF;

block.png Noise NoIsoEthernetHiCurr.png Noise IsoEthernetHiCurrent.png Noise w Iso noEthernet and HiCurrent.png

To summarize for now, a practical solution in this noisy environment and to minimize also ground touching influence is to combine: The edited Hi Current setting code above. No Ethernet Wiring nearby, instead I bought a couple of hi speed WIFI USB3 sticks for my tower computers and no increase of noise at all vs no wiring. Then I left installed the wonderful Adafruit isolator (this is only ok up to 100ma load) beyond that you need to power your Teensy with another isolated power supply via Vin (Use diode oring) or find another isolator for more current.
 
Status
Not open for further replies.
Back
Top