Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flip divider resistance circuit for thermistors #90

Merged
merged 8 commits into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
taesungh marked this conversation as resolved.
Show resolved Hide resolved
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, 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()
}
Expand Down