1
0
Fork 0

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
This commit is contained in:
linuswck 2024-04-23 15:42:17 +08:00
parent c5efc6ca57
commit 7be35fe7f0
1 changed files with 4 additions and 4 deletions

View File

@ -302,12 +302,12 @@ impl Thermostat{
/// VREF measurement can introduce significant noise at the current output, degrading the stabilily performance of the /// VREF measurement can introduce significant noise at the current output, degrading the stabilily performance of the
/// thermostat. /// thermostat.
pub fn calibrate_dac_value(&mut self) { pub fn calibrate_dac_value(&mut self) {
const STEPS: i32 = 18; const DAC_BIT: u32 = 18;
let target_voltage = self.max1968.adc_read(AdcReadTarget::VREF, 64); const ADC_BIT: u32 = 12;
let target_voltage = self.max1968.adc_read(AdcReadTarget::VREF, 512);
let mut start_value = 1; let mut start_value = 1;
let mut best_error = ElectricPotential::new::<volt>(100.0); let mut best_error = ElectricPotential::new::<volt>(100.0);
for step in (0..STEPS).rev() { for step in (DAC_BIT-ADC_BIT-1..DAC_BIT).rev() {
debug!("TEC VREF Calibrating: Step {}/{}", step, STEPS);
let mut prev_value = start_value; let mut prev_value = start_value;
for value in (start_value..=ad5680::MAX_VALUE).step_by(1 << step) { for value in (start_value..=ad5680::MAX_VALUE).step_by(1 << step) {
self.max1968.phy.dac.set(value).unwrap(); self.max1968.phy.dac.set(value).unwrap();