InternalTemperature problem

Status
Not open for further replies.

alex64

New member
hi !

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

image_2021-06-18_115759.png

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 ? :eek:

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
 
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.
 
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);
 
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
}
 
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..?
 
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.
 
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.
 
Status
Not open for further replies.
Back
Top