smaller temp calc
This commit is contained in:
parent
11d5ccb2d3
commit
29a48d22a7
@ -4,24 +4,15 @@
|
|||||||
#define NTC_B1 0.000300131f
|
#define NTC_B1 0.000300131f
|
||||||
#define NTC_C1 5.08516E-06f
|
#define NTC_C1 5.08516E-06f
|
||||||
#define NTC_D1 2.18765E-07f
|
#define NTC_D1 2.18765E-07f
|
||||||
#define NTC_R25 10000.0f // 10k ohm at 25C
|
|
||||||
|
|
||||||
#define NTC_R_DIVIDER 10000.0f
|
#define VREF 3000.0
|
||||||
#define NTC_V_DIVIDER 3.000f // 3V
|
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
// More efficient (?) calc using:
|
||||||
static inline float ntc_ohms_to_celsius(float ohms) {
|
// R_T = R_Pullup / (V_REF / ADC - 1)
|
||||||
float log_ohms = logf(ohms / NTC_R25);
|
// With R_T/R_0 and R_0 = R_T@25C
|
||||||
|
// R_T/R_0 = 1 / V_REF / ADC - 1
|
||||||
|
|
||||||
|
static inline int ntc_mv_to_celsius(int16_t adc) {
|
||||||
|
float log_ohms = logf(1/((VREF/adc)-1));
|
||||||
return 1.0f / (NTC_A1 + NTC_B1 * log_ohms + NTC_C1 * log_ohms * log_ohms + NTC_D1 * log_ohms * log_ohms * log_ohms) - 273.15f;
|
return 1.0f / (NTC_A1 + NTC_B1 * log_ohms + NTC_C1 * log_ohms * log_ohms + NTC_D1 * log_ohms * log_ohms * log_ohms) - 273.15f;
|
||||||
}
|
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
|
||||||
static inline float ohms_from_ntc_v(float v) {
|
|
||||||
return (NTC_R_DIVIDER * v) / (NTC_V_DIVIDER - v);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[maybe_unused]]
|
|
||||||
static int ntc_mv_to_celsius(int mv) {
|
|
||||||
float v = (float)mv * 0.001f;
|
|
||||||
return (int)ntc_ohms_to_celsius(ohms_from_ntc_v(v));
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user