Fix a ld current ramp up bug

- During ld_i ramp up, if pwr up cmd is called, ld_i is set incorrectly
master
linuswck 2024-03-18 16:39:22 +08:00
parent c06491a8b2
commit 3ad7c417f6
2 changed files with 10 additions and 2 deletions

View File

@ -117,13 +117,14 @@ impl LdDrive{
self.ctrl.ld_short_disable(); 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(); LdCurrentOutCtrlTimer::reset();
let _ = self.ctrl.set_i(ElectricCurrent::new::<milliampere>(0.0), Settings::LD_DRIVE_TRANSIMPEDANCE, Settings::DAC_OUT_V_MAX); let _ = self.ctrl.set_i(ElectricCurrent::new::<milliampere>(0.0), Settings::LD_DRIVE_TRANSIMPEDANCE, Settings::DAC_OUT_V_MAX);
LdPwrExcProtector::pwr_on_and_arm_protection(); LdPwrExcProtector::pwr_on_and_arm_protection();
// Wait for LD Power Supply to start up before driving current to laser diode // Wait for LD Power Supply to start up before driving current to laser diode
sleep(30); sleep(30);
self.ld_set_i(self.settings.ld_drive_current); self.ld_set_i(prev_i_set);
self.settings.pwr_on = true; self.settings.pwr_on = true;
} }

View File

@ -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::<ampere>(0.0)
}
pub fn set_alarm() { pub fn set_alarm() {
if let Some(ref mut ld_current_out_ctrl_timer ) = LdCurrentOutCtrlTimer::get() { if let Some(ref mut ld_current_out_ctrl_timer ) = LdCurrentOutCtrlTimer::get() {
ld_current_out_ctrl_timer.timeout = true; ld_current_out_ctrl_timer.timeout = true;