Teensy 3.5 analog input always returns 65535

Status
Not open for further replies.
I measured it with my meter and the voltage between analog input pin and GND / analogGND (I have them connected) is 2.36V, but the analogRead() funcion always returns 65535. I used jumper cable to connect pin to GND and readings went to 0, so something works, but it doesn't work as it should or as I expected it.

The voltage source is this voltage divider, BATT_LVL goes to pin 22 on Teensy 3.5.
Bez tytułu.png

Edit: I've found the culprit - getting CPU temperature using <InternalTemperature.h> library. Do you have any idea, why this library made analogRead() useless?
 
Last edited:
Edit: I've found the culprit - getting CPU temperature using <InternalTemperature.h> library. Do you have any idea, why this library made analogRead() useless?

The default setting (begin()) for InternalTemperature lib will do analogReference(INTERNAL); (1.2v)

As Frank notes, without seeing your sketch, we can only guess.
 
I have hundreds lines of code that requires multiple external components in order to work... and my problem was specifically that one thing... nobody would even try to understand that code, not to mention finding all the components and physically testing it...
 
I have hundreds lines of code that requires multiple external components in order to work... and my problem was specifically that one thing... nobody would even try to understand that code, not to mention finding all the components and physically testing it...

Ah, then your challenge becomes developing a small program that exhibits the problem. In this case, it seems a small program that uses InternalTemperature and reads an analog pin with 2.4v on it. Experiment with the different values to begin() in InternalTemperature lib.
 
As mentioned it is sort of hard to help here when there is nothing to check.

That is are you using the library: https://github.com/LAtimes2/InternalTemperature ?

How are you calling it? How are you reading the analog pin? Are you using the built in analogRead(pin) code
or are you using ADC library? or...

Again why I ask, is there are comments in that library:
Code:
  // Note: If settings_type is TEMPERATURE_MAX_ACCURACY, it will change
  //       the ADC settings to be optimal for reading temperature.
  //       If settings_type is TEMPERATURE_NO_ADC_SETTING_CHANGES, it will
  //       keep the default ADC settings or any other settings changes.
  //       readTemperature will detect the current settings and use them.
  bool begin (int temperature_settings_type = TEMPERATURE_MAX_ACCURACY);
 
I reproduced your problem with this simple sketch using Arduino 1.8.11 and TD 1.51-beta1
Code:
//
// Teensy 3.x/LC simple internal temperature
//

#include <InternalTemperature.h>

InternalTemperature temperature;

void setup()
{
  analogWrite(A21, 192);  // 2.5v on DAC0 jumper to A8 (pin 22)
  analogReadResolution(16);
  temperature.begin(1);   // 0 max/internal(1.2v)   1 external 3.3v

  Serial.begin(115200);
  while (!Serial);
}

void loop()
{
  Serial.print("Temperature: ");
  Serial.print(temperature.readTemperatureC(), 1);
  Serial.println("°C");
  uint32_t val = analogRead(A8);  // pin 22
  Serial.printf("A8 %d %.2f v\n", val, 3.3 * val / 65536);
  delay(3000);
}
CORRECTION: do DAC before all else to get 2.48 v on DAC pin.
I use the T3.5 DAC0 to produce 2.48 v on pin A21 jumpered to pin 22 (A8), using the latest InternalTemperature lib and Teensy analogRead(). The analogRead() is 65535 when using 0 (default) for the temperature.begin(). When using temperature.begin(1), analogRead returns expected value.
 
Last edited:
Status
Not open for further replies.
Back
Top