From 680193b34b6dc24689e623dde8336f296ea4b189 Mon Sep 17 00:00:00 2001 From: linuswck Date: Fri, 20 Sep 2024 21:21:14 +0800 Subject: [PATCH] Fix incorrect dac calibration algo - Fix abnormally long calibration time --- src/channels.rs | 5 +---- src/main.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/channels.rs b/src/channels.rs index 37ba961..9d5c533 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -297,7 +297,6 @@ impl Channels { let mut best_error = ElectricPotential::new::(100.0); for step in (5..18).rev() { - let mut prev_value = start_value; for value in (start_value..=ad5680::MAX_VALUE).step_by(1 << step) { match channel { 0 => { @@ -316,7 +315,7 @@ impl Channels { break; } else if error < best_error { best_error = error; - start_value = prev_value; + start_value = value; let vref = (value as f64 / ad5680::MAX_VALUE as f64) * DAC_OUT_V_MAX; match channel { @@ -325,8 +324,6 @@ impl Channels { _ => unreachable!(), } } - - prev_value = value; } } diff --git a/src/main.rs b/src/main.rs index 0e79e1b..353a161 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,7 @@ mod hw_rev; const HSE: MegaHertz = MegaHertz(8); #[cfg(not(feature = "semihosting"))] -const WATCHDOG_INTERVAL: u32 = 2_000; +const WATCHDOG_INTERVAL: u32 = 1_000; #[cfg(feature = "semihosting")] const WATCHDOG_INTERVAL: u32 = 30_000;