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

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
    Location
    Colmar, France
    Posts
    2,530
    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
    Location
    Colmar, France
    Posts
    2,530
    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:

    https://www.kickstarter.com/projects...rduino-a/posts
    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?

  6. #6
    For a four wire cable with ground shield, I will be testing for open, and/or wires shorted to other wires, or to ground. The short or open always happens in the connector body, never along the cable. I also need this to tell me which end of the cable has the break, that is the reason for reading capacitance. So eight touchRead() pins used on a Teensy 3.0. I also have an OLED display, so I've had to solder a few wires on the bottom to bring the other touchRead() pins out.

    I will refer to pins when I mean the pin in a connector, and wire when I mean the wire in the cable between the connector pins.

    I'm thinking of this sequence:

    All eight pins as outputs, set Low.

    One at a time, set a pin to input with pullup. If it reads 1, that wire is open on one end or the other.

    With one pin set to input with pullup, set its match to input with pullup. If it reads 0, that wire is shorted on one end. Set each of the other pins as input with pullup in turn to determine which one is shorted, the inputs should read 1 when the pin that is shorted to the pin under test is set as input. If the pin under test reads 0 even when all other pins are set as input, then it is shorted to ground.

    I was originally planning on using an inductance measurement to determine which end of the cable is shorted, but I have since determined that physical manipulation will clear the short and indicate which end is shorted. If it reads 1, then that wire is good at both ends.

    In the event of any pins reading open, each end will have capacitance measured using touchRead().

    This is meant to be a continuous test so the cable can be manipulated to detect intermittent faults. The display will indicate which error or indicate Good. A quiet "beep" will indicate when a fault is detected. I was thinking of having the frequency or pattern change depending on if it is indicating a short or open.

    Be gentle, I'm only learning to program. I've built cable testers before, but with a PCB full of logic gates.

  7. #7
    Thanks, Theremingenieur.

    By the principle of try it and see, the touchRead() function returns 65535 when it times out by short, or presumably too high a capacitance. My worst case cable reading (the longest cable) is a reading of around 50000 including parasitic capacitance. I'd love more headroom, but it would make things more complicated to add series capacitors. Because I'm using INPUT_PULLUP to check for shorts between wires and to ground.

    At 1/50th of a pF, I guess that makes it about 1000pF maximum cable capacitance.

  8. #8
    I check for any shorts to ground by just setting all 8 pins to INPUT_PULLUP and checking to see that all measure HIGH.

    Check for shorts between pins by setting all pins to OUTPUT and setting LOW, then changing the matching pins to INPUT_PULLUP and checking, after a short delay, to see that they both read HIGH.

    I have it successfully working now. Red LEDs indicate short and which end, a yellow LED indicates a short between pins by turning on solid and a short to ground by blinking. The OLED display won't be in the final box, although I'll still bring the pins out inside and leave the code in place for future troubleshooting and reprogramming.

Posting Permissions

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