Configurable Thermistor (#13888)

This commit is contained in:
doggyfan
2019-05-07 00:51:06 +01:00
committed by Scott Lahteine
parent 172abc305b
commit 23a8707ef1
183 changed files with 4575 additions and 151 deletions

View File

@ -26,6 +26,7 @@
*/
#include "thermistor/thermistors.h"
#include "../inc/MarlinConfig.h"
#if ENABLED(AUTO_POWER_CONTROL)
@ -207,6 +208,53 @@ typedef struct { int16_t raw_min, raw_max; } raw_range_t;
typedef struct { int16_t mintemp, maxtemp; } celsius_range_t;
typedef struct { int16_t raw_min, raw_max, mintemp, maxtemp; } temp_range_t;
#define THERMISTOR_ADC_RESOLUTION 1024 // 10-bit ADC .. shame to waste 12-bits of resolution on 32-bit
#define THERMISTOR_ABS_ZERO_C -273.15f // bbbbrrrrr cold !
#define THERMISTOR_RESISTANCE_NOMINAL_C 25.0f // mmmmm comfortable
#if HAS_USER_THERMISTORS
enum CustomThermistorIndex : uint8_t {
#if ENABLED(HEATER_0_USER_THERMISTOR)
CTI_HOTEND_0,
#endif
#if ENABLED(HEATER_1_USER_THERMISTOR)
CTI_HOTEND_1,
#endif
#if ENABLED(HEATER_2_USER_THERMISTOR)
CTI_HOTEND_2,
#endif
#if ENABLED(HEATER_3_USER_THERMISTOR)
CTI_HOTEND_3,
#endif
#if ENABLED(HEATER_4_USER_THERMISTOR)
CTI_HOTEND_4,
#endif
#if ENABLED(HEATER_5_USER_THERMISTOR)
CTI_HOTEND_5,
#endif
#if ENABLED(BED_USER_THERMISTOR)
CTI_BED,
#endif
#if ENABLED(CHAMBER_USER_THERMISTOR)
CTI_CHAMBER,
#endif
USER_THERMISTORS
};
// User-defined thermistor
typedef struct {
bool pre_calc; // true if pre-calculations update needed
float sh_c_coeff, // Steinhart-Hart C coefficient .. defaults to '0.0'
sh_alpha,
series_res,
res_25, res_25_recip,
res_25_log,
beta, beta_recip;
} user_thermistor_t;
#endif
class Temperature {
public:
@ -363,6 +411,38 @@ class Temperature {
/**
* Static (class) methods
*/
#if HAS_USER_THERMISTORS
static user_thermistor_t user_thermistor[USER_THERMISTORS];
static void log_user_thermistor(const uint8_t t_index, const bool eprom=false);
static void reset_user_thermistors();
static float user_thermistor_to_deg_c(const uint8_t t_index, const int raw);
static bool set_pull_up_res(int8_t t_index, float value) {
//if (!WITHIN(t_index, 0, USER_THERMISTORS - 1)) return false;
if (!WITHIN(value, 1, 1000000)) return false;
user_thermistor[t_index].series_res = value;
return true;
}
static bool set_res25(int8_t t_index, float value) {
if (!WITHIN(value, 1, 10000000)) return false;
user_thermistor[t_index].res_25 = value;
user_thermistor[t_index].pre_calc = true;
return true;
}
static bool set_beta(int8_t t_index, float value) {
if (!WITHIN(value, 1, 1000000)) return false;
user_thermistor[t_index].beta = value;
user_thermistor[t_index].pre_calc = true;
return true;
}
static bool set_sh_coeff(int8_t t_index, float value) {
if (!WITHIN(value, -0.01f, 0.01f)) return false;
user_thermistor[t_index].sh_c_coeff = value;
user_thermistor[t_index].pre_calc = true;
return true;
}
#endif
static float analog_to_celsius_hotend(const int raw, const uint8_t e);
#if HAS_HEATED_BED