forked from M-Labs/thermostat
Stop i_set from fluctuating in every report
i_set is a user-provided value that shouldn't fluctuate with every VREF measurement. Storing i_set as channel state is the simplest way to avoid that.
This commit is contained in:
parent
ae3d8b51d4
commit
8b975e656e
|
@ -2,11 +2,13 @@ use smoltcp::time::{Duration, Instant};
|
|||
use uom::si::{
|
||||
f64::{
|
||||
ElectricPotential,
|
||||
ElectricCurrent,
|
||||
ElectricalResistance,
|
||||
ThermodynamicTemperature,
|
||||
Time,
|
||||
},
|
||||
electric_potential::volt,
|
||||
electric_current::ampere,
|
||||
electrical_resistance::ohm,
|
||||
thermodynamic_temperature::degree_celsius,
|
||||
time::millisecond,
|
||||
|
@ -29,6 +31,7 @@ pub struct ChannelState {
|
|||
/// 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,
|
||||
|
@ -44,6 +47,7 @@ impl ChannelState {
|
|||
adc_interval: Duration::from_millis(100),
|
||||
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(),
|
||||
|
|
|
@ -113,11 +113,8 @@ impl<'a> Channels<'a> {
|
|||
}
|
||||
|
||||
pub fn get_i(&mut self, channel: usize) -> ElectricCurrent {
|
||||
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
|
||||
let i_set = self.channel_state(channel).i_set;
|
||||
i_set
|
||||
}
|
||||
|
||||
/// i_set DAC
|
||||
|
@ -143,6 +140,7 @@ impl<'a> Channels<'a> {
|
|||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue