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.
This commit is contained in:
parent
6f0acc73b8
commit
d68e6f16a0
|
@ -106,7 +106,7 @@ formatted as line-delimited JSON.
|
||||||
| `pwm <0/1> i_set <amp>` | Disengage PID, set fixed output current |
|
| `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 |
|
| `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> <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` | Show PID configuration |
|
||||||
| `pid <0/1> target <deg_celsius>` | Set the PID controller target temperature |
|
| `pid <0/1> target <deg_celsius>` | Set the PID controller target temperature |
|
||||||
| `pid <0/1> kp <value>` | Set proportional gain |
|
| `pid <0/1> kp <value>` | Set proportional gain |
|
||||||
|
|
|
@ -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 {
|
pub fn get_center(&mut self, channel: usize) -> ElectricPotential {
|
||||||
match self.channel_state(channel).center {
|
match self.channel_state(channel).center {
|
||||||
CenterPoint::Vref => {
|
CenterPoint::Vref => {
|
||||||
let vref = self.read_vref(channel);
|
match channel {
|
||||||
self.channel_state(channel).vref = vref;
|
0 => self.channel0.vref_meas,
|
||||||
vref
|
1 => self.channel1.vref_meas,
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
CenterPoint::Override(center_point) =>
|
CenterPoint::Override(center_point) =>
|
||||||
ElectricPotential::new::<volt>(center_point.into()),
|
ElectricPotential::new::<volt>(center_point.into()),
|
||||||
|
@ -268,7 +270,7 @@ impl Channels {
|
||||||
let samples = 50;
|
let samples = 50;
|
||||||
let mut target_voltage = ElectricPotential::new::<volt>(0.0);
|
let mut target_voltage = ElectricPotential::new::<volt>(0.0);
|
||||||
for _ in 0..samples {
|
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;
|
target_voltage = target_voltage / samples as f64;
|
||||||
let mut start_value = 1;
|
let mut start_value = 1;
|
||||||
|
|
Loading…
Reference in New Issue