From f76ee9a6079fa2dc2a7b788f96aafd7381390b85 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 16 Sep 2020 23:31:49 +0200 Subject: [PATCH] separate adc and max vref --- src/channel_state.rs | 5 ++++- src/channels.rs | 3 +-- src/main.rs | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/channel_state.rs b/src/channel_state.rs index 586aae0..7cc5def 100644 --- a/src/channel_state.rs +++ b/src/channel_state.rs @@ -16,11 +16,13 @@ use crate::{ }; const R_INNER: f64 = 2.0 * 5100.0; +const VREF_SENS: f64 = 3.3 / 2.0; pub struct ChannelState { pub adc_data: Option, pub adc_calibration: ad7172::ChannelCalibration, pub adc_time: Instant, + /// VREF for the TEC (1.5V) pub vref: ElectricPotential, pub dac_value: ElectricPotential, pub pid_engaged: bool, @@ -62,8 +64,9 @@ impl ChannelState { /// Get `SENS[01]` input resistance pub fn get_sens(&self) -> Option { let r_inner = ElectricalResistance::new::(R_INNER); + let vref = ElectricPotential::new::(VREF_SENS); 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) } diff --git a/src/channels.rs b/src/channels.rs index c6ee771..02a6772 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -51,8 +51,7 @@ impl Channels { let pwm = pins.pwm; let mut channels = Channels { channel0, channel1, adc, pins_adc, pwm }; 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 diff --git a/src/main.rs b/src/main.rs index 0999bbd..d14fa84 100644 --- a/src/main.rs +++ b/src/main.rs @@ -170,11 +170,11 @@ fn main() -> ! { Command::Show(ShowCommand::Input) => { for channel in 0..CHANNELS { 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 itec = channels.read_itec(channel); - let tec_i = -(itec - ElectricPotential::new::(1.5)) / ElectricalResistance::new::(0.4); + let tec_i = (itec - vref) / ElectricalResistance::new::(0.4); let tec_u_meas = channels.read_tec_u_meas(channel);