From 3067b356c541247145daab9f4861658a0659c700 Mon Sep 17 00:00:00 2001 From: topquark12 Date: Fri, 8 Jan 2021 16:18:20 +0800 Subject: [PATCH] channels: add methods to retrieve actual voltage and current of TEC --- src/channels.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/channels.rs b/src/channels.rs index d5ef47d..ccdf8f7 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -364,6 +364,16 @@ impl Channels { (duty * max, max) } + // Get actual current passing through TEC + pub fn get_tec_i(&mut self, channel: usize) -> ElectricCurrent { + (self.read_itec(channel) - self.read_vref(channel)) / ElectricalResistance::new::(0.4) + } + + // Get actual voltage across TEC + pub fn get_tec_v(&mut self, channel: usize) -> ElectricPotential { + (self.read_tec_u_meas(channel) - ElectricPotential::new::(1.5)) * 4.0 + } + fn set_pwm(&mut self, channel: usize, pin: PwmPin, duty: f64) -> f64 { fn set>(pin: &mut P, duty: f64) -> f64 { let max = pin.get_max_duty(); @@ -417,7 +427,7 @@ impl Channels { let vref = self.channel_state(channel).vref; let (i_set, _) = self.get_i(channel); let i_tec = self.read_itec(channel); - let tec_i = (i_tec - vref) / ElectricalResistance::new::(0.4); + let tec_i = self.get_tec_i(channel); let (dac_value, _) = self.get_dac(channel); let state = self.channel_state(channel); let pid_output = state.pid.last_output.map(|last_output| @@ -438,7 +448,7 @@ impl Channels { dac_feedback: self.read_dac_feedback(channel), i_tec, tec_i, - tec_u_meas: (self.read_tec_u_meas(channel) - ElectricPotential::new::(1.5)) * 4.0, + tec_u_meas: self.get_tec_v(channel), pid_output, } }