Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Cable tester using touchRead() pins for other functions

  1. #1

    Cable tester using touchRead() pins for other functions

    I am having a hard time finding some information on touchRead(). It appears simple enough to use, just insert the pin number in there and it spits out a value.

    1. It returns the value in units about 1/20th of a pF. Is that correct?

    2. What is the maximum capacitance it will measure before it overflows and returns a -1?

    3. What is the maximum amount of time before it returns?

    4. Is it blocking?

    5. Will a 470 ohm resistor in line with the touchRead() pin prevent using it effectively?

    6. Can I switch between using touchRead() on a pin, and using the pin for an IO pin?

    What I am doing: A cable tester for a cable with 4 wires.

    How I'm thinking of doing this: Connect the 8 pins total to 8 of the touchRead() pins on a Teensy 3.0. First, set all pins as input with the internal pullup active. Then pull each pin low one at a time and check that only the matching pin also pulls low. The 470 ohm resistor is to prevent overcurrent if a pin is shorted to ground.

    If any of the wires are shorted to each other, an indication is given.

    To determine which end of the cable has an open, touchRead() will then be used on each of the ends of the cable on the wires indicating an open circuit. The other wires will also be read to give an indication, as there is a variation in cable length over about a 5:1 range, and the multiwire cable comes in at least two varieties. I am fairly certain that the maximum capacitance on any wire is 1nF to 2nF, and that the shortest cable will still have at least 100pF.

    It is to continue testing the cable as long as it is turned on.

    So am I on the right track? I am a newbie to programming but not to electronics.

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Colmar, France
    1. With the TSI settings of the Teensyduino core touchRead function, it's 1/50 of a pF. But many other settings are possible by writing directly to the TSI configuration registers.
    2. 65535 x the units (default 1/50pF IIRC) makes ~1.2nF
    3. Depends on the capacitance and the resolution, the higher, the slower. Again, reconfiguring the TSI registers allows to trade speed vs accuracy
    4. The touchRead function is blocking, yes. But there are mechanisms to make the TSI non blocking and/or continuous measurements, triggering an interrupt when complete.
    5. Yes.
    6. Yes. IIRC, I gave you that answer already in a different thread.

    To fully understand how the TSI engine works and to get the maximum out of it, I highly recommend that you read the corresponding chapter in the reference manual (for the Teensy 3.2 it's chapter 50, p.1339) and that you look at the source code of the touch.c core file.

  3. #3
    Thank you. I saw your answer, I posted that and then realized I had a lot more questions and should start a thread. Although there, I was not clear what I meant.

    With this project, I'm fine with it being blocking. Makes things easier, in fact.

    Not being able to include a series resistor stops me in my tracks, though. Will a series resistor just prevent it from working, or just degrade the accuracy? 100 ohms?

    To use the pins as IO, the resistor is required to limit current.

    If I must, I suppose I could use 8 more pins. There are certainly enough available. I only need a few pins left for an I2C display or a few LEDs.

  4. #4
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Colmar, France
    Since the TSI engine detects the capacitance with a constant current source and the rise/fall time of the resulting triangle signal, the same constant current will create a voltage drop across the resistor which will lead to the TSI seeing much shorter rise and fall times which in the end will lead to very small result numbers in a relatively unpredictable way. So, it's much worse than just degrading accuracy.

  5. #5
    Thanks for the tips, I will look that up.

    In case anyone looking up touchRead() finds this, I found this on the Kickstarter page for the Teensy:
    Touch Sensing
    The touchRead(pin) function is finally implemented. It works similarly to analogRead(pin). Just call the function with one of the pins that has touch sensing, and it will return a 16 bit number representing the capacitance on that pin, in 1/50th pico-Farad units. If the pin has 40 pF, you'll get 2000.

    The measurement is the capacitive coupling to ground. For human touch interfaces, the best results are when the person's body is physically connected to ground. With hand-held devices, usually the enclosure has exposed metal for this purpose. It still works reasonably if Teensy's ground is connected to earth ground, usually through the USB cable. But running from a battery (called "floating") or connected to a laptop computer running from its battery doesn't work well.

    Of course, it's possible to implement capacitive sensing using ordinary pins. The CapSense library does it quite well. But Teensy 3.0's built-in hardware gives you 3 things you can't get from software-based capacitive sensing.

    1: Sensitivity: By default, touchRead() gives 0.02 pF sensitivity.

    2: Speed: The measurement time depends on the capacitance. A worst-case measurement takes about 5 ms. Typical capacitances used for human touch typically read much faster. Even when cycling through all the touch sensitive pins, you get excellent sensitivity at very responsive speeds.

    3: Stability: The measurement works by comparing the pin's capacitance to an on-chip reference capacitor. If the power supply voltage, charging and discharging currents or other electrical factors change, their effect on the measurement are largely canceled out by using the same on-chip hardware to measure both the pin and the reference capacitor.

    The common use is to replace buttons and sliders with touch-sensitive controls. But with 0.02 pF sensitivity, perhaps touchRead() can be used for other very interesting projects?

Posting Permissions

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