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

Thread: Teensy 3.1 ADC lag issues. taking 10-20ms to detect immediate changes in voltage.

  1. #1

    Teensy 3.1 ADC lag issues. taking 10-20ms to detect immediate changes in voltage.

    I have been trying to get a soft pot (touch strip potentiometer) working with the teensy for a music controller project. Here is my circuit.
    Click image for larger version. 

Name:	TeensySoftpotImage.jpg 
Views:	250 
Size:	62.5 KB 
ID:	3143

    It is easy enough to output the absolute position of my finger via Serial or usbMIDI. (Must be sure to use a 10k between the collector pin of the sensor and ground - otherwise you will get random noise when it is not pressed)

    I am trying to use the soft pot kind of like a rotary encoder - I want to make increments/decrements to an existing value in software rather than select some fixed position. Volume control for example. Rather than having the sensor select between levels 0-127, I want it to simply increase or decrease by a certain amount from the current value. It will not matter where the finger is initially placed on the soft pot - it is the distance from this initial placement that is the relevant data. So if I place my finger in the middle of the soft pot, then slide up 25% the length of the soft pot, the volume will increase by 25%.

    In designing the software side of this, it necessary to be able detect when the sensor is pressed, and when it is released.


    Here is the issue. When I press down on the soft pot , the analog input is actually ramping up to the value rather than jumping to it immediately - the same is true for release and ramping down to zero. Hypothetically, this delay/ramp should be able to be managed in software with relevant delays. But the delays are too long, and confusing me because they are much longer than expected. A guy on the phone from SpectraSymbol (soft pot manufacturer) brought up that the teensy data sheet indicates a 10pf internal capacitor for the adc, so with a 10kish resistor(the soft pot) the delay should be less than a microsecond. I am seeing delays from 10-50 MILLISECONDS! This is approaching being slower than my movement which won't work. Here is my teensy code and the output I'm seeing when I press, hold, and release.

    int a=0;
    int alag=10;

    void setup(){

    void loop(){
    a = analogRead(A0);


    6567 0 *
    6567 1
    6579 0
    6580 1 noise fluctuations between 0 and 1 ... I am not pressing it
    6580 0
    6605 1
    6605 0 *
    12958 21 * I press the soft pot and it takes until 13,047ms to get to the value I am actually at, 97
    12958 82
    12958 83
    12958 84
    12958 85
    12958 87
    12959 88
    12959 89
    12959 90
    12959 91
    12964 90
    12971 91
    12975 92
    12983 93
    12990 94
    13006 95
    13024 96
    13047 97 HERE *
    16248 96
    17898 97
    18757 96 * I hold the value for a few seconds and then begin release here
    18763 95
    18766 94
    18769 93
    18770 92
    18773 91
    18773 90
    18775 89
    18776 87
    18777 86
    18777 85
    18777 84
    18778 83
    18778 82
    18778 81
    18778 78
    18778 76
    18778 70
    18778 62
    18778 47
    18778 35
    18778 0 and it finally gets to zero here. it is taking 18ms to release to zero. *
    18779 1
    18780 0
    18782 1
    18782 0
    18783 1
    18783 0
    18786 1
    18786 0
    18786 1
    18786 0
    18787 1

    Why is there a delay thousands of times longer than expected? Is this sort of delay actually just inherent to using an analog sensor with a micro controller, or is there something I can do to make things more immediate? And if anyone has any code ideas for my relative positions sensing I am happily all ears!

  2. #2
    Senior Member
    Join Date
    Jun 2013
    So. Calif
    I wonder if Serial.print() is flooding the buffers -maybe you need a delay(100) or some such inside the loop, to prevent blasting the serial/USB link.
    I suppose de-buffering could hog CPU time such that reading the ADC is delayed until the buffers fill.
    Or not.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    An oscilloscope would really be ideal for troubleshooting this problem, to see the actual voltage Teensy is receiving over time. Your code looks fine. There are ways to introduce lag, but I don't see anything wrong here. I'm pretty sure the numbers you're seeing from Teensy are a faithful representation of the signal it actually received.

    My best guess, based only on the data and code posted, is the touch strip may be sensitive to more than just position. It very likely also has some response to how much pressure your finger is applying. Perhaps that could be due to more surface area, which slightly changes the net contact distance from the wires, as your skin and the sensor's material flex.

    In the data, the reading goes from nothing to 91 within 1 millisecond (12958 to 12959). That seems like a very rapid response to me. Then, 16 ms later (at 12975) it begins to rise further, reaching 97 after another 72 ms (at 13047).

    Perhaps your finger made initial contact at 12958, and your skin started the flex and increase the area/pressure of contact at 12975, with the full amount of pressure & surface area pressed at 13047?

    A simple experiment (in the absence of an oscilloscope) might involve watching the numbers as you touch the material differently. My guess is you'll be able to see these sorts of changes as you vary the amount of pressure (and skin surface area contact) onto the sensor.

    But that's all just guesswork, from the numbers & code you posted, and my intuition about a specific sensor I've never actually used. An properly configured oscilloscope would really give a true picture of what the sensor is really doing.
    Last edited by PaulStoffregen; 12-17-2014 at 09:03 AM.

  4. #4
    Hey Steve - the Serial.print is only outputting if it detects a large enough change in value, so I don't think it is being blasted. The delay(100) wont work because I need to have immediate sensing of my positions, and so the Serial output has to be faster than my hand.

  5. #5
    Paul - thanks for the response, and sorry for my delay, just getting back to this project now.

    You are completely right - the sensor is sensitive to more than position. I hooked it up to an oscilloscope, and am seeing exactly the sort of curve you're talking about. It is extremely fast, but its there. When I press down on the strip, it takes less than a millisecond to jump from zero to a value close to the expected, and then takes around 20 ms to reach the actual value. The same is true on release, slow ramp down and then a quick jump to zero.
    This is not an issue with the teensy - it is simply exactly what the sensor is outputting.

    Thanks for your help! From here on I'll just do my programming with this behavior taken into consideration.

    Once I get it all working, i'll post some code and a video of it all.

  6. #6
    Here is a picture of the scope when my finger is released from the sensor - each grid column is 20 milliseconds.
    Pressing down on the sensor looks the same but opposite direction of course.

    Click image for larger version. 

Name:	SoftPotScopeRelease.jpg 
Views:	141 
Size:	101.7 KB 
ID:	3246

Posting Permissions

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