From 33d9cb45c426dd502b64b312aace0beb103a6b44 Mon Sep 17 00:00:00 2001 From: linuswck Date: Thu, 11 Jan 2024 12:51:08 +0800 Subject: [PATCH] ld_drive: Add soft current limit --- src/device/boot.rs | 2 +- src/laser_diode/ld_drive.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/device/boot.rs b/src/device/boot.rs index d48e41e..407cccd 100644 --- a/src/device/boot.rs +++ b/src/device/boot.rs @@ -63,7 +63,7 @@ pub fn bootup( laser.setup(); laser.ld_open(); laser.power_up(); - + laser.set_ld_drive_current_limit(ElectricCurrent::new::(0.2)); laser.ld_set_i(ElectricCurrent::new::(0.15)); // Set a non-zero value so that there is a non NAN power reading diff --git a/src/laser_diode/ld_drive.rs b/src/laser_diode/ld_drive.rs index 5b91b02..9c5a18f 100644 --- a/src/laser_diode/ld_drive.rs +++ b/src/laser_diode/ld_drive.rs @@ -40,6 +40,7 @@ impl Settings{ #[derive(Clone, Debug, Miniconf)] pub struct Settings { ld_drive_current: ElectricCurrent, + ld_drive_current_limit: ElectricCurrent, pd_i_to_out_pwr: IToPowerUnit, } @@ -47,6 +48,7 @@ impl Default for Settings { fn default() -> Self { Self { ld_drive_current: ElectricCurrent::new::(0.0), + ld_drive_current_limit: ElectricCurrent::new::(0.0), pd_i_to_out_pwr: IToPowerUnit {dimension: PhantomData, units: PhantomData, value: NAN} } } @@ -83,6 +85,10 @@ impl LdDrive{ self.settings.ld_drive_current } + pub fn set_ld_drive_current_limit(&mut self, i_limit: ElectricCurrent){ + self.settings.ld_drive_current_limit = i_limit; + } + pub fn set_pd_i_to_out_pwr(&mut self, val: IToPowerUnit){ self.settings.pd_i_to_out_pwr = val; } @@ -105,7 +111,8 @@ impl LdDrive{ } pub fn ld_set_i(&mut self, i: ElectricCurrent) -> ElectricCurrent { - let ld_i_set = self.ctrl.set_i(i, Settings::LD_DRIVE_TRANSIMPEDANCE, Settings::DAC_OUT_V_MAX); + let ld_i_set = i.min(self.settings.ld_drive_current_limit); + let ld_i_set = self.ctrl.set_i(ld_i_set, Settings::LD_DRIVE_TRANSIMPEDANCE, Settings::DAC_OUT_V_MAX); self.settings.ld_drive_current = ld_i_set; ld_i_set }