2024-02-06 15:20:23 +08:00
|
|
|
use core::f64::NAN;
|
2024-01-04 17:13:46 +08:00
|
|
|
use core::marker::PhantomData;
|
2024-02-06 15:20:23 +08:00
|
|
|
use crate::sys_timer;
|
2023-12-21 13:13:06 +08:00
|
|
|
use crate::thermostat::ad5680;
|
2024-01-04 17:13:46 +08:00
|
|
|
use crate::thermostat::max1968::{MAX1968, AdcReadTarget, PwmPinsEnum};
|
2024-01-17 16:06:07 +08:00
|
|
|
use crate::thermostat::ad7172;
|
2024-02-06 15:20:23 +08:00
|
|
|
use crate::thermostat::pid_state::{PidState, PidSettings};
|
2024-01-17 17:01:25 +08:00
|
|
|
use crate::thermostat::steinhart_hart;
|
2024-02-21 15:49:08 +08:00
|
|
|
use crate::thermostat::temp_mon::{TempMon, TempStatus, TempMonSettings};
|
2024-02-15 10:37:45 +08:00
|
|
|
use serde::{Deserialize, Serialize};
|
2024-02-01 15:49:41 +08:00
|
|
|
use log::debug;
|
2023-12-22 17:09:45 +08:00
|
|
|
use uom::si::{
|
|
|
|
electric_current::ampere,
|
2024-01-05 15:00:50 +08:00
|
|
|
electric_potential::volt,
|
2023-12-22 17:09:45 +08:00
|
|
|
electrical_resistance::ohm,
|
2024-02-06 15:20:23 +08:00
|
|
|
thermodynamic_temperature::degree_celsius,
|
|
|
|
f64::{ThermodynamicTemperature, ElectricCurrent, ElectricPotential, ElectricalResistance},
|
2023-12-22 17:09:45 +08:00
|
|
|
ratio::ratio,
|
|
|
|
};
|
2024-02-02 14:07:25 +08:00
|
|
|
use miniconf::Tree;
|
2023-12-21 13:13:06 +08:00
|
|
|
|
2024-02-15 11:00:53 +08:00
|
|
|
use super::pid_state;
|
|
|
|
|
2024-01-04 17:13:46 +08:00
|
|
|
pub const R_SENSE: ElectricalResistance = ElectricalResistance {
|
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
|
|
|
value: 0.05,
|
|
|
|
};
|
|
|
|
|
2024-02-02 14:07:25 +08:00
|
|
|
#[derive(Clone, Debug, Tree)]
|
2024-01-18 15:14:24 +08:00
|
|
|
pub struct TecSettings {
|
2024-01-05 15:00:50 +08:00
|
|
|
pub center_pt: ElectricPotential,
|
|
|
|
pub max_v_set: ElectricPotential,
|
|
|
|
pub max_i_pos_set: ElectricCurrent,
|
|
|
|
pub max_i_neg_set: ElectricCurrent,
|
|
|
|
pub i_set: ElectricCurrent,
|
|
|
|
}
|
2024-01-04 17:13:46 +08:00
|
|
|
|
2024-01-18 15:14:24 +08:00
|
|
|
impl TecSettings{
|
2024-01-05 15:00:50 +08:00
|
|
|
pub const DAC_OUT_V_MAX: ElectricPotential = ElectricPotential {
|
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
2024-01-24 12:25:45 +08:00
|
|
|
value: 3.0,
|
2024-01-05 15:00:50 +08:00
|
|
|
};
|
|
|
|
pub const TEC_VSEC_BIAS_V: ElectricPotential = ElectricPotential {
|
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
|
|
|
value: 1.65,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Kirdy Design Specs:
|
|
|
|
// MaxV = 5.0V
|
|
|
|
// MAX Current = +- 1.0A
|
2024-01-18 15:14:24 +08:00
|
|
|
const MAX_I_SET : ElectricCurrent = ElectricCurrent {
|
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
|
|
|
value: 1.0,
|
|
|
|
};
|
2024-01-05 15:00:50 +08:00
|
|
|
const MAX_V_DUTY_TO_CURRENT_RATE: ElectricPotential = ElectricPotential {
|
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
|
|
|
value: 4.0 * 3.3,
|
|
|
|
};
|
|
|
|
pub const MAX_V_MAX: ElectricPotential = ElectricPotential {
|
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
|
|
|
value: 5.0,
|
|
|
|
};
|
2024-01-18 15:14:24 +08:00
|
|
|
const MAX_V_DUTY_MAX: f64 = TecSettings::MAX_V_MAX.value / TecSettings::MAX_V_DUTY_TO_CURRENT_RATE.value;
|
2024-01-05 15:00:50 +08:00
|
|
|
const MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE: ElectricCurrent = ElectricCurrent {
|
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
|
|
|
value: 1.0 / (10.0 * R_SENSE.value / 3.3),
|
|
|
|
};
|
|
|
|
pub const MAX_I_POS_CURRENT: ElectricCurrent = ElectricCurrent {
|
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
|
|
|
value: 1.0,
|
|
|
|
};
|
|
|
|
pub const MAX_I_NEG_CURRENT: ElectricCurrent = ElectricCurrent {
|
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
|
|
|
value: 1.0,
|
|
|
|
};
|
|
|
|
// .get::<ratio>() is not implemented for const
|
2024-01-18 15:14:24 +08:00
|
|
|
const MAX_I_POS_DUTY_MAX: f64 = TecSettings::MAX_I_POS_CURRENT.value / TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE.value;
|
|
|
|
const MAX_I_NEG_DUTY_MAX: f64 = TecSettings::MAX_I_NEG_CURRENT.value / TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE.value;
|
2024-01-05 15:00:50 +08:00
|
|
|
}
|
|
|
|
|
2024-01-18 15:14:24 +08:00
|
|
|
impl Default for TecSettings {
|
2024-01-05 15:00:50 +08:00
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
center_pt: ElectricPotential::new::<volt>(1.5),
|
|
|
|
max_v_set: ElectricPotential::new::<volt>(5.0),
|
|
|
|
max_i_pos_set: ElectricCurrent::new::<ampere>(1.0),
|
|
|
|
max_i_neg_set: ElectricCurrent::new::<ampere>(1.0),
|
|
|
|
i_set: ElectricCurrent::new::<ampere>(0.0),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-04 17:13:46 +08:00
|
|
|
|
2023-12-21 13:13:06 +08:00
|
|
|
pub struct Thermostat {
|
|
|
|
max1968: MAX1968,
|
2024-01-17 16:06:07 +08:00
|
|
|
ad7172: ad7172::AdcPhy,
|
2024-01-18 15:14:24 +08:00
|
|
|
pub tec_setting: TecSettings,
|
2024-01-17 17:01:25 +08:00
|
|
|
pid_ctrl_ch0: PidState,
|
2024-02-21 15:49:08 +08:00
|
|
|
temp_mon: TempMon,
|
2023-12-21 13:13:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Thermostat{
|
2024-01-17 16:06:07 +08:00
|
|
|
pub fn new (max1968: MAX1968, ad7172: ad7172::AdcPhy) -> Self {
|
2023-12-21 13:13:06 +08:00
|
|
|
Thermostat{
|
2024-01-05 15:00:50 +08:00
|
|
|
max1968: max1968,
|
2024-01-17 16:06:07 +08:00
|
|
|
ad7172: ad7172,
|
2024-01-18 15:14:24 +08:00
|
|
|
tec_setting: TecSettings::default(),
|
2024-01-17 17:01:25 +08:00
|
|
|
pid_ctrl_ch0: PidState::default(),
|
2024-02-21 15:49:08 +08:00
|
|
|
temp_mon: TempMon::default(),
|
2023-12-21 13:13:06 +08:00
|
|
|
}
|
|
|
|
}
|
2024-01-17 16:06:07 +08:00
|
|
|
pub fn setup(&mut self){
|
|
|
|
self.tec_setup();
|
|
|
|
let t_adc_ch0_cal = self.t_adc_setup();
|
2024-02-06 15:20:23 +08:00
|
|
|
self.pid_ctrl_ch0.set_adc_calibration(t_adc_ch0_cal) ;
|
2024-01-17 16:06:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn tec_setup(&mut self) {
|
2024-01-09 16:58:17 +08:00
|
|
|
self.power_down();
|
2024-01-04 17:13:46 +08:00
|
|
|
|
2024-01-18 15:14:24 +08:00
|
|
|
self.tec_setting = TecSettings::default();
|
2024-01-04 17:13:46 +08:00
|
|
|
|
2024-01-05 15:00:50 +08:00
|
|
|
self.set_i(self.tec_setting.i_set);
|
2024-01-04 17:13:46 +08:00
|
|
|
|
2024-01-05 15:00:50 +08:00
|
|
|
self.set_max_v(self.tec_setting.max_v_set);
|
|
|
|
self.set_max_i_pos(self.tec_setting.max_i_pos_set);
|
|
|
|
self.set_max_i_neg(self.tec_setting.max_i_neg_set);
|
2024-01-04 17:13:46 +08:00
|
|
|
}
|
|
|
|
|
2024-01-17 16:06:07 +08:00
|
|
|
fn t_adc_setup(&mut self)->ad7172::ChannelCalibration{
|
|
|
|
self.ad7172.set_sync_enable(false).unwrap();
|
|
|
|
self.ad7172.setup_channel(0, ad7172::Input::Ain0, ad7172::Input::Ain1).unwrap();
|
|
|
|
let adc_calibration0 = self.ad7172.get_calibration(0)
|
|
|
|
.expect("adc_calibration0");
|
|
|
|
self.ad7172.start_continuous_conversion().unwrap();
|
|
|
|
adc_calibration0
|
|
|
|
}
|
|
|
|
|
2024-02-06 15:20:23 +08:00
|
|
|
pub fn poll_adc_and_update_pid(&mut self) -> bool {
|
2024-02-15 11:00:53 +08:00
|
|
|
let mut data_rdy = false;
|
2024-02-06 15:20:23 +08:00
|
|
|
self.ad7172.data_ready().unwrap().map(|_ch| {
|
2024-01-17 16:06:07 +08:00
|
|
|
let data = self.ad7172.read_data().unwrap();
|
2024-01-17 17:01:25 +08:00
|
|
|
let state: &mut PidState = &mut self.pid_ctrl_ch0;
|
2024-02-06 15:20:23 +08:00
|
|
|
state.update(data);
|
|
|
|
debug!("state.get_pid_engaged(): {:?}", state.get_pid_engaged());
|
2024-02-21 15:49:08 +08:00
|
|
|
let pid_engaged = state.get_pid_engaged();
|
|
|
|
if pid_engaged {
|
2024-02-06 15:20:23 +08:00
|
|
|
match state.update_pid() {
|
|
|
|
Some(pid_output) => {
|
|
|
|
self.set_i(ElectricCurrent::new::<ampere>(pid_output));
|
|
|
|
debug!("Temperature Set Point: {:?} degree", self.pid_ctrl_ch0.get_pid_setpoint().get::<degree_celsius>());
|
|
|
|
}
|
|
|
|
None => { }
|
2024-01-17 16:06:07 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-21 15:49:08 +08:00
|
|
|
let temp = self.get_temperature();
|
|
|
|
self.temp_mon.update_status(pid_engaged, temp);
|
|
|
|
debug!("Temperature: {:?} degree", temp.get::<degree_celsius>());
|
2024-02-15 11:00:53 +08:00
|
|
|
data_rdy = true;
|
2024-02-06 15:20:23 +08:00
|
|
|
});
|
2024-02-15 11:00:53 +08:00
|
|
|
data_rdy
|
2024-01-17 16:06:07 +08:00
|
|
|
}
|
|
|
|
|
2024-02-21 15:49:08 +08:00
|
|
|
pub fn get_temp_mon_status(&mut self) -> TempStatus {
|
|
|
|
self.temp_mon.get_status()
|
|
|
|
}
|
|
|
|
|
2024-01-04 17:13:46 +08:00
|
|
|
pub fn power_up(&mut self){
|
|
|
|
self.max1968.power_up();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn power_down(&mut self){
|
|
|
|
self.max1968.power_down();
|
2024-02-06 15:20:23 +08:00
|
|
|
self.pid_ctrl_ch0.reset_pid_state();
|
|
|
|
self.set_i(ElectricCurrent::new::<ampere>(0.0));
|
2024-01-04 17:13:46 +08:00
|
|
|
}
|
|
|
|
|
2024-01-05 15:00:50 +08:00
|
|
|
fn set_center_pt(&mut self, value: ElectricPotential){
|
|
|
|
self.tec_setting.center_pt = value;
|
|
|
|
}
|
|
|
|
|
2024-01-04 17:13:46 +08:00
|
|
|
pub fn set_i(&mut self, i_tec: ElectricCurrent) -> ElectricCurrent {
|
2024-01-05 15:00:50 +08:00
|
|
|
let voltage = i_tec * 10.0 * R_SENSE + self.tec_setting.center_pt;
|
2024-01-18 15:14:24 +08:00
|
|
|
let voltage = self.max1968.set_dac(voltage, TecSettings::DAC_OUT_V_MAX);
|
2024-01-05 15:00:50 +08:00
|
|
|
self.tec_setting.i_set = (voltage - self.tec_setting.center_pt) / (10.0 * R_SENSE);
|
|
|
|
self.tec_setting.i_set
|
2024-01-04 17:13:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_max_v(&mut self, max_v: ElectricPotential) -> ElectricPotential {
|
2024-01-18 15:14:24 +08:00
|
|
|
let duty = (max_v / TecSettings::MAX_V_DUTY_TO_CURRENT_RATE).get::<ratio>();
|
|
|
|
let duty = self.max1968.set_pwm(PwmPinsEnum::MaxV, duty, TecSettings::MAX_V_DUTY_MAX);
|
|
|
|
self.tec_setting.max_v_set = duty * TecSettings::MAX_V_DUTY_TO_CURRENT_RATE;
|
2024-01-05 15:00:50 +08:00
|
|
|
self.tec_setting.max_v_set
|
2024-01-04 17:13:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_max_i_pos(&mut self, max_i_pos: ElectricCurrent) -> ElectricCurrent {
|
2024-01-18 15:14:24 +08:00
|
|
|
let duty = (max_i_pos / TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE).get::<ratio>();
|
|
|
|
let duty = self.max1968.set_pwm(PwmPinsEnum::MaxPosI, duty, TecSettings::MAX_I_POS_DUTY_MAX);
|
|
|
|
self.tec_setting.max_i_pos_set = duty * TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE;
|
2024-01-05 15:00:50 +08:00
|
|
|
self.tec_setting.max_i_pos_set
|
2024-01-04 17:13:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_max_i_neg(&mut self, max_i_neg: ElectricCurrent) -> ElectricCurrent {
|
2024-01-18 15:14:24 +08:00
|
|
|
let duty = (max_i_neg / TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE).get::<ratio>();
|
|
|
|
let duty = self.max1968.set_pwm(PwmPinsEnum::MaxNegI, duty, TecSettings::MAX_I_NEG_DUTY_MAX);
|
|
|
|
self.tec_setting.max_i_neg_set = duty * TecSettings::MAX_I_POS_NEG_DUTY_TO_CURRENT_RATE;
|
2024-01-05 15:00:50 +08:00
|
|
|
self.tec_setting.max_i_neg_set
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_dac_vfb(&mut self) -> ElectricPotential {
|
|
|
|
self.max1968.adc_read(AdcReadTarget::DacVfb, 16)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_vref(&mut self) -> ElectricPotential {
|
|
|
|
self.max1968.adc_read(AdcReadTarget::VREF, 16)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_tec_i(&mut self) -> ElectricCurrent {
|
|
|
|
let vref = self.get_vref();
|
|
|
|
(self.max1968.adc_read(AdcReadTarget::ITec, 16) - vref) / ElectricalResistance::new::<ohm>(0.4)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_tec_v(&mut self) -> ElectricPotential {
|
2024-01-24 12:25:45 +08:00
|
|
|
(self.max1968.adc_read(AdcReadTarget::VTec, 16) - TecSettings::TEC_VSEC_BIAS_V) * 4.0
|
2023-12-21 13:13:06 +08:00
|
|
|
}
|
2023-12-22 17:09:45 +08:00
|
|
|
|
|
|
|
/// Calibrates the DAC output to match vref of the MAX driver to reduce zero-current offset of the MAX driver output.
|
|
|
|
///
|
|
|
|
/// The thermostat DAC applies a control voltage signal to the CTLI pin of MAX driver chip to control its output current.
|
|
|
|
/// The CTLI input signal is centered around VREF of the MAX chip. Applying VREF to CTLI sets the output current to 0.
|
|
|
|
///
|
|
|
|
/// This calibration routine measures the VREF voltage and the DAC output with the STM32 ADC, and uses a breadth-first
|
|
|
|
/// search to find the DAC setting that will produce a DAC output voltage closest to VREF. This DAC output voltage will
|
|
|
|
/// be stored and used in subsequent i_set routines to bias the current control signal to the measured VREF, reducing
|
|
|
|
/// the offset error of the current control signal.
|
|
|
|
///
|
|
|
|
/// The input offset of the STM32 ADC is eliminated by using the same ADC for the measurements, and by only using the
|
|
|
|
/// difference in VREF and DAC output for the calibration.
|
|
|
|
///
|
|
|
|
/// This routine should be called only once after boot, repeated reading of the vref signal and changing of the stored
|
|
|
|
/// VREF measurement can introduce significant noise at the current output, degrading the stabilily performance of the
|
|
|
|
/// thermostat.
|
|
|
|
pub fn calibrate_dac_value(&mut self) {
|
2024-02-01 15:49:41 +08:00
|
|
|
const STEPS: i32 = 18;
|
2024-01-05 15:00:50 +08:00
|
|
|
let target_voltage = self.max1968.adc_read(AdcReadTarget::VREF, 64);
|
2023-12-22 17:09:45 +08:00
|
|
|
let mut start_value = 1;
|
|
|
|
let mut best_error = ElectricPotential::new::<volt>(100.0);
|
2024-02-01 15:49:41 +08:00
|
|
|
for step in (0..STEPS).rev() {
|
|
|
|
debug!("TEC VREF Calibrating: Step {}/{}", step, STEPS);
|
2023-12-22 17:09:45 +08:00
|
|
|
let mut prev_value = start_value;
|
|
|
|
for value in (start_value..=ad5680::MAX_VALUE).step_by(1 << step) {
|
|
|
|
self.max1968.phy.dac.set(value).unwrap();
|
|
|
|
sys_timer::sleep(5);
|
|
|
|
|
|
|
|
let dac_feedback = self.max1968.adc_read(AdcReadTarget::DacVfb, 64);
|
|
|
|
let error = target_voltage - dac_feedback;
|
|
|
|
if error < ElectricPotential::new::<volt>(0.0) {
|
|
|
|
break;
|
|
|
|
} else if error < best_error {
|
|
|
|
best_error = error;
|
|
|
|
start_value = prev_value;
|
|
|
|
|
2024-01-18 15:14:24 +08:00
|
|
|
let vref = (value as f64 / ad5680::MAX_VALUE as f64) * TecSettings::DAC_OUT_V_MAX;
|
2024-01-05 15:00:50 +08:00
|
|
|
self.set_center_pt(vref);
|
2023-12-22 17:09:45 +08:00
|
|
|
}
|
|
|
|
prev_value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-06 15:20:23 +08:00
|
|
|
pub fn set_pid_engaged(&mut self, val: bool) {
|
|
|
|
self.pid_ctrl_ch0.set_pid_engaged(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_pid_engaged(&mut self) -> bool {
|
|
|
|
self.pid_ctrl_ch0.get_pid_engaged()
|
2024-01-17 16:06:07 +08:00
|
|
|
}
|
|
|
|
|
2024-01-18 15:14:24 +08:00
|
|
|
pub fn get_status_report(&mut self) -> StatusReport {
|
|
|
|
StatusReport {
|
2024-02-15 10:37:45 +08:00
|
|
|
ts: sys_timer::now(),
|
2024-02-06 15:20:23 +08:00
|
|
|
pid_engaged: self.get_pid_engaged(),
|
2024-02-21 15:49:08 +08:00
|
|
|
temp_mon_status: self.temp_mon.get_status(),
|
2024-01-18 15:14:24 +08:00
|
|
|
temperature: self.pid_ctrl_ch0.get_temperature(),
|
|
|
|
i_set: self.tec_setting.i_set,
|
|
|
|
tec_i: self.get_tec_i(),
|
|
|
|
tec_v: self.get_tec_v(),
|
|
|
|
tec_vref: self.get_vref(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-06 15:20:23 +08:00
|
|
|
pub fn get_temperature(&mut self) -> ThermodynamicTemperature {
|
|
|
|
match self.pid_ctrl_ch0.get_temperature() {
|
|
|
|
Some(val) => {
|
|
|
|
val
|
|
|
|
}
|
|
|
|
None => { ThermodynamicTemperature::new::<degree_celsius>(NAN) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-15 11:00:53 +08:00
|
|
|
pub fn get_pid_settings(&mut self) -> pid_state::Parameters {
|
2024-02-06 15:20:23 +08:00
|
|
|
self.pid_ctrl_ch0.get_pid_settings()
|
2024-01-18 15:14:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_steinhart_hart(&mut self) -> steinhart_hart::Parameters {
|
2024-02-06 15:20:23 +08:00
|
|
|
self.pid_ctrl_ch0.get_sh()
|
2024-01-18 15:14:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_tec_settings(&mut self) -> TecSettingSummary {
|
|
|
|
TecSettingSummary {
|
|
|
|
center_point: self.tec_setting.center_pt,
|
|
|
|
i_set: TecSettingsSummaryField { value: self.tec_setting.i_set, max: TecSettings::MAX_I_SET },
|
|
|
|
max_v: TecSettingsSummaryField { value: self.tec_setting.max_v_set, max: TecSettings::MAX_V_MAX },
|
|
|
|
max_i_pos: TecSettingsSummaryField { value: self.tec_setting.max_i_pos_set, max: TecSettings::MAX_I_POS_CURRENT },
|
|
|
|
max_i_neg: TecSettingsSummaryField { value: self.tec_setting.max_i_neg_set, max: TecSettings::MAX_I_NEG_CURRENT },
|
|
|
|
}
|
|
|
|
}
|
2024-01-22 12:24:19 +08:00
|
|
|
|
|
|
|
pub fn get_calibrated_vdda(&mut self) -> u32 {
|
|
|
|
self.max1968.get_calibrated_vdda()
|
|
|
|
}
|
|
|
|
|
2024-02-06 15:20:23 +08:00
|
|
|
pub fn set_pid(&mut self, param: PidSettings, val: f64){
|
|
|
|
self.pid_ctrl_ch0.set_pid_params(param, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_sh_beta(&mut self, beta: f64) {
|
|
|
|
self.pid_ctrl_ch0.set_sh_beta(beta);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_sh_r0(&mut self, r0: ElectricalResistance) {
|
|
|
|
self.pid_ctrl_ch0.set_sh_r0(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_sh_t0(&mut self, t0: ThermodynamicTemperature) {
|
|
|
|
self.pid_ctrl_ch0.set_sh_t0(t0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_temperature_setpoint(&mut self, t: ThermodynamicTemperature) {
|
|
|
|
self.pid_ctrl_ch0.set_pid_setpoint(t);
|
2024-02-21 15:49:08 +08:00
|
|
|
self.temp_mon.set_setpoint(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_temp_mon_upper_limit(&mut self, t: ThermodynamicTemperature) {
|
|
|
|
self.temp_mon.set_upper_limit(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_temp_mon_lower_limit(&mut self, t: ThermodynamicTemperature) {
|
|
|
|
self.temp_mon.set_lower_limit(t);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
2024-02-21 15:49:08 +08:00
|
|
|
|
|
|
|
pub fn clear_temp_mon_alarm(&mut self) {
|
|
|
|
self.temp_mon.clear_alarm();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_temp_mon_settings(&mut self) -> TempMonSettings {
|
|
|
|
self.temp_mon.get_settings()
|
|
|
|
}
|
|
|
|
|
2024-01-18 15:14:24 +08:00
|
|
|
}
|
|
|
|
|
2024-02-19 15:08:00 +08:00
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
|
2024-01-18 15:14:24 +08:00
|
|
|
pub struct StatusReport {
|
2024-02-15 10:37:45 +08:00
|
|
|
ts: u32,
|
2024-01-18 15:14:24 +08:00
|
|
|
pid_engaged: bool,
|
2024-02-21 15:49:08 +08:00
|
|
|
temp_mon_status: TempStatus,
|
2024-01-18 15:14:24 +08:00
|
|
|
temperature: Option<ThermodynamicTemperature>,
|
|
|
|
i_set: ElectricCurrent,
|
|
|
|
tec_i: ElectricCurrent,
|
|
|
|
tec_v: ElectricPotential,
|
|
|
|
tec_vref: ElectricPotential,
|
|
|
|
}
|
|
|
|
|
2024-02-02 14:07:25 +08:00
|
|
|
#[derive(Tree)]
|
2024-01-18 15:14:24 +08:00
|
|
|
pub struct TecSettingsSummaryField<T> {
|
|
|
|
value: T,
|
|
|
|
max: T,
|
|
|
|
}
|
|
|
|
|
2024-02-02 14:07:25 +08:00
|
|
|
#[derive(Tree)]
|
2024-01-18 15:14:24 +08:00
|
|
|
pub struct TecSettingSummary {
|
|
|
|
center_point: ElectricPotential,
|
2024-02-02 14:07:25 +08:00
|
|
|
#[tree]
|
2024-01-18 15:14:24 +08:00
|
|
|
i_set: TecSettingsSummaryField<ElectricCurrent>,
|
2024-02-02 14:07:25 +08:00
|
|
|
#[tree]
|
2024-01-18 15:14:24 +08:00
|
|
|
max_v: TecSettingsSummaryField<ElectricPotential>,
|
2024-02-02 14:07:25 +08:00
|
|
|
#[tree]
|
2024-01-18 15:14:24 +08:00
|
|
|
max_i_pos: TecSettingsSummaryField<ElectricCurrent>,
|
2024-02-02 14:07:25 +08:00
|
|
|
#[tree]
|
2024-01-18 15:14:24 +08:00
|
|
|
max_i_neg: TecSettingsSummaryField<ElectricCurrent>,
|
|
|
|
}
|
|
|
|
|
2024-02-02 14:07:25 +08:00
|
|
|
#[derive(Tree)]
|
2024-01-18 15:14:24 +08:00
|
|
|
pub struct SteinhartHartSummary {
|
2024-02-02 14:07:25 +08:00
|
|
|
#[tree]
|
2024-01-18 15:14:24 +08:00
|
|
|
params: steinhart_hart::Parameters,
|
2024-01-17 16:06:07 +08:00
|
|
|
}
|