Skip to content

Commit d6b6dc7

Browse files
committed
Implement temp calibration as 6-point calibration with linear fitting
1 parent 7db2145 commit d6b6dc7

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

AxxSolder_firmware/Core/Inc/main.h

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ typedef struct{
4747
double current_measurement;
4848
double startup_beep;
4949
double deg_celsius;
50+
double temp_cal_100;
51+
double temp_cal_200;
52+
double temp_cal_300;
53+
double temp_cal_350;
54+
double temp_cal_400;
55+
double temp_cal_450;
5056
}Flash_values;
5157

5258
/* USER CODE END Includes */

AxxSolder_firmware/Core/Src/main.c

+36-3
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,17 @@ Flash_values default_flash_values = {.startup_temperature = 330,
284284
.power_limit = 0,
285285
.current_measurement = 1,
286286
.startup_beep = 1,
287-
.deg_celsius = 1};
287+
.deg_celsius = 1,
288+
.temp_cal_100 = 100,
289+
.temp_cal_200 = 200,
290+
.temp_cal_300 = 300,
291+
.temp_cal_350 = 350,
292+
.temp_cal_400 = 400,
293+
.temp_cal_450 = 450};
288294

289295
/* List of names for settings menu */
290-
#define menu_length 17
291-
char menu_names[menu_length][22] = { "Startup Temp °C ",
296+
#define menu_length 23
297+
char menu_names[menu_length][28] = { "Startup Temp °C ",
292298
"Temp Offset °C ",
293299
"Standby Temp °C ",
294300
"Standby Time [min] ",
@@ -302,6 +308,12 @@ char menu_names[menu_length][22] = { "Startup Temp °C ",
302308
"I Measurement ",
303309
"Startup Beep ",
304310
"Temp in Celsius ",
311+
"Temp cal 100 ",
312+
"Temp cal 200 ",
313+
"Temp cal 300 ",
314+
"Temp cal 350 ",
315+
"Temp cal 400 ",
316+
"Temp cal 450 ",
305317
"-Load Default- ",
306318
"-Save and Reboot- ",
307319
"-Exit no Save- "};
@@ -478,6 +490,27 @@ void get_thermocouple_temperature(){
478490
else if(attached_handle == NT115){
479491
sensor_values.thermocouple_temperature = TC_temp*TC_temp*TC_COMPENSATION_X2_NT115 + TC_temp*TC_COMPENSATION_X1_NT115 + TC_COMPENSATION_X0_NT115;
480492
}
493+
494+
/*Adjust measured temperature to fit calibrated values */
495+
if(sensor_values.thermocouple_temperature < 100){
496+
sensor_values.thermocouple_temperature = sensor_values.thermocouple_temperature*(flash_values.temp_cal_100)/100;
497+
}
498+
else if(sensor_values.thermocouple_temperature < 200){
499+
sensor_values.thermocouple_temperature = (sensor_values.thermocouple_temperature - 100)*(flash_values.temp_cal_200-flash_values.temp_cal_100)/100 + flash_values.temp_cal_100;
500+
}
501+
else if(sensor_values.thermocouple_temperature < 300){
502+
sensor_values.thermocouple_temperature = (sensor_values.thermocouple_temperature - 200)*(flash_values.temp_cal_300-flash_values.temp_cal_200)/100 + flash_values.temp_cal_200;
503+
}
504+
else if(sensor_values.thermocouple_temperature < 350){
505+
sensor_values.thermocouple_temperature = (sensor_values.thermocouple_temperature - 300)*(flash_values.temp_cal_350-flash_values.temp_cal_300)/50 + flash_values.temp_cal_300;
506+
}
507+
else if(sensor_values.thermocouple_temperature < 400){
508+
sensor_values.thermocouple_temperature = (sensor_values.thermocouple_temperature - 350)*(flash_values.temp_cal_400-flash_values.temp_cal_350)/50 + flash_values.temp_cal_350;
509+
}
510+
else{
511+
sensor_values.thermocouple_temperature = (sensor_values.thermocouple_temperature - 400)*(flash_values.temp_cal_450-flash_values.temp_cal_400)/50 + flash_values.temp_cal_400;
512+
}
513+
481514
sensor_values.thermocouple_temperature += flash_values.temperature_offset; // Add temperature offset value
482515
sensor_values.thermocouple_temperature = clamp(sensor_values.thermocouple_temperature ,0 ,500); // Clamp
483516

0 commit comments

Comments
 (0)