- Modified some thermocouple functions to use f64 instead of f32

- Added thermistor
- Added resistive divider
This commit is contained in:
Zachary Sunforge
2024-07-07 18:57:59 -07:00
parent 403df6f5f4
commit 96ae59087e
7 changed files with 87 additions and 15 deletions

View File

@ -0,0 +1,33 @@
use libm::{log, logf};
use uom::si::electrical_resistance::ohm;
use uom::si::quantities::{ThermodynamicTemperature, ElectricalResistance};
use uom::si::thermodynamic_temperature::kelvin;
/// Convert thermistor resistance to a temperature using beta parameter equation
pub fn convert_beta(
resistance: ElectricalResistance<f32>,
beta: f32,
reference_temp: ThermodynamicTemperature<f32>,
reference_resist: ElectricalResistance<f32>,
) -> ThermodynamicTemperature<f32> {
let ohms = resistance.get::<ohm>();
let reference_kelvin = reference_temp.get::<kelvin>();
let reference_ohms = reference_resist.get::<ohm>();
let result_kelvin = 1.0 / ((1.0 / reference_kelvin) + (1.0 / beta) * logf(ohms / reference_ohms));
ThermodynamicTemperature::new::<kelvin>(result_kelvin)
}
/// Convert thermistor resistance to a temperature using Steinhart-Hart equation
pub fn convert_steinhart(
resistance: ElectricalResistance<f32>,
a: f64,
b: f64,
c: f64,
) -> ThermodynamicTemperature<f32> {
let ohms = resistance.get::<ohm>() as f64;
let log_omhs = log(ohms);
let kelvins = 1.0 / (a + b * log_omhs + c * log_omhs * log_omhs * log_omhs);
ThermodynamicTemperature::new::<kelvin>(kelvins as f32)
}