From c5943df788164d0d2c8e984f72af594542244403 Mon Sep 17 00:00:00 2001 From: Paul Fagerburg Date: Tue, 6 Aug 2019 14:43:55 -0600 Subject: thermistor: update Steinhart-Hart equations Add support for 30.9K pull-up on resistor divider with the 47K thermistor. BRANCH=none BUG=b:124316213 TEST=Rebuild EC and flash Change-Id: I5bc72fa67549ab15c0e4e1b0291eb934990ee61b Signed-off-by: Paul Fagerburg Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1742914 Reviewed-by: Scott Collyer Reviewed-by: Jett Rink --- driver/temp_sensor/thermistor.c | 36 +++++++++++++++++++++++++++++++++++- driver/temp_sensor/thermistor.h | 18 ++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) (limited to 'driver') diff --git a/driver/temp_sensor/thermistor.c b/driver/temp_sensor/thermistor.c index 25ff819321..dab0e985ce 100644 --- a/driver/temp_sensor/thermistor.c +++ b/driver/temp_sensor/thermistor.c @@ -66,7 +66,8 @@ int thermistor_linear_interpolate(uint16_t mv, #if defined(CONFIG_STEINHART_HART_3V3_51K1_47K_4050B) || \ defined(CONFIG_STEINHART_HART_3V3_13K7_47K_4050B) || \ defined(CONFIG_STEINHART_HART_6V0_51K1_47K_4050B) || \ - defined(CONFIG_STEINHART_HART_3V0_22K6_47K_4050B) + defined(CONFIG_STEINHART_HART_3V0_22K6_47K_4050B) || \ + defined(CONFIG_STEINHART_HART_3V3_30K9_47K_4050B) static int thermistor_get_temperature(int idx_adc, int *temp_ptr, const struct thermistor_info *info) { @@ -233,3 +234,36 @@ int get_temp_3v0_22k6_47k_4050b(int idx_adc, int *temp_ptr) &thermistor_info_22_47); } #endif /* CONFIG_STEINHART_HART_3V0_22K6_47K_4050B */ + +#ifdef CONFIG_STEINHART_HART_3V3_30K9_47K_4050B +/* + * Data derived from Steinhart-Hart equation in a resistor divider circuit with + * Vdd=3000mV, R = 30.9Kohm, and thermistor (B = 4050, T0 = 298.15 K, nominal + * resistance (R0) = 47Kohm). + */ +#define THERMISTOR_SCALING_FACTOR_31_47 11 +static const struct thermistor_data_pair thermistor_data_31_47[] = { + { 2753 / THERMISTOR_SCALING_FACTOR_31_47, 0 }, + { 2487 / THERMISTOR_SCALING_FACTOR_31_47, 10 }, + { 2165 / THERMISTOR_SCALING_FACTOR_31_47, 20 }, + { 1813 / THERMISTOR_SCALING_FACTOR_31_47, 30 }, + { 1145 / THERMISTOR_SCALING_FACTOR_31_47, 50 }, + { 878 / THERMISTOR_SCALING_FACTOR_31_47, 60 }, + { 665 / THERMISTOR_SCALING_FACTOR_31_47, 70 }, + { 500 / THERMISTOR_SCALING_FACTOR_31_47, 80 }, + { 375 / THERMISTOR_SCALING_FACTOR_31_47, 90 }, + { 282 / THERMISTOR_SCALING_FACTOR_31_47, 100 }, +}; + +static const struct thermistor_info thermistor_info_31_47 = { + .scaling_factor = THERMISTOR_SCALING_FACTOR_31_47, + .num_pairs = ARRAY_SIZE(thermistor_data_31_47), + .data = thermistor_data_31_47, +}; + +int get_temp_3v3_30k9_47k_4050b(int idx_adc, int *temp_ptr) +{ + return thermistor_get_temperature(idx_adc, temp_ptr, + &thermistor_info_31_47); +} +#endif /* CONFIG_STEINHART_HART_3V3_30K9_47K_4050B */ diff --git a/driver/temp_sensor/thermistor.h b/driver/temp_sensor/thermistor.h index 5ba338f40f..7ebe2b42ac 100644 --- a/driver/temp_sensor/thermistor.h +++ b/driver/temp_sensor/thermistor.h @@ -129,4 +129,22 @@ int get_temp_6v0_51k1_47k_4050b(int idx_adc, int *temp_ptr); int get_temp_3v0_22k6_47k_4050b(int idx_adc, int *temp_ptr); #endif +#ifdef CONFIG_STEINHART_HART_3V3_30K9_47K_4050B +/** + * Reads the specified ADC channel and uses a lookup table and interpolation to + * return a temperature in degrees K. + * + * The lookup table is based off of a resistor divider circuit on 3.3V with a + * 30.9K resistor in series with a thermistor with nominal value of 47K (at 25C) + * and a B (25/100) value of 4050. + * + * @param idx_adc The idx value from the temp_sensor_t struct, which is + * the ADC channel to read and convert to degrees K + * @param temp_ptr Destination for temperature (in degrees K) + * + * @return EC_SUCCESS, or non-zero if error. + */ +int get_temp_3v3_30k9_47k_4050b(int idx_adc, int *temp_ptr); +#endif + #endif /* __CROS_EC_TEMP_SENSOR_THERMISTOR_NCP15WB_H */ -- cgit v1.2.1