diff --git a/pod-operation/src/components/lim_temperature.rs b/pod-operation/src/components/lim_temperature.rs index 5e070e12..34df75dc 100644 --- a/pod-operation/src/components/lim_temperature.rs +++ b/pod-operation/src/components/lim_temperature.rs @@ -12,15 +12,14 @@ const C_TO_K_CONVERSION: f32 = 273.15; // connected to a thermistor, with the ADS1015 is measuring the node connecting // the two (a voltage divider circuit). -const DIVIDER_RESISTANCE: f32 = 22000.0; // Ohms +const DIVIDER_RESISTANCE: f32 = 1000.0; // Ohms const V_IN: f32 = 5.0; // Volts const BETA: f32 = 3950.0; // Kelvins const R_0: f32 = 10000.0; // Ohms const ROOM_TEMP: f32 = 25.0 + C_TO_K_CONVERSION; // Kelvins -fn voltage_to_temp(voltage: i16) -> f32 { - let voltage = f32::from(voltage) / 1000.0; - let thermistor_resistance = (voltage * DIVIDER_RESISTANCE) / (V_IN - voltage); +fn voltage_to_temp(voltage: f32) -> f32 { + let thermistor_resistance = ((V_IN - voltage) * DIVIDER_RESISTANCE) / voltage; let r_inf = R_0 * std::f32::consts::E.powf(-BETA / ROOM_TEMP); let temp_kelvins = BETA / (thermistor_resistance / r_inf).ln(); temp_kelvins - C_TO_K_CONVERSION @@ -43,7 +42,7 @@ impl LimTemperature { pub fn read_lim_temps(&mut self) -> (f32, f32, f32, f32) { [SingleA0, SingleA1, SingleA2, SingleA3] - .map(|channel| block!(self.ads1015.read(channel)).unwrap()) + .map(|channel| f32::from(block!(self.ads1015.read(channel)).unwrap()) / 1000.0) .map(voltage_to_temp) .into() }