pd_mon: add fns to convert between pwr and current
This commit is contained in:
parent
e22f424531
commit
9d8a553669
|
@ -2,7 +2,8 @@ use miniconf::Miniconf;
|
|||
use stm32f4xx_hal::pac::ADC2;
|
||||
use crate::laser_diode::ld_ctrl::LdCtrl;
|
||||
use crate::laser_diode::ld_pwr_exc_protector::{LdPwrExcProtector, self};
|
||||
use core::{marker::PhantomData, f64::NAN};
|
||||
use crate::laser_diode::pd_mon;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use uom::si::{
|
||||
electric_current::milliampere,
|
||||
|
@ -43,7 +44,8 @@ impl Settings{
|
|||
pub struct Settings {
|
||||
ld_drive_current: ElectricCurrent,
|
||||
ld_drive_current_limit: ElectricCurrent,
|
||||
pd_i_to_out_pwr: IToPowerUnit,
|
||||
#[miniconf(defer)]
|
||||
pd_responsitivity: pd_mon::Parameters,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
|
@ -51,7 +53,7 @@ impl Default for Settings {
|
|||
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}
|
||||
pd_responsitivity: pd_mon::Parameters::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,16 +127,17 @@ impl LdDrive{
|
|||
LdPwrExcProtector::clear_alarm_status();
|
||||
}
|
||||
|
||||
pub fn set_pd_responsitivity(&mut self, responsitivity: pd_mon::ResponsitivityUnit){
|
||||
self.settings.pd_responsitivity.responsitivity = responsitivity;
|
||||
}
|
||||
|
||||
pub fn set_ld_power_limit(&mut self, pwr_limit: Power){
|
||||
// LdPwrExcProtector::set_trigger_threshold_v(convert pwr_limit to raw adc code)
|
||||
unimplemented!()
|
||||
LdPwrExcProtector::set_trigger_threshold_v(self.settings.pd_responsitivity
|
||||
.get_ld_i_from_ld_pwr(pwr_limit) / Settings::PD_MON_TRANSCONDUCTANCE
|
||||
);
|
||||
}
|
||||
|
||||
pub fn set_pd_i_limit(&mut self, i: ElectricCurrent){
|
||||
LdPwrExcProtector::set_trigger_threshold_v(i / Settings::PD_MON_TRANSCONDUCTANCE);
|
||||
}
|
||||
|
||||
pub fn set_pd_v_limit(&mut self, v: ElectricPotential){
|
||||
LdPwrExcProtector::set_trigger_threshold_v(v);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,19 +12,22 @@ use miniconf::Miniconf;
|
|||
// Ampere / Watt
|
||||
pub type ResponsitivityUnit = Quantity<ISQ<N2, N1, P3, P1, Z0, Z0, Z0>, SI<f64>, f64>;
|
||||
|
||||
/// Steinhart-Hart equation Photodiode
|
||||
#[derive(Clone, Debug, PartialEq, Miniconf)]
|
||||
pub struct Parameters {
|
||||
/// Responsitivity
|
||||
pub responsitivity: ResponsitivityUnit,
|
||||
pub i_dark: ElectricCurrent,
|
||||
}
|
||||
|
||||
impl Parameters {
|
||||
pub fn get_ld_output_power(&self, i: ElectricCurrent) -> Power {
|
||||
pub fn get_ld_pwr_from_ld_i(&self, i: ElectricCurrent) -> Power {
|
||||
let ld_power = (i - self.i_dark) / self.responsitivity;
|
||||
ld_power
|
||||
}
|
||||
|
||||
pub fn get_ld_i_from_ld_pwr(&self, pwr: Power) -> ElectricCurrent {
|
||||
let ld_i = pwr * self.responsitivity + self.i_dark;
|
||||
ld_i
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Parameters {
|
||||
|
|
Loading…
Reference in New Issue