Skip to content

Commit

Permalink
Flip divider resistance circuit for thermistors (#90)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
ryescholin and samderanova authored May 31, 2024
1 parent 84ab1b7 commit e9dea41
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pod-operation/src/components/lim_temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,7 +42,7 @@ impl LimTemperature {

pub fn read_lim_temps(&mut self) -> [f32; 4] {
[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)
}
}

0 comments on commit e9dea41

Please sign in to comment.