Skip to content

Commit e9dea41

Browse files
Flip divider resistance circuit for thermistors (#90)
* updates * remove sleep time * fix imports * move conversion * chk * Fix compilation error * update -- tested * remove full scale, etc --------- Co-authored-by: Sam Der <[email protected]>
1 parent 84ab1b7 commit e9dea41

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

pod-operation/src/components/lim_temperature.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ const C_TO_K_CONVERSION: f32 = 273.15;
1212
// connected to a thermistor, with the ADS1015 is measuring the node connecting
1313
// the two (a voltage divider circuit).
1414

15-
const DIVIDER_RESISTANCE: f32 = 22000.0; // Ohms
15+
const DIVIDER_RESISTANCE: f32 = 1000.0; // Ohms
1616
const V_IN: f32 = 5.0; // Volts
1717
const BETA: f32 = 3950.0; // Kelvins
1818
const R_0: f32 = 10000.0; // Ohms
1919
const ROOM_TEMP: f32 = 25.0 + C_TO_K_CONVERSION; // Kelvins
2020

21-
fn voltage_to_temp(voltage: i16) -> f32 {
22-
let voltage = f32::from(voltage) / 1000.0;
23-
let thermistor_resistance = (voltage * DIVIDER_RESISTANCE) / (V_IN - voltage);
21+
fn voltage_to_temp(voltage: f32) -> f32 {
22+
let thermistor_resistance = ((V_IN - voltage) * DIVIDER_RESISTANCE) / voltage;
2423
let r_inf = R_0 * std::f32::consts::E.powf(-BETA / ROOM_TEMP);
2524
let temp_kelvins = BETA / (thermistor_resistance / r_inf).ln();
2625
temp_kelvins - C_TO_K_CONVERSION
@@ -43,7 +42,7 @@ impl LimTemperature {
4342

4443
pub fn read_lim_temps(&mut self) -> [f32; 4] {
4544
[SingleA0, SingleA1, SingleA2, SingleA3]
46-
.map(|channel| block!(self.ads1015.read(channel)).unwrap())
45+
.map(|channel| f32::from(block!(self.ads1015.read(channel)).unwrap()) / 1000.0)
4746
.map(voltage_to_temp)
4847
}
4948
}

0 commit comments

Comments
 (0)