defragster
Senior Member+
Wonder if some odd number use might explain the Zero temp @mjs513 showed in a CrashReport w/final beta and one here showed a version of NAN on restart.
wasnt the temperature registers changed recently?
https://github.com/PaulStoffregen/cores/commit/63b036386a16df74ec93e1f2f0ef836d4fa49b40
Not sure that would be the cause for that issue since the temps for testing should have been in the normal range within the scope of unsigned. But always the chance. Yes I am up early - couldn't sleep again.defragster said:Wonder if some odd number use might explain the Zero temp @mjs513 showed in a CrashReport w/final beta and one here showed a version of NAN on restart.
Actually pretty close to the fix I just tested. Using the fault test sketch (High_Temp_ISR_test) wound up converting to float 2 things:LAtimes said:It looks like this is caused by using unsigned integers in tempmon.c. As temperature goes up, nmeas goes down. When it gets below s_hotCount (i.e. above 95 degrees), the value goes negative, which is a large positive number due to unsigned int.
Fix is probably to change nmeas and s_hotCount to signed integers
s_hot_ROOM = (float) (s_hotTemp) - 25.0f;
s_roomC_hotC = roomCount - s_hotCount;
// MyFault - collection of examples to trigger fault exceptions
// This may take a while to trip
#include <InternalTemperature.h>
extern "C" uint32_t set_arm_clock(uint32_t frequency); // clockspeed.c
static uint16_t frequency = 0x03U;
static uint32_t highAlarmTemp = 85U;
static uint32_t lowAlarmTemp = 25U;
static uint32_t panicAlarmTemp = 95U;
volatile bool TempAlarm = false;
void setup() {
Serial.begin(9600);
Serial.print(CrashReport);
tempmon_setup();
//set_arm_clock(912000000);
delay(500);
//Attach window for high/low window
attachInterruptVector(IRQ_TEMPERATURE, &High_Low_Temp_isr);
NVIC_ENABLE_IRQ(IRQ_TEMPERATURE);
}
elapsedMillis tempPrint;
void loop() {
float temperature = tempmonGetTemp();
if(tempPrint > 1000) {
//Serial.printf("Temp(degC) = , %f", temperature);
Serial.print(temperature, 2); Serial.print(",");
Serial.println(InternalTemperature.readTemperatureC(),2);
tempPrint = 0;
}
//comment this test out if you want to test panic alarm!!!!!
if (TempAlarm && ((temperature - highAlarmTemp > 0)) && (temperature - panicAlarmTemp < 0) )
{
set_arm_clock(24000000);
delay(500);
TempAlarm = false;
Serial.println();
Serial.println("Danger Will Robinson");
Serial.printf("HIGH Temperature Alarm %.1f. \r\n", temperature);
Serial.println("System Clock set to 24Mhz");
Serial.println();
}
}
static uint32_t s_hotTemp, s_hotCount ;
static float s_hot_ROOM, s_roomC_hotC;
void tempmon_setup(void)
{
uint32_t calibrationData;
uint32_t roomCount;
uint32_t tempCodeVal;
//first power on the temperature sensor - no register change
//power is already on so uncomment for example
TEMPMON_TEMPSENSE0 &= ~0x1U;
//set monitoring frequency - no register change
TEMPMON_TEMPSENSE1 = (((uint32_t)(((uint32_t)(frequency)) << 0U)) & 0xFFFFU);
//read calibration data - this works
calibrationData = HW_OCOTP_ANA1;
s_hotTemp = (uint32_t)(calibrationData & 0xFFU) >> 0x00U;
s_hotCount = (uint32_t)(calibrationData & 0xFFF00U) >> 0X08U;
roomCount = (uint32_t)(calibrationData & 0xFFF00000U) >> 0x14U;
s_hot_ROOM = (float) (s_hotTemp) - 25.0f;
s_roomC_hotC = (float) roomCount - (float) s_hotCount;
Serial.println("Calibration values from fuse values:");
Serial.printf(" HOT_TEMP: %d\n HOT_COUNT: %d\n ROOM_COUNT: %d\n", s_hotTemp, s_hotCount, roomCount);
Serial.println("Cal equation: Tmeas = HOT_TEMP - (Nmeas - HOT_COUNT) * ((HOT_TEMP - 25.0) / (ROOM_COUNT – HOT_COUNT))");
Serial.printf("(HOT_TEMP - 25.0) = %f\n", s_hot_ROOM);
Serial.printf("(ROOM_COUNT – HOT_COUNT) = %f\n", s_roomC_hotC);
Serial.println();
//time to set alarm temperatures
//Set High Alarm Temp
tempCodeVal = (uint32_t)(s_hotCount + (s_hotTemp - highAlarmTemp) * s_roomC_hotC / s_hot_ROOM);
TEMPMON_TEMPSENSE0 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 20U)) & 0xFFF00000U);
//Set Panic Alarm Temp
tempCodeVal = (uint32_t)(s_hotCount + (s_hotTemp - panicAlarmTemp) * s_roomC_hotC / s_hot_ROOM);
TEMPMON_TEMPSENSE2 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 16U)) & 0xFFF0000U);
// Set Low Temp Alarm Temp
tempCodeVal = (uint32_t)(s_hotCount + (s_hotTemp - lowAlarmTemp) * s_roomC_hotC / s_hot_ROOM);
TEMPMON_TEMPSENSE2 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 0U)) & 0xFFFU);
//Start temp monitoring
TEMPMON_TEMPSENSE0 |= 0x2U; //starts temp monitoring
}
void High_Low_Temp_isr(void)
{
TempAlarm = true;
}
I modified the panic temp to 100 but then the processor immediately stops after reboot. The max I can use for the panic mode is 95. The problem seems in the read value for the chip value.
If read above 95 the value gets negative. I also dis-abled the shutdown function to be able to see this. I really don't like the behavior it shuts down and does not recover at all. Could this be fixed somehow?
Thanks all.
94.33°C
94.33°C
95.00°C
-2890843392.00°C
95.00°C
-2890843392.00°C
91.63°C
With the latest set of changes two issues are now fixed:
1. Setting panic temp above 95°C
and
2. Correct readings for temperature.
A PR has been issued but I am attaching a copy of the tempmon.c file if you want to give it a try.
I gave the attached file a try but the behavior is the same. All changes I did are also in tempmon.c. When using the crash report sketch It says no data to report.
It is easy to verify. Just change the line
static uint32_t panicAlarmTemp = 95U;
to
static uint32_t panicAlarmTemp = 99U;
The result is a direct crash after reboot when tempmon is called. There is no need to increase the temperature of the IC. Ofcourse I tried that also and when reaching the panic temp the processor restarts until the actual measured temp is below the panic temp.
So that is ok...
// MyFault - collection of examples to trigger fault exceptions
// This may take a while to trip
extern "C" uint32_t set_arm_clock(uint32_t frequency); // clockspeed.c
static int16_t frequency = 0x03U;
static int32_t highAlarmTemp = 50U;
static int32_t lowAlarmTemp = 25U;
static int32_t panicAlarmTemp = 90U;
volatile bool TempAlarm = false;
void setup() {
Serial.begin(9600);
Serial.print(CrashReport);
tempmon_setup();
set_arm_clock(912000000);
delay(500);
//Attach window for high/low window
attachInterruptVector(IRQ_TEMPERATURE, &High_Low_Temp_isr);
NVIC_ENABLE_IRQ(IRQ_TEMPERATURE);
}
elapsedMillis tempPrint;
void loop() {
float temperature = tempmonGetTemp();
if(tempPrint > 1000) {
Serial.printf("Temp(degC) = , %f\n", temperature);
tempPrint = 0;
}
//comment this test out if you want to test panic alarm!!!!!
if (TempAlarm && ((temperature - highAlarmTemp > 0)) && (temperature - panicAlarmTemp < 0) )
{
set_arm_clock(24000000);
delay(500);
TempAlarm = false;
Serial.println();
Serial.println("Danger Will Robinson");
Serial.printf("HIGH Temperature Alarm %.1f. \r\n", temperature);
Serial.println("System Clock set to 24Mhz");
Serial.println();
}
}
static uint32_t s_hotTemp, s_hotCount ;
static float s_hot_ROOM, s_roomC_hotC;
void tempmon_setup(void)
{
uint32_t calibrationData;
uint32_t roomCount;
uint32_t tempCodeVal;
//first power on the temperature sensor - no register change
//power is already on so uncomment for example
TEMPMON_TEMPSENSE0 &= ~0x1U;
//set monitoring frequency - no register change
TEMPMON_TEMPSENSE1 = (((uint32_t)(((uint32_t)(frequency)) << 0U)) & 0xFFFFU);
//read calibration data - this works
calibrationData = HW_OCOTP_ANA1;
s_hotTemp = (uint32_t)(calibrationData & 0xFFU) >> 0x00U;
s_hotCount = (uint32_t)(calibrationData & 0xFFF00U) >> 0X08U;
roomCount = (uint32_t)(calibrationData & 0xFFF00000U) >> 0x14U;
s_hot_ROOM = (float) (s_hotTemp) - 25.0f;
s_roomC_hotC = (float) roomCount - (float) s_hotCount;
//time to set alarm temperatures
//Set High Alarm Temp
tempCodeVal = ((float)s_hotCount + ((float)s_hotTemp - highAlarmTemp) * s_roomC_hotC / s_hot_ROOM);
TEMPMON_TEMPSENSE0 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 20U)) & 0xFFF00000U);
//Set Panic Alarm Temp
tempCodeVal = ((float)s_hotCount + ((float)s_hotTemp - panicAlarmTemp) * s_roomC_hotC / s_hot_ROOM);
TEMPMON_TEMPSENSE2 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 16U)) & 0xFFF0000U);
// Set Low Temp Alarm Temp
tempCodeVal = ((float)s_hotCount + ((float)s_hotTemp - lowAlarmTemp) * s_roomC_hotC / s_hot_ROOM);
TEMPMON_TEMPSENSE2 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 0U)) & 0xFFFU);
//Start temp monitoring
TEMPMON_TEMPSENSE0 |= 0x2U; //starts temp monitoring
}
void High_Low_Temp_isr(void)
{
TempAlarm = true;
}
// MyFault - collection of examples to trigger fault exceptions
// This may take a while to trip
extern "C" uint32_t set_arm_clock(uint32_t frequency); // clockspeed.c
static int16_t frequency = 0x03U;
static int32_t highAlarmTemp = 50U;
static int32_t lowAlarmTemp = 25U;
static int32_t panicAlarmTemp = 55U;
volatile bool TempAlarm = false;
void setup() {
Serial.begin(9600);
Serial.print(CrashReport);
tempmon_setup();
set_arm_clock(912000000);
delay(500);
//Attach window for high/low window
attachInterruptVector(IRQ_TEMPERATURE, &High_Low_Temp_isr);
NVIC_ENABLE_IRQ(IRQ_TEMPERATURE);
}
elapsedMillis tempPrint;
void loop() {
float temperature = tempmonGetTemp();
if(tempPrint > 1000) {
Serial.printf("Temp(degC) = , %f\n", temperature);
tempPrint = 0;
}
//comment this test out if you want to test panic alarm!!!!!
if (TempAlarm && ((temperature - highAlarmTemp > 0)) && (temperature - panicAlarmTemp < 0) )
{
set_arm_clock(24000000);
delay(500);
TempAlarm = false;
Serial.println();
Serial.println("Danger Will Robinson");
Serial.printf("HIGH Temperature Alarm %.1f. \r\n", temperature);
Serial.println("System Clock set to 24Mhz");
Serial.println();
}
}
static uint32_t s_hotTemp, s_hotCount ;
static float s_hot_ROOM, s_roomC_hotC;
void tempmon_setup(void)
{
uint32_t calibrationData;
uint32_t roomCount;
uint32_t tempCodeVal;
//first power on the temperature sensor - no register change
//power is already on so uncomment for example
//TEMPMON_TEMPSENSE0 &= ~0x1U;
//Stop current temp monitoring
TEMPMON_TEMPSENSE0 &= ~0x2U;
//set monitoring frequency - no register change
TEMPMON_TEMPSENSE1 = (((uint32_t)(((uint32_t)(frequency)) << 0U)) & 0xFFFFU);
//read calibration data - this works
calibrationData = HW_OCOTP_ANA1;
s_hotTemp = (uint32_t)(calibrationData & 0xFFU) >> 0x00U;
s_hotCount = (uint32_t)(calibrationData & 0xFFF00U) >> 0X08U;
roomCount = (uint32_t)(calibrationData & 0xFFF00000U) >> 0x14U;
s_hot_ROOM = (float) (s_hotTemp) - 25.0f;
s_roomC_hotC = (float) roomCount - (float) s_hotCount;
//time to set alarm temperatures
//Set High Alarm Temp
tempCodeVal = ((float)s_hotCount + ((float)s_hotTemp - highAlarmTemp) * s_roomC_hotC / s_hot_ROOM);
TEMPMON_TEMPSENSE0 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 20U)) & 0xFFF00000U);
//Set Panic Alarm Temp
tempCodeVal = ((float)s_hotCount + ((float)s_hotTemp - panicAlarmTemp) * s_roomC_hotC / s_hot_ROOM);
TEMPMON_TEMPSENSE2 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 16U)) & 0xFFF0000U);
// Set Low Temp Alarm Temp
tempCodeVal = ((float)s_hotCount + ((float)s_hotTemp - lowAlarmTemp) * s_roomC_hotC / s_hot_ROOM);
TEMPMON_TEMPSENSE2 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 0U)) & 0xFFFU);
// Set Low Temp Alarm Temp
tempCodeVal = ((float)s_hotCount + ((float)s_hotTemp - lowAlarmTemp) * s_roomC_hotC / s_hot_ROOM);
TEMPMON_TEMPSENSE2 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 0U)) & 0xFFFU);
//Start temp monitoring
TEMPMON_TEMPSENSE0 |= 0x2U; //starts temp monitoring
}
void High_Low_Temp_isr(void)
{
TempAlarm = true;
}
Actually, its fixed, the sketch in #53 is outdated after I made the additional changes to fix in the PR and tempmon.c that I posted. This is the latest version of the sketch that matches whats in tempmon.c and in the pr:
Code:// MyFault - collection of examples to trigger fault exceptions // This may take a while to trip extern "C" uint32_t set_arm_clock(uint32_t frequency); // clockspeed.c static int16_t frequency = 0x03U; static int32_t highAlarmTemp = 50U; static int32_t lowAlarmTemp = 25U; static int32_t panicAlarmTemp = 90U; volatile bool TempAlarm = false; void setup() { Serial.begin(9600); Serial.print(CrashReport); tempmon_setup(); set_arm_clock(912000000); delay(500); //Attach window for high/low window attachInterruptVector(IRQ_TEMPERATURE, &High_Low_Temp_isr); NVIC_ENABLE_IRQ(IRQ_TEMPERATURE); } elapsedMillis tempPrint; void loop() { float temperature = tempmonGetTemp(); if(tempPrint > 1000) { Serial.printf("Temp(degC) = , %f\n", temperature); tempPrint = 0; } //comment this test out if you want to test panic alarm!!!!! if (TempAlarm && ((temperature - highAlarmTemp > 0)) && (temperature - panicAlarmTemp < 0) ) { set_arm_clock(24000000); delay(500); TempAlarm = false; Serial.println(); Serial.println("Danger Will Robinson"); Serial.printf("HIGH Temperature Alarm %.1f. \r\n", temperature); Serial.println("System Clock set to 24Mhz"); Serial.println(); } } static uint32_t s_hotTemp, s_hotCount ; static float s_hot_ROOM, s_roomC_hotC; void tempmon_setup(void) { uint32_t calibrationData; uint32_t roomCount; uint32_t tempCodeVal; //first power on the temperature sensor - no register change //power is already on so uncomment for example TEMPMON_TEMPSENSE0 &= ~0x1U; //set monitoring frequency - no register change TEMPMON_TEMPSENSE1 = (((uint32_t)(((uint32_t)(frequency)) << 0U)) & 0xFFFFU); //read calibration data - this works calibrationData = HW_OCOTP_ANA1; s_hotTemp = (uint32_t)(calibrationData & 0xFFU) >> 0x00U; s_hotCount = (uint32_t)(calibrationData & 0xFFF00U) >> 0X08U; roomCount = (uint32_t)(calibrationData & 0xFFF00000U) >> 0x14U; s_hot_ROOM = (float) (s_hotTemp) - 25.0f; s_roomC_hotC = (float) roomCount - (float) s_hotCount; //time to set alarm temperatures //Set High Alarm Temp tempCodeVal = ((float)s_hotCount + ((float)s_hotTemp - highAlarmTemp) * s_roomC_hotC / s_hot_ROOM); TEMPMON_TEMPSENSE0 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 20U)) & 0xFFF00000U); //Set Panic Alarm Temp tempCodeVal = ((float)s_hotCount + ((float)s_hotTemp - panicAlarmTemp) * s_roomC_hotC / s_hot_ROOM); TEMPMON_TEMPSENSE2 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 16U)) & 0xFFF0000U); // Set Low Temp Alarm Temp tempCodeVal = ((float)s_hotCount + ((float)s_hotTemp - lowAlarmTemp) * s_roomC_hotC / s_hot_ROOM); TEMPMON_TEMPSENSE2 |= (((uint32_t)(((uint32_t)(tempCodeVal)) << 0U)) & 0xFFFU); //Start temp monitoring TEMPMON_TEMPSENSE0 |= 0x2U; //starts temp monitoring } void High_Low_Temp_isr(void) { TempAlarm = true; }
cheers
EDIT: Here is the results of running the updated test sketch - no hangs on setting Panic alarm to 110:
View attachment 25494
Ok, I will first try if I can find maybe some problem also. The help here is great. I modified a tempmon.c from TD1.53 that for now helps me to continue. It simply disables the panic temp shutdown. I modified my SW in such a way that I read the temp every sec and write the max value to the EEprom. In this way I also get a good impression what to expect in the car. But running at 20C ambient I already see around 81C. So not that much margin left. I also don't want you to blow your Teensy ofcourse.
93.86
95.00
-2444290304.00
-2444290304.00
95.00
93.86
94.43
94.43
-2444290304.00
-2444290304.00
-2444290304.00
-2444290304.00
-2444290304.00
94.43
93.86
Temp(degC) = , 95.000000
1201, 1201
Temp(degC) = , 95.000000
1200, 1201
Temp(degC) = , 95.569107
1199, 1201
Temp(degC) = , 96.138214
1200, 1201
Temp(degC) = , 95.569107
1198, 1201
Temp(degC) = , 96.707314
1197, 1201
Temp(degC) = , 97.276421
1197, 1201
Temp(degC) = , 97.276421
1196, 1201
Temp(degC) = , 97.845528
1196, 1201
Temp(degC) = , 97.845528
1196, 1201
Temp(degC) = , 97.845528
1194, 1201
Temp(degC) = , 98.983742
1194, 1201
Temp(degC) = , 98.983742
1193, 1201
Temp(degC) = , 99.552849
1192, 1201
Temp(degC) = , 100.121948
1193, 1201
Temp(degC) = , 99.552849
1192, 1201
Temp(degC) = , 100.121948
1192, 1201
Temp(degC) = , 100.121948
1192, 1201
Temp(degC) = , 100.121948
1191, 1201
Temp(degC) = , 100.691055
1190, 1201
Temp(degC) = , 101.260162
1190, 1201
Temp(degC) = , 101.260162
1189, 1201
Temp(degC) = , 101.829269
1190, 1201
Temp(degC) = , 101.260162
1189, 1201
Temp(degC) = , 101.829269
Tested and indeed works perfect. Tested now at panic set to 99 and when temp is reached a reset occurs and starts when temp is below 99. Here the temps after restart
Processor core temperature: 98.37°C
Processor core temperature: 97.69°C
Processor core temperature: 97.69°C
Processor core temperature: 97.02°C
Really great and thanks a lot...you made my day..