From 3ad7c417f66969d6d6680c4a09c9cb447d38562c Mon Sep 17 00:00:00 2001 From: linuswck Date: Mon, 18 Mar 2024 16:39:22 +0800 Subject: [PATCH] Fix a ld current ramp up bug - During ld_i ramp up, if pwr up cmd is called, ld_i is set incorrectly --- src/laser_diode/laser_diode.rs | 5 +++-- src/laser_diode/ld_current_out_ctrl_timer.rs | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/laser_diode/laser_diode.rs b/src/laser_diode/laser_diode.rs index dc01280..4948b1c 100644 --- a/src/laser_diode/laser_diode.rs +++ b/src/laser_diode/laser_diode.rs @@ -117,13 +117,14 @@ impl LdDrive{ self.ctrl.ld_short_disable(); } - pub fn power_up(&mut self){ + pub fn power_up(&mut self){ + let prev_i_set = LdCurrentOutCtrlTimer::get_target_i(); LdCurrentOutCtrlTimer::reset(); let _ = self.ctrl.set_i(ElectricCurrent::new::(0.0), Settings::LD_DRIVE_TRANSIMPEDANCE, Settings::DAC_OUT_V_MAX); LdPwrExcProtector::pwr_on_and_arm_protection(); // Wait for LD Power Supply to start up before driving current to laser diode sleep(30); - self.ld_set_i(self.settings.ld_drive_current); + self.ld_set_i(prev_i_set); self.settings.pwr_on = true; } diff --git a/src/laser_diode/ld_current_out_ctrl_timer.rs b/src/laser_diode/ld_current_out_ctrl_timer.rs index 780d787..3a3fb84 100644 --- a/src/laser_diode/ld_current_out_ctrl_timer.rs +++ b/src/laser_diode/ld_current_out_ctrl_timer.rs @@ -63,6 +63,13 @@ impl LdCurrentOutCtrlTimer { } } + pub fn get_target_i() -> ElectricCurrent { + if let Some(ref mut ld_current_out_ctrl_timer ) = LdCurrentOutCtrlTimer::get() { + return ld_current_out_ctrl_timer.target_i + } + ElectricCurrent::new::(0.0) + } + pub fn set_alarm() { if let Some(ref mut ld_current_out_ctrl_timer ) = LdCurrentOutCtrlTimer::get() { ld_current_out_ctrl_timer.timeout = true;