From 7be35fe7f071eb1dd2dd210104cb0d4d16dbe9a7 Mon Sep 17 00:00:00 2001 From: linuswck Date: Tue, 23 Apr 2024 15:42:17 +0800 Subject: [PATCH] thermostat: Reduce DAC calibration time - 13 out of 18 bit of DAC is used to calibrate the output with 12bit ADC - Calibration with more than 13 bit does not improve the accuracy --- src/thermostat/thermostat.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/thermostat/thermostat.rs b/src/thermostat/thermostat.rs index e4fbe13..d6d6440 100644 --- a/src/thermostat/thermostat.rs +++ b/src/thermostat/thermostat.rs @@ -302,12 +302,12 @@ impl Thermostat{ /// VREF measurement can introduce significant noise at the current output, degrading the stabilily performance of the /// thermostat. pub fn calibrate_dac_value(&mut self) { - const STEPS: i32 = 18; - let target_voltage = self.max1968.adc_read(AdcReadTarget::VREF, 64); + const DAC_BIT: u32 = 18; + const ADC_BIT: u32 = 12; + let target_voltage = self.max1968.adc_read(AdcReadTarget::VREF, 512); let mut start_value = 1; let mut best_error = ElectricPotential::new::(100.0); - for step in (0..STEPS).rev() { - debug!("TEC VREF Calibrating: Step {}/{}", step, STEPS); + for step in (DAC_BIT-ADC_BIT-1..DAC_BIT).rev() { 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();