Compare commits

...

2 Commits

Author SHA1 Message Date
b3a6d16c3d steinhart_hart: Beta Parameter uom dimensions
The Beta Parameter is not dimensionless, and has unit kelvin.
Incorporate that into the type system.
2024-08-20 12:40:32 +08:00
c6040899dd ItecPin -> ITecPin 2024-08-12 13:02:22 +08:00
4 changed files with 16 additions and 12 deletions

View File

@ -24,7 +24,7 @@ pub struct Channel<C: ChannelPins> {
pub vref_meas: ElectricPotential, pub vref_meas: ElectricPotential,
pub shdn: C::Shdn, pub shdn: C::Shdn,
pub vref_pin: C::VRefPin, pub vref_pin: C::VRefPin,
pub itec_pin: C::ItecPin, pub itec_pin: C::ITecPin,
/// feedback from `dac` output /// feedback from `dac` output
pub dac_feedback_pin: C::DacFeedbackPin, pub dac_feedback_pin: C::DacFeedbackPin,
pub tec_u_meas_pin: C::TecUMeasPin, pub tec_u_meas_pin: C::TecUMeasPin,

View File

@ -34,11 +34,13 @@ use uom::{
ElectricPotential, ElectricPotential,
ElectricalResistance, ElectricalResistance,
ThermodynamicTemperature, ThermodynamicTemperature,
TemperatureInterval,
}, },
electric_current::ampere, electric_current::ampere,
electric_potential::volt, electric_potential::volt,
electrical_resistance::ohm, electrical_resistance::ohm,
thermodynamic_temperature::degree_celsius, thermodynamic_temperature::degree_celsius,
temperature_interval::kelvin,
}, },
}; };
@ -243,7 +245,7 @@ impl Handler {
use super::command_parser::ShParameter::*; use super::command_parser::ShParameter::*;
match parameter { match parameter {
T0 => sh.t0 = ThermodynamicTemperature::new::<degree_celsius>(value), T0 => sh.t0 = ThermodynamicTemperature::new::<degree_celsius>(value),
B => sh.b = value, B => sh.b = TemperatureInterval::new::<kelvin>(value),
R0 => sh.r0 = ElectricalResistance::new::<ohm>(value), R0 => sh.r0 = ElectricalResistance::new::<ohm>(value),
} }
send_line(socket, b"{}"); send_line(socket, b"{}");

View File

@ -61,7 +61,7 @@ pub trait ChannelPins {
type DacSync: OutputPin; type DacSync: OutputPin;
type Shdn: OutputPin; type Shdn: OutputPin;
type VRefPin; type VRefPin;
type ItecPin; type ITecPin;
type DacFeedbackPin; type DacFeedbackPin;
type TecUMeasPin; type TecUMeasPin;
} }
@ -76,7 +76,7 @@ impl ChannelPins for Channel0 {
type DacSync = PE4<Output<PushPull>>; type DacSync = PE4<Output<PushPull>>;
type Shdn = PE10<Output<PushPull>>; type Shdn = PE10<Output<PushPull>>;
type VRefPin = Channel0VRef; type VRefPin = Channel0VRef;
type ItecPin = PA6<Analog>; type ITecPin = PA6<Analog>;
type DacFeedbackPin = PA4<Analog>; type DacFeedbackPin = PA4<Analog>;
type TecUMeasPin = PC2<Analog>; type TecUMeasPin = PC2<Analog>;
} }
@ -91,7 +91,7 @@ impl ChannelPins for Channel1 {
type DacSync = PF6<Output<PushPull>>; type DacSync = PF6<Output<PushPull>>;
type Shdn = PE15<Output<PushPull>>; type Shdn = PE15<Output<PushPull>>;
type VRefPin = Channel1VRef; type VRefPin = Channel1VRef;
type ItecPin = PB0<Analog>; type ITecPin = PB0<Analog>;
type DacFeedbackPin = PA5<Analog>; type DacFeedbackPin = PA5<Analog>;
type TecUMeasPin = PC3<Analog>; type TecUMeasPin = PC3<Analog>;
} }
@ -108,7 +108,7 @@ pub struct ChannelPinSet<C: ChannelPins> {
pub dac_sync: C::DacSync, pub dac_sync: C::DacSync,
pub shdn: C::Shdn, pub shdn: C::Shdn,
pub vref_pin: C::VRefPin, pub vref_pin: C::VRefPin,
pub itec_pin: C::ItecPin, pub itec_pin: C::ITecPin,
pub dac_feedback_pin: C::DacFeedbackPin, pub dac_feedback_pin: C::DacFeedbackPin,
pub tec_u_meas_pin: C::TecUMeasPin, pub tec_u_meas_pin: C::TecUMeasPin,
} }

View File

@ -3,10 +3,12 @@ use uom::si::{
f64::{ f64::{
ElectricalResistance, ElectricalResistance,
ThermodynamicTemperature, ThermodynamicTemperature,
TemperatureInterval,
}, },
electrical_resistance::ohm, electrical_resistance::ohm,
ratio::ratio, ratio::ratio,
thermodynamic_temperature::{degree_celsius, kelvin}, thermodynamic_temperature::{degree_celsius, kelvin},
temperature_interval::kelvin as kelvin_interval,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -15,17 +17,17 @@ use serde::{Deserialize, Serialize};
pub struct Parameters { pub struct Parameters {
/// Base temperature /// Base temperature
pub t0: ThermodynamicTemperature, pub t0: ThermodynamicTemperature,
/// Base resistance /// Resistance at base temperature
pub r0: ElectricalResistance, pub r0: ElectricalResistance,
/// Beta /// Beta
pub b: f64, pub b: TemperatureInterval,
} }
impl Parameters { impl Parameters {
/// Perform the voltage to temperature conversion. /// Perform the resistance to temperature conversion.
pub fn get_temperature(&self, r: ElectricalResistance) -> ThermodynamicTemperature { pub fn get_temperature(&self, r: ElectricalResistance) -> ThermodynamicTemperature {
let inv_temp = 1.0 / self.t0.get::<kelvin>() + (r / self.r0).get::<ratio>().ln() / self.b; let temp = (self.t0.recip() + (r / self.r0).get::<ratio>().ln() / self.b).recip();
ThermodynamicTemperature::new::<kelvin>(1.0 / inv_temp) ThermodynamicTemperature::new::<kelvin>(temp.get::<kelvin_interval>())
} }
} }
@ -34,7 +36,7 @@ impl Default for Parameters {
Parameters { Parameters {
t0: ThermodynamicTemperature::new::<degree_celsius>(25.0), t0: ThermodynamicTemperature::new::<degree_celsius>(25.0),
r0: ElectricalResistance::new::<ohm>(10_000.0), r0: ElectricalResistance::new::<ohm>(10_000.0),
b: 3800.0, b: TemperatureInterval::new::<kelvin_interval>(3800.0),
} }
} }
} }