ld_drive: Add fns to set ld output current

This commit is contained in:
linuswck 2024-01-09 16:02:17 +08:00
parent 58a8b15c40
commit d1f7a20c15
2 changed files with 23 additions and 0 deletions

View File

@ -9,7 +9,13 @@ use stm32f4xx_hal::{
spi::{NoMiso, Spi, TransferModeNormal}, spi::{NoMiso, Spi, TransferModeNormal},
}; };
use uom::si::{
ratio::ratio,
f64::{ElectricPotential, ElectricCurrent},
};
use crate::laser_diode::max5719::{self, Dac}; use crate::laser_diode::max5719::{self, Dac};
use crate::laser_diode::ld_drive::transimpedance_unit;
pub trait ChannelPins { pub trait ChannelPins {
type PdMonPin; type PdMonPin;
@ -82,4 +88,16 @@ impl CurrentSource {
pub fn ld_short_disable(&mut self) { pub fn ld_short_disable(&mut self) {
self.phy.current_source_short_pin.set_high(); self.phy.current_source_short_pin.set_high();
} }
pub fn set_dac(&mut self, voltage: ElectricPotential, dac_out_v_max: ElectricPotential) -> ElectricPotential {
let value = ((voltage / dac_out_v_max).get::<ratio>()
* (max5719::MAX_VALUE as f64)) as u32;
self.phy.dac.set(value).unwrap();
voltage
}
pub fn set_i(&mut self, current: ElectricCurrent, transimpedance: transimpedance_unit, dac_out_v_max: ElectricPotential) -> ElectricCurrent {
let v = current * transimpedance;
self.set_dac(current * transimpedance, dac_out_v_max) / transimpedance
}
} }

View File

@ -85,4 +85,9 @@ impl LD_Drive{
self.ctrl.ld_short_disable(); self.ctrl.ld_short_disable();
} }
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);
self.settings.ld_drive_current = ld_i_set;
ld_i_set
}
} }