Compare commits

..

2 Commits

Author SHA1 Message Date
atse 7043974bb5 Make set_i use get_center again
This brings back the ability to override the center point for the
current setpoint.
2023-08-21 13:36:18 +08:00
atse d68e6f16a0 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.
2023-08-21 13:34:48 +08:00
3 changed files with 14 additions and 7 deletions

View File

@ -184,7 +184,7 @@ postfilter rate can be tuned with the `postfilter` command.
- Connect TEC module device 1 to TEC1- and TEC1+.
- The GND pin is for shielding not for sinking TEC module currents.
When using a TEC module with the Thermostat, the Thermostat expects the thermal load (where the thermistor is located) to cool down with a positive software current set point, and heat up with a negative current set point.
When using a TEC module with the Thermostat, the Thermostat expects the thermal load (where the thermistor is located) to heat up with a positive software current set point, and cool down with a negative current set point.
Testing heat flow direction with a low set current is recommended before installation of the TEC module.

View File

@ -1,13 +1,11 @@
use smoltcp::time::{Duration, Instant};
use uom::si::{
f64::{
ElectricCurrent,
ElectricPotential,
ElectricalResistance,
ThermodynamicTemperature,
Time,
},
electric_current::ampere,
electric_potential::volt,
electrical_resistance::ohm,
thermodynamic_temperature::degree_celsius,
@ -28,10 +26,11 @@ pub struct ChannelState {
pub adc_calibration: ad7172::ChannelCalibration,
pub adc_time: Instant,
pub adc_interval: Duration,
/// VREF for the TEC (1.5V)
pub vref: ElectricPotential,
/// i_set 0A center point
pub center: CenterPoint,
pub dac_value: ElectricPotential,
pub i_set: ElectricCurrent,
pub pid_engaged: bool,
pub pid: pid::Controller,
pub sh: sh::Parameters,
@ -45,9 +44,10 @@ impl ChannelState {
adc_time: Instant::from_secs(0),
// default: 10 Hz
adc_interval: Duration::from_millis(100),
// updated later with Channels.read_vref()
vref: ElectricPotential::new::<volt>(1.5),
center: CenterPoint::Vref,
dac_value: ElectricPotential::new::<volt>(0.0),
i_set: ElectricCurrent::new::<ampere>(0.0),
pid_engaged: false,
pid: pid::Controller::new(pid::Parameters::default()),
sh: sh::Parameters::default(),

View File

@ -58,6 +58,7 @@ impl Channels {
let pwm = pins.pwm;
let mut channels = Channels { channel0, channel1, adc, pins_adc, pwm };
for channel in 0..CHANNELS {
channels.channel_state(channel).vref = channels.read_vref(channel);
channels.calibrate_dac_value(channel);
channels.set_i(channel, ElectricCurrent::new::<ampere>(0.0));
}
@ -116,7 +117,11 @@ impl Channels {
}
pub fn get_i(&mut self, channel: usize) -> ElectricCurrent {
self.channel_state(channel).i_set
let center_point = self.get_center(channel);
let r_sense = ElectricalResistance::new::<ohm>(R_SENSE);
let voltage = self.get_dac(channel);
let i_tec = (voltage - center_point) / (10.0 * r_sense);
i_tec
}
/// i_set DAC
@ -137,7 +142,6 @@ impl Channels {
let voltage = i_tec * 10.0 * r_sense + center_point;
let voltage = self.set_dac(channel, voltage);
let i_tec = (voltage - center_point) / (10.0 * r_sense);
self.channel_state(channel).i_set = i_tec;
i_tec
}
@ -425,6 +429,7 @@ impl Channels {
}
fn report(&mut self, channel: usize) -> Report {
let vref = self.channel_state(channel).vref;
let i_set = self.get_i(channel);
let i_tec = self.read_itec(channel);
let tec_i = self.get_tec_i(channel);
@ -441,6 +446,7 @@ impl Channels {
.map(|temperature| temperature.get::<degree_celsius>()),
pid_engaged: state.pid_engaged,
i_set,
vref,
dac_value,
dac_feedback: self.read_dac_feedback(channel),
i_tec,
@ -538,6 +544,7 @@ pub struct Report {
temperature: Option<f64>,
pid_engaged: bool,
i_set: ElectricCurrent,
vref: ElectricPotential,
dac_value: ElectricPotential,
dac_feedback: ElectricPotential,
i_tec: ElectricPotential,