diff --git a/README.md b/README.md index 88ed2ec..c3c8cd8 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ formatted as line-delimited JSON. | `pwm <0/1> i_set ` | Disengage PID, set fixed output current | | `pwm <0/1> pid` | Let output current to be controlled by the PID | | `center <0/1> ` | Set the MAX1968 0A-centerpoint to the specified fixed voltage | -| `center <0/1> vref` | Set the MAX1968 0A-centerpoint to measure from VREF | +| `center <0/1> vref` | Set the MAX1968 0A-centerpoint to a stable calibrated VREF | | `pid` | Show PID configuration | | `pid <0/1> target ` | Set the PID controller target temperature | | `pid <0/1> kp ` | Set proportional gain | diff --git a/src/channels.rs b/src/channels.rs index 3b70a6f..66ee00d 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -95,13 +95,15 @@ impl Channels { }) } - /// calculate the TEC i_set centerpoint + /// get the TEC i_set centerpoint pub fn get_center(&mut self, channel: usize) -> ElectricPotential { match self.channel_state(channel).center { CenterPoint::Vref => { - let vref = self.read_vref(channel); - self.channel_state(channel).vref = vref; - vref + match channel { + 0 => self.channel0.vref_meas, + 1 => self.channel1.vref_meas, + _ => unreachable!(), + } }, CenterPoint::Override(center_point) => ElectricPotential::new::(center_point.into()), @@ -268,7 +270,7 @@ impl Channels { let samples = 50; let mut target_voltage = ElectricPotential::new::(0.0); for _ in 0..samples { - target_voltage = target_voltage + self.get_center(channel); + target_voltage = target_voltage + self.read_vref(channel); } target_voltage = target_voltage / samples as f64; let mut start_value = 1;