forked from M-Labs/thermostat
Compare commits
1 Commits
master
...
uom-consta
Author | SHA1 | Date | |
---|---|---|---|
9381feec1b |
@ -1,13 +1,11 @@
|
||||
use core::marker::PhantomData;
|
||||
use core::fmt;
|
||||
use log::{info, warn};
|
||||
use stm32f4xx_hal::hal::{
|
||||
blocking::spi::Transfer,
|
||||
digital::v2::OutputPin,
|
||||
};
|
||||
use uom::si::{
|
||||
f64::ElectricPotential,
|
||||
electric_potential::volt,
|
||||
};
|
||||
use uom::si::f64::ElectricPotential;
|
||||
use super::{
|
||||
regs::{self, Register, RegisterData},
|
||||
checksum::{ChecksumMode, Checksum},
|
||||
@ -270,7 +268,11 @@ impl ChannelCalibration {
|
||||
let data = data + (self.offset as i32 - 0x80_0000) as f64;
|
||||
let data = data / (2 << 23) as f64;
|
||||
|
||||
const V_REF: f64 = 3.3;
|
||||
ElectricPotential::new::<volt>(data * V_REF / 0.75)
|
||||
const V_REF: ElectricPotential = ElectricPotential {
|
||||
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 uom::si::{
|
||||
f64::{
|
||||
@ -9,7 +11,6 @@ use uom::si::{
|
||||
},
|
||||
electric_potential::volt,
|
||||
electric_current::ampere,
|
||||
electrical_resistance::ohm,
|
||||
thermodynamic_temperature::degree_celsius,
|
||||
time::millisecond,
|
||||
};
|
||||
@ -20,8 +21,16 @@ use crate::{
|
||||
command_parser::CenterPoint,
|
||||
};
|
||||
|
||||
const R_INNER: f64 = 2.0 * 5100.0;
|
||||
const VREF_SENS: f64 = 3.3 / 2.0;
|
||||
const R_INNER: ElectricalResistance = ElectricalResistance {
|
||||
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 adc_data: Option<u32>,
|
||||
@ -87,10 +96,9 @@ impl ChannelState {
|
||||
|
||||
/// Get `SENS[01]` input resistance
|
||||
pub fn get_sens(&self) -> Option<ElectricalResistance> {
|
||||
let r_inner = ElectricalResistance::new::<ohm>(R_INNER);
|
||||
let vref = ElectricPotential::new::<volt>(VREF_SENS);
|
||||
let vref = VREF_SENS;
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,11 @@ pub enum PinsAdcReadTarget {
|
||||
}
|
||||
|
||||
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
|
||||
pub const MAX_TEC_I: ElectricCurrent = ElectricCurrent {
|
||||
@ -159,10 +163,9 @@ impl Channels {
|
||||
_ => unreachable!(),
|
||||
};
|
||||
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 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;
|
||||
i_set
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user