
Originally Posted by
manitou
As the forum rule suggests, you need to provide a sketch that someone could actually run and test. There are no ADCs on Port C.
You should use analogRead() not adc_read(). The mux values for adc_read() are not linear. See
https://www.pjrc.com/teensy/adc_simple.zip from
https://www.pjrc.com/teensy/adc.html
this simple sketch reads all the ADC pins on Teensy 2
Code:
void setup() {
Serial.begin(9600);
}
void loop() {
int i, val;
for (i = 0; i < 12; i++) {
Serial.print(i); Serial.print(" "); Serial.println(analogRead(i));
}
delay(2000);
}
You can jumper GND to each of the ADC pins and see that the corresponding value changes.
Thanks and sorry for wrong format, safari did not show anything about it. And I misspelled Port C instead of Port B while not copy-pasting.
This code snippet is part of a longer project with a dozen files and more than thousend lines, written in C. It loggs data via nRF24L01-Modules and saves it to a sd-card.
I used the adc_read() in several projects from ATiny13 to Atmega644 and teensy2++ with adopted macros without problems.
The gcc compiler shows no overrun of RAM or things like that. I only wonder why the teensy2 behaves in this manner for the channels on Port B.
I modified your code snippet to read only channel 1 and 11.
Code:
int i, val;
Serial.print(1); Serial.print(" "); Serial.print(analogRead(1));
Serial.print(" ");
Serial.print(11 ); Serial.print(" "); Serial.print(analogRead(11));
Serial.println();
The result is rather strange.
Both pins are connected to the same value (output of an analog 3x4 keyboard)
Channel 1 reads as expected. Channel 11 reads another value.
inserting a delay between the readings changes the return value of channel 11.
Code:
Serial.print(1); Serial.print(" "); Serial.print(analogRead(1));
Serial.print(" ");
delay(1000);
Serial.print(11 ); Serial.print(" "); Serial.print(analogRead(11));
Serial.println();
Attatched is an excel sheet with the results. (val 11 A with delay, val 11 B without delay)

Connecting channel 11 to ground changes nothing, the reading of the channel is the same as when connected to the input voltage. Connecting channel 1 to ground fixes the reading of channel 11 to a constant value for every input value. Connecting all open ADC channels to ground gives another serie of data on channel 11.
The oscilloscope shows proper values.
Somewhat is going wrong.