Fix Incorrect Dac Calibration Algorithm #133

Merged
sb10q merged 1 commits from linuswck/thermostat:fix_incorrect_dac_cal into master 2024-09-25 17:18:33 +08:00
2 changed files with 2 additions and 5 deletions

View File

@ -297,7 +297,6 @@ impl Channels {
let mut best_error = ElectricPotential::new::<volt>(100.0); let mut best_error = ElectricPotential::new::<volt>(100.0);
for step in (5..18).rev() { for step in (5..18).rev() {
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) {
match channel { match channel {
0 => { 0 => {
@ -316,7 +315,7 @@ impl Channels {
break; break;
} else if error < best_error { } else if error < best_error {
best_error = 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; let vref = (value as f64 / ad5680::MAX_VALUE as f64) * DAC_OUT_V_MAX;
match channel { match channel {
@ -325,8 +324,6 @@ impl Channels {
_ => unreachable!(), _ => unreachable!(),
} }
} }
prev_value = value;
} }
} }

View File

@ -58,7 +58,7 @@ mod hw_rev;
const HSE: MegaHertz = MegaHertz(8); const HSE: MegaHertz = MegaHertz(8);
#[cfg(not(feature = "semihosting"))] #[cfg(not(feature = "semihosting"))]
const WATCHDOG_INTERVAL: u32 = 2_000; const WATCHDOG_INTERVAL: u32 = 1_000;
#[cfg(feature = "semihosting")] #[cfg(feature = "semihosting")]
const WATCHDOG_INTERVAL: u32 = 30_000; const WATCHDOG_INTERVAL: u32 = 30_000;