ld_drive: Add soft current limit

This commit is contained in:
linuswck 2024-01-11 12:51:08 +08:00
parent 8ae27725c6
commit 33d9cb45c4
2 changed files with 9 additions and 2 deletions

View File

@ -63,7 +63,7 @@ pub fn bootup(
laser.setup();
laser.ld_open();
laser.power_up();
laser.set_ld_drive_current_limit(ElectricCurrent::new::<ampere>(0.2));
laser.ld_set_i(ElectricCurrent::new::<ampere>(0.15));
// Set a non-zero value so that there is a non NAN power reading

View File

@ -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::<milliampere>(0.0),
ld_drive_current_limit: ElectricCurrent::new::<milliampere>(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
}