Fix get_center to use calibrated VREF

The reason get_center should not measure VREF on every call (via
read_vref), is that it introduces significant noise for current setpoint
values derived from this center point, which are user-supplied, and
should not depend on any measurement.

The stable value of VREF supplied by the startup calibrating routine in
calibrate_dac_value should be used instead.

Since that calibrating routine is the very thing that produces a
calibrated VREF, it should stop calling get_center, and use read_vref
directly.
atse 2023-08-21 12:55:31 +08:00
parent 6f0acc73b8
commit d68e6f16a0
2 changed files with 8 additions and 6 deletions

View File

@ -106,7 +106,7 @@ formatted as line-delimited JSON.
| `pwm <0/1> i_set <amp>` | Disengage PID, set fixed output current |
| `pwm <0/1> pid` | Let output current to be controlled by the PID |
| `center <0/1> <volt>` | 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 <deg_celsius>` | Set the PID controller target temperature |
| `pid <0/1> kp <value>` | Set proportional gain |

View File

@ -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::<volt>(center_point.into()),
@ -268,7 +270,7 @@ impl Channels {
let samples = 50;
let mut target_voltage = ElectricPotential::new::<volt>(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;