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

Thread: Teensy 3.5 analog input always returns 65535

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Posts
    13

    Teensy 3.5 analog input always returns 65535

    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.
    Click image for larger version. 

Name:	Bez*tytułu.png 
Views:	1 
Size:	35.4 KB 
ID:	19491

    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 by WGSpacetime; 03-26-2020 at 03:04 AM.

  2. #2
    Hello,

    maybe you have set your reference voltage to INTERNAL, wich is 1.2 Volt für teensy 3.5

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,525
    Forum Rule: Always post complete source code & details to reproduce any issue!

  4. #4
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,383
    Quote Originally Posted by WGSpacetime View Post

    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.

  5. #5
    Junior Member
    Join Date
    Jan 2020
    Posts
    13
    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...

  6. #6
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,383
    Quote Originally Posted by WGSpacetime View Post
    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.

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,315
    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);

  8. #8
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,383
    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 by manitou; 03-26-2020 at 07:34 PM. Reason: do DAC first

  9. #9
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,383
    I corrected post #8

Posting Permissions

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