Skip to content

Commit 8144a15

Browse files
committed
updated thermistor equation
1 parent 0e13f9d commit 8144a15

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Sensors/Core/Inc/lim.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
//Steinhart-Hart constants
1919
#define MAX_ADC_COUNT 4095U
2020
#define ABSOLUTE_ZERO 273.15
21-
#define NOMINAL_TEMPERATURE 25U
21+
#define NOMINAL_TEMPERATURE 298.15
2222
#define NOMINAL_RESISTANCE 10000U
2323
#define B_COEFFICIENT 3950U
2424

25-
#define VOLTAGE_SUPPLY 5U
25+
#define VOLTAGE_SUPPLY 5
26+
#define MAX_VOLTAGE 3.3
2627
#define R10K 10000U
2728

2829

Sensors/Core/Src/lim.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ void get_lim_data(uint8_t lim_temps[NUM_LIMS]) {
2929
}
3030

3131
uint8_t get_temp(uint16_t adc_value) {
32-
uint32_t voltage_in = adc_value * (VOLTAGE_SUPPLY / MAX_ADC_COUNT);
33-
uint32_t thermistor_resistance = voltage_in * R10K / (VOLTAGE_SUPPLY - voltage_in);
32+
uint32_t voltage_in = adc_value * (MAX_VOLTAGE / MAX_ADC_COUNT);
33+
uint32_t thermistor_resistance = (voltage_in * R10K) / (VOLTAGE_SUPPLY - voltage_in);
34+
35+
uint8_t temp_steinhart = -ABSOLUTE_ZERO + (NOMINAL_TEMPERATURE * B_COEFFICIENT)/(NOMINAL_TEMPERATURE
36+
* log(thermistor_resistance / R10K) + B_COEFFICIENT);
3437

35-
uint8_t temp_steinhart = -ABSOLUTE_ZERO + (1.0/((1.0/ (NOMINAL_TEMPERATURE + ABSOLUTE_ZERO)) + (log(thermistor_resistance / NOMINAL_RESISTANCE) / B_COEFFICIENT)));
3638
return temp_steinhart;
3739
}

0 commit comments

Comments
 (0)