do not overwrite dac value when pid is disengaged

softspi
Astro 2020-05-13 22:11:25 +02:00
parent b9d05ff274
commit c0079007f2
2 changed files with 4 additions and 4 deletions

View File

@ -26,7 +26,7 @@ impl Default for ChannelState {
impl ChannelState {
/// Update PID state on ADC input, calculate new DAC output
pub fn update_pid(&mut self, now: Instant, adc_data: u32) {
pub fn update_pid(&mut self, now: Instant, adc_data: u32) -> u32 {
self.adc_data = Some(adc_data);
self.adc_time = now;
@ -34,6 +34,6 @@ impl ChannelState {
let input = (adc_data as f64) / (ad7172::MAX_VALUE as f64);
let temperature = self.sh.get_temperature(input);
let output = self.pid.update(temperature);
self.dac_value = (output * (ad5680::MAX_VALUE as f64)) as u32;
(output * (ad5680::MAX_VALUE as f64)) as u32
}
}

View File

@ -48,10 +48,10 @@ impl Channels {
let dac_value = {
let state = self.channel_state(channel);
state.update_pid(instant, data);
let pid_output = state.update_pid(instant, data);
if state.pid_engaged {
Some(state.dac_value)
Some(pid_output)
} else {
None
}