Compare commits
2 Commits
fc0ca8b581
...
dd06ae1075
Author | SHA1 | Date |
---|---|---|
Astro | dd06ae1075 | |
Astro | f76ee9a607 |
|
@ -16,11 +16,13 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
const R_INNER: f64 = 2.0 * 5100.0;
|
const R_INNER: f64 = 2.0 * 5100.0;
|
||||||
|
const VREF_SENS: f64 = 3.3 / 2.0;
|
||||||
|
|
||||||
pub struct ChannelState {
|
pub struct ChannelState {
|
||||||
pub adc_data: Option<u32>,
|
pub adc_data: Option<u32>,
|
||||||
pub adc_calibration: ad7172::ChannelCalibration,
|
pub adc_calibration: ad7172::ChannelCalibration,
|
||||||
pub adc_time: Instant,
|
pub adc_time: Instant,
|
||||||
|
/// VREF for the TEC (1.5V)
|
||||||
pub vref: ElectricPotential,
|
pub vref: ElectricPotential,
|
||||||
pub dac_value: ElectricPotential,
|
pub dac_value: ElectricPotential,
|
||||||
pub pid_engaged: bool,
|
pub pid_engaged: bool,
|
||||||
|
@ -62,8 +64,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 r_inner = ElectricalResistance::new::<ohm>(R_INNER);
|
||||||
|
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 / (self.vref - adc_input);
|
let r = r_inner * adc_input / (vref - adc_input);
|
||||||
Some(r)
|
Some(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,7 @@ impl Channels {
|
||||||
let pwm = pins.pwm;
|
let pwm = pins.pwm;
|
||||||
let mut channels = Channels { channel0, channel1, adc, pins_adc, pwm };
|
let mut channels = Channels { channel0, channel1, adc, pins_adc, pwm };
|
||||||
for channel in 0..CHANNELS {
|
for channel in 0..CHANNELS {
|
||||||
// FIXME: this reads 1.5 V instead of the expected 1.65 V.
|
channels.channel_state(channel).vref = channels.read_vref(channel);
|
||||||
// channels.channel_state(channel).vref = channels.read_vref(channel);
|
|
||||||
channels.calibrate_dac_value(channel);
|
channels.calibrate_dac_value(channel);
|
||||||
}
|
}
|
||||||
channels
|
channels
|
||||||
|
|
|
@ -170,17 +170,17 @@ fn main() -> ! {
|
||||||
Command::Show(ShowCommand::Input) => {
|
Command::Show(ShowCommand::Input) => {
|
||||||
for channel in 0..CHANNELS {
|
for channel in 0..CHANNELS {
|
||||||
if let Some(adc_input) = channels.channel_state(channel).get_adc() {
|
if let Some(adc_input) = channels.channel_state(channel).get_adc() {
|
||||||
let vref = channels.read_vref(channel);
|
let vref = channels.channel_state(channel).vref;
|
||||||
let dac_feedback = channels.read_dac_feedback(channel);
|
let dac_feedback = channels.read_dac_feedback(channel);
|
||||||
|
|
||||||
let itec = channels.read_itec(channel);
|
let itec = channels.read_itec(channel);
|
||||||
let tec_i = -(itec - ElectricPotential::new::<volt>(1.5)) / ElectricalResistance::new::<ohm>(0.4);
|
let tec_i = (itec - vref) / ElectricalResistance::new::<ohm>(0.4);
|
||||||
|
|
||||||
let tec_u_meas = channels.read_tec_u_meas(channel);
|
let tec_u_meas = channels.read_tec_u_meas(channel);
|
||||||
|
|
||||||
let state = channels.channel_state(channel);
|
let state = channels.channel_state(channel);
|
||||||
let _ = writeln!(
|
let _ = writeln!(
|
||||||
socket, "channel {}: t={} adc{}={} adc_r={} vref={} dac_feedback={} itec={} tec={} tec_u_meas={} r={:03}",
|
socket, "channel {}: t={:.0} adc{}={:.3} adc_r={:.3} vref={:.3} dac_feedback={:.3} itec={:.3} tec={:.3} tec_u_meas={:.3} r={:.3}",
|
||||||
channel, state.adc_time,
|
channel, state.adc_time,
|
||||||
channel, adc_input.into_format_args(volt, Abbreviation),
|
channel, adc_input.into_format_args(volt, Abbreviation),
|
||||||
state.get_sens().unwrap().into_format_args(ohm, Abbreviation),
|
state.get_sens().unwrap().into_format_args(ohm, Abbreviation),
|
||||||
|
@ -269,9 +269,10 @@ fn main() -> ! {
|
||||||
match (state.get_adc(), state.get_sens(), state.get_temperature()) {
|
match (state.get_adc(), state.get_sens(), state.get_temperature()) {
|
||||||
(Some(adc), Some(sens), Some(temp)) => {
|
(Some(adc), Some(sens), Some(temp)) => {
|
||||||
let _ = writeln!(
|
let _ = writeln!(
|
||||||
socket, "- adc={} r={} temp={:.3}K",
|
socket, "- adc={:.6} r={:.0} temp{}={:.3}K",
|
||||||
adc.into_format_args(volt, Abbreviation),
|
adc.into_format_args(volt, Abbreviation),
|
||||||
sens.into_format_args(ohm, Abbreviation),
|
sens.into_format_args(ohm, Abbreviation),
|
||||||
|
channel,
|
||||||
temp.into_format_args(degree_celsius, Abbreviation),
|
temp.into_format_args(degree_celsius, Abbreviation),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue