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

Thread: InternalTemperature problem

  1. #1
    Junior Member
    Join Date
    Jun 2021
    Posts
    1

    InternalTemperature problem

    hi !

    I'm using this code which displays the tension measured on pin A12 and the internal Temperature using InternalTemperature library.
    The problem ?

    Name:  image_2021-06-18_115759.png
Views: 80
Size:  6.3 KB

    As you can see, the first time I display voltage there is no problem, but after getting the temperature, the voltage just displays wrong value.

    Anyone already have this problem and/or know how to resolve it ?

    Code:
    #include <InternalTemperature.h>
    
    void setup() {
      Serial.begin(9600);
      delay(500);
    }
    
    void loop() {
      Serial.print("\nvoltage = ");
      Serial.println(getVoltage());
      delay(500);
      Serial.print("temperature = ");
      Serial.println(getTemperature());
      delay(500);
    
    }
    
    float getTemperature() {
      return InternalTemperature.readTemperatureC();
    }
    
    float getVoltage() {
      return analogRead(A12) * 3.3 * (82 + 10) / float(1023 * 10); //82 & 10 are resistance in kOmh
    }
    win10/arduino 1.8.13/teensy 3.2

  2. #2
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    202
    I think the temperature library is messing with the ADC Resolution, Voltage reference and Averaging. Try to reload the Voltage reference and number of bits to what your default choice was. Averaging won't disturb your reading as much as the other two settings would.

  3. #3
    Member
    Join Date
    Aug 2018
    Location
    Brisbane, Australia
    Posts
    59
    Check this:
    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.
      static bool begin (int temperature_settings_type = TEMPERATURE_MAX_ACCURACY);

  4. #4
    Senior Member
    Join Date
    Jul 2015
    Posts
    116
    Try adding a call to "begin" in setup:

    Code:
    #include <InternalTemperature.h>
    
    void setup() {
      Serial.begin(9600);
      InternalTemperature.begin (TEMPERATURE_NO_ADC_SETTING_CHANGES);
      delay(500);
    }
    
    void loop() {
      Serial.print("\nvoltage = ");
      Serial.println(getVoltage());
      delay(500);
      Serial.print("temperature = ");
      Serial.println(getTemperature());
      delay(500);
    
    }
    
    float getTemperature() {
      return InternalTemperature.readTemperatureC();
    }
    
    float getVoltage() {
      return analogRead(A12) * 3.3 * (82 + 10) / float(1023 * 10); //82 & 10 are resistance in kOmh
    }

  5. #5
    Hm.

    Thought I'd give this a shot as I'm curious about maybe up-clocking the t4.1 and monitoring temperature might be smrt.

    I'm seeing about 50c.. ambient temp is maybe 20-25c? does this sound about right?

    It does seem to be responding, I was a bit worried at first when I put a extra pi heat sink on and didn't really see a change so I took a lighter to the heat sink and it went up 3-4 degrees after about 5-10 sec.. 50 seems a bit high though? chip didn't feel anywhere near like 50c when I touched it before heatsink..

    I don't really see any difference between TEMPERATURE_NO_ADC_SETTING_CHANGES and TEMPERATURE_MAX_ACCURACY ..? I assume though that maybe the difference could the be exaggerated if ADC stuff was changed by other stuff..?

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,492
    Quote Originally Posted by forbiddenera View Post
    Hm.

    Thought I'd give this a shot as I'm curious about maybe up-clocking the t4.1 and monitoring temperature might be smrt.

    I'm seeing about 50c.. ambient temp is maybe 20-25c? does this sound about right?

    It does seem to be responding, I was a bit worried at first when I put a extra pi heat sink on and didn't really see a change so I took a lighter to the heat sink and it went up 3-4 degrees after about 5-10 sec.. 50 seems a bit high though? chip didn't feel anywhere near like 50c when I touched it before heatsink..

    I don't really see any difference between TEMPERATURE_NO_ADC_SETTING_CHANGES and TEMPERATURE_MAX_ACCURACY ..? I assume though that maybe the difference could the be exaggerated if ADC stuff was changed by other stuff..?
    Temp is a spot temp internal to the MCU somewhere, not what is apparent on the casing.

    50C doesn't sound awful - depending on the workload - and not running OC above 600 MHz. I haven't watched lately (notes posted on Beta thread) - may be on the warmer side IIRC. Decent Heat sink will net a couple degrees of drop - a fan moving air over the whole board is better (about double) as it cools the whole of the board as heat sink with solder connect to MCU.

    Whatever <InternalTemperature.h> does - when told not to change ADC settings it probably calibrates to compensate and gets close enough.

  7. #7
    Senior Member
    Join Date
    Jul 2015
    Posts
    116
    For a Teensy 4, TEMPERATURE_NO_ADC_SETTING_CHANGES and TEMPERATURE_MAX_ACCURACY aren't used. InternalTemperature is just a wrapper around tempmonGetTemp.

    The original poster was probably using a Teensy 3, where it does make a difference.

Posting Permissions

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