touchRead() all pins simultaneously

Status
Not open for further replies.

ftrias

Well-known member
I'm doing a project where I use all 12 touch pins. I need fairly fast reaction times and low lag. As I looked at implementing this, it seems I need to call touchRead() for each pin. However, there is a delay built into each touchRead(), along with a wait for states to change. Unfortunately, I'm not familiar enough with the internals of the teensy, so I'm wondering if there is a way to speed things up by reading all pins at the same time.
 
No, unfortunately this is impossible. The touch sensing hardware inside the chip measures only 1 pin at a time. It's much like the ADC... even though there are many analog input pins, inside the chip there's only 1 ADC that actually measures the voltage. It just gets connected temporarily to the pin when you call analogRead().

The maximum delay is relatively fast, only several milliseconds, and that only happens if there's a huge capacitance on the pin. Sweeping through all 12 should normally be quite fast, compared with human perceivable times.

But if you want to go faster, the touch sensing hardware as a LOT of configurable options. You'll need to edit the code directly. Going faster usually involves trading off resolution for speed, but if you don't need the full resolution, you can program the relative currents and counts to go faster.
 
I'm having another problem. I connected all 12 pins and am getting some strange results. When I touch a pin, the pin next to it also rises with a slight lag and then settles back down and then back up. I connect each pin to a thumb tack for testing. Below is my code. I touch my pad number 11, which is connected to pin 0. The value for 11 goes high, then drops as the value for pad number 10 (pin 1) goes higher and matches pad 11. The value for pad 11 stays stable and the value for pad 10 goes up and down. Pad 10 and 11 are 6 inches apart. Same thing happens with other pins.

int pinTouch[] = {32,33,25,22,23,19,18,17,16,15,1,0};

void setup() {
Serial.begin(9600);
}

void loop() {
int pin;
int v;
for(int i=0; i<12; i++) {
pin = pinTouch;
v = touchRead(pin);
Serial.print(i);
Serial.print("=");
Serial.print(v);
Serial.print(" ");
}
Serial.println(" ");
delay(500);
}

0=502 1=500 2=506 3=639 4=751 5=730 6=729 7=599 8=524 9=558 10=720 11=791
0=499 1=504 2=507 3=641 4=754 5=732 6=726 7=603 8=523 9=558 10=735 11=890
0=501 1=501 2=506 3=640 4=753 5=733 6=731 7=601 8=524 9=559 10=808 11=6040 <-- touch 11 only
0=502 1=503 2=507 3=639 4=754 5=737 6=728 7=601 8=523 9=557 10=814 11=2671 <-- 10 starts rising
0=503 1=499 2=506 3=638 4=750 5=738 6=732 7=602 8=523 9=557 10=863 11=3029
0=503 1=505 2=508 3=638 4=750 5=736 6=734 7=603 8=524 9=560 10=1661 11=1651 <-- 10 higher than 11!
0=508 1=502 2=508 3=634 4=755 5=739 6=734 7=604 8=524 9=557 10=1029 11=1620
0=502 1=505 2=508 3=638 4=747 5=739 6=732 7=602 8=524 9=558 10=985 11=1657
0=501 1=503 2=507 3=636 4=749 5=738 6=731 7=603 8=524 9=558 10=1044 11=2109
0=504 1=505 2=507 3=640 4=752 5=745 6=736 7=605 8=525 9=557 10=1648 11=1654 <-- 10 and 11 almost the same
0=504 1=505 2=507 3=637 4=749 5=743 6=732 7=603 8=523 9=559 10=1181 11=1664
0=503 1=505 2=507 3=641 4=751 5=741 6=734 7=607 8=524 9=557 10=1153 11=1646
0=501 1=498 2=506 3=638 4=753 5=731 6=727 7=604 8=522 9=557 10=719 11=789
0=501 1=503 2=506 3=638 4=746 5=733 6=729 7=603 8=523 9=557 10=721 11=791
 
Status
Not open for further replies.
Back
Top