From 30ab228b4b646a4d70ba6917303150bf30542a85 Mon Sep 17 00:00:00 2001 From: linuswck Date: Tue, 20 Feb 2024 16:22:13 +0800 Subject: [PATCH] ld: Set default ld_current_limit in setup() fn --- src/device/boot.rs | 1 - src/laser_diode/laser_diode.rs | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/device/boot.rs b/src/device/boot.rs index e64ee4a..f6f5e90 100644 --- a/src/device/boot.rs +++ b/src/device/boot.rs @@ -75,7 +75,6 @@ pub fn bootup( let mut laser = LdDrive::new(current_source, perif.ADC2, perif.TIM2.counter(&clocks), pd_mon_phy); laser.setup(); laser.ld_open(); - laser.set_ld_drive_current_limit(ElectricCurrent::new::(0.2)); laser.ld_set_i(ElectricCurrent::new::(0.0)); laser.set_pd_i_limit(ElectricCurrent::new::(2.5)); laser.set_pd_mon_calibrated_vdda(thermostat.get_calibrated_vdda()); diff --git a/src/laser_diode/laser_diode.rs b/src/laser_diode/laser_diode.rs index 7f60ade..1b0ef4f 100644 --- a/src/laser_diode/laser_diode.rs +++ b/src/laser_diode/laser_diode.rs @@ -22,6 +22,11 @@ pub type TransimpedanceUnit = Quantity, SI, type TransconductanceUnit = Quantity, SI, f64>; impl Settings{ + pub const LD_CURRENT_MAX: ElectricCurrent = ElectricCurrent { + dimension: PhantomData, + units: PhantomData, + value: 0.3, + }; pub const DAC_OUT_V_MAX: ElectricPotential = ElectricPotential { dimension: PhantomData, units: PhantomData, @@ -89,6 +94,7 @@ impl LdDrive{ pub fn setup(&mut self) { LdPwrExcProtector::pwr_off(); self.ctrl.set_i(ElectricCurrent::new::(0.0), Settings::LD_DRIVE_TRANSIMPEDANCE, Settings::DAC_OUT_V_MAX); + self.set_ld_drive_current_limit(Settings::LD_CURRENT_MAX); LdCurrentOutCtrlTimer::reset(); self.ld_short(); } @@ -98,7 +104,7 @@ impl LdDrive{ } pub fn set_ld_drive_current_limit(&mut self, i_limit: ElectricCurrent){ - self.settings.ld_drive_current_limit = i_limit; + self.settings.ld_drive_current_limit = i_limit.min(Settings::LD_CURRENT_MAX); } pub fn ld_short(&mut self) {