forked from M-Labs/thermostat
Constants uom
This commit is contained in:
parent
c6040899dd
commit
9381feec1b
@ -1,13 +1,11 @@
|
|||||||
|
use core::marker::PhantomData;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use stm32f4xx_hal::hal::{
|
use stm32f4xx_hal::hal::{
|
||||||
blocking::spi::Transfer,
|
blocking::spi::Transfer,
|
||||||
digital::v2::OutputPin,
|
digital::v2::OutputPin,
|
||||||
};
|
};
|
||||||
use uom::si::{
|
use uom::si::f64::ElectricPotential;
|
||||||
f64::ElectricPotential,
|
|
||||||
electric_potential::volt,
|
|
||||||
};
|
|
||||||
use super::{
|
use super::{
|
||||||
regs::{self, Register, RegisterData},
|
regs::{self, Register, RegisterData},
|
||||||
checksum::{ChecksumMode, Checksum},
|
checksum::{ChecksumMode, Checksum},
|
||||||
@ -270,7 +268,11 @@ impl ChannelCalibration {
|
|||||||
let data = data + (self.offset as i32 - 0x80_0000) as f64;
|
let data = data + (self.offset as i32 - 0x80_0000) as f64;
|
||||||
let data = data / (2 << 23) as f64;
|
let data = data / (2 << 23) as f64;
|
||||||
|
|
||||||
const V_REF: f64 = 3.3;
|
const V_REF: ElectricPotential = ElectricPotential {
|
||||||
ElectricPotential::new::<volt>(data * V_REF / 0.75)
|
dimension: PhantomData,
|
||||||
|
units: PhantomData,
|
||||||
|
value: 3.3,
|
||||||
|
};
|
||||||
|
data * V_REF / 0.75
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
use smoltcp::time::{Duration, Instant};
|
use smoltcp::time::{Duration, Instant};
|
||||||
use uom::si::{
|
use uom::si::{
|
||||||
f64::{
|
f64::{
|
||||||
@ -9,7 +11,6 @@ use uom::si::{
|
|||||||
},
|
},
|
||||||
electric_potential::volt,
|
electric_potential::volt,
|
||||||
electric_current::ampere,
|
electric_current::ampere,
|
||||||
electrical_resistance::ohm,
|
|
||||||
thermodynamic_temperature::degree_celsius,
|
thermodynamic_temperature::degree_celsius,
|
||||||
time::millisecond,
|
time::millisecond,
|
||||||
};
|
};
|
||||||
@ -20,8 +21,16 @@ use crate::{
|
|||||||
command_parser::CenterPoint,
|
command_parser::CenterPoint,
|
||||||
};
|
};
|
||||||
|
|
||||||
const R_INNER: f64 = 2.0 * 5100.0;
|
const R_INNER: ElectricalResistance = ElectricalResistance {
|
||||||
const VREF_SENS: f64 = 3.3 / 2.0;
|
dimension: PhantomData,
|
||||||
|
units: PhantomData,
|
||||||
|
value: 2.0 * 5100.0,
|
||||||
|
};
|
||||||
|
const VREF_SENS: ElectricPotential = ElectricPotential {
|
||||||
|
dimension: PhantomData,
|
||||||
|
units: PhantomData,
|
||||||
|
value: 3.3 / 2.0,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct ChannelState {
|
pub struct ChannelState {
|
||||||
pub adc_data: Option<u32>,
|
pub adc_data: Option<u32>,
|
||||||
@ -87,10 +96,9 @@ impl ChannelState {
|
|||||||
|
|
||||||
/// Get `SENS[01]` input resistance
|
/// Get `SENS[01]` input resistance
|
||||||
pub fn get_sens(&self) -> Option<ElectricalResistance> {
|
pub fn get_sens(&self) -> Option<ElectricalResistance> {
|
||||||
let r_inner = ElectricalResistance::new::<ohm>(R_INNER);
|
let vref = VREF_SENS;
|
||||||
let vref = ElectricPotential::new::<volt>(VREF_SENS);
|
|
||||||
let adc_input = self.get_adc()?;
|
let adc_input = self.get_adc()?;
|
||||||
let r = r_inner * adc_input / (vref - adc_input);
|
let r = R_INNER * adc_input / (vref - adc_input);
|
||||||
Some(r)
|
Some(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,11 @@ pub enum PinsAdcReadTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub const CHANNELS: usize = 2;
|
pub const CHANNELS: usize = 2;
|
||||||
pub const R_SENSE: f64 = 0.05;
|
pub const R_SENSE: ElectricalResistance = ElectricalResistance {
|
||||||
|
dimension: PhantomData,
|
||||||
|
units: PhantomData,
|
||||||
|
value: 0.05,
|
||||||
|
};
|
||||||
|
|
||||||
// From design specs
|
// From design specs
|
||||||
pub const MAX_TEC_I: ElectricCurrent = ElectricCurrent {
|
pub const MAX_TEC_I: ElectricCurrent = ElectricCurrent {
|
||||||
@ -159,10 +163,9 @@ impl Channels {
|
|||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
let center_point = vref_meas;
|
let center_point = vref_meas;
|
||||||
let r_sense = ElectricalResistance::new::<ohm>(R_SENSE);
|
let voltage = i_set * 10.0 * R_SENSE + center_point;
|
||||||
let voltage = i_set * 10.0 * r_sense + center_point;
|
|
||||||
let voltage = self.set_dac(channel, voltage);
|
let voltage = self.set_dac(channel, voltage);
|
||||||
let i_set = (voltage - center_point) / (10.0 * r_sense);
|
let i_set = (voltage - center_point) / (10.0 * R_SENSE);
|
||||||
self.channel_state(channel).i_set = i_set;
|
self.channel_state(channel).i_set = i_set;
|
||||||
i_set
|
i_set
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user