Compare commits

..

1 Commits

Author SHA1 Message Date
linuswck ecfcce13a8 Update Kirdy Driver Example Code 2024-06-21 17:59:18 +08:00
6 changed files with 28 additions and 39 deletions

View File

@ -129,11 +129,16 @@ class FilterConfig:
def _filter_type(self):
return "Sinc3"
############## Rewrite
class Sinc3WithFineODR():
def __init__(self, rate):
assert rate >= 1.907465 and rate <= 31250
self.rate = float(rate)
# def rate(self, rate):
# assert rate >= 1.907465 and rate <= 31250
# return float(rate)
def _odr_type(self):
return "sinc3fineodr"
@ -223,7 +228,7 @@ class Device:
'ld_i_set': 0.0, # Laser Diode Output Current (A)
'pd_i': 2.0000002e-06, # Internal Photodiode Monitor current (A)
'pd_pwr': None, # Power Readings from Internal Photodiode (W). Return None if pd_mon parameter(s) are not defined.
'term_50ohm': 'Is50Ohm' # Is the Low Frequency Modulation Input's Impedance 50 Ohm? (On/Off)
'term_status': 'Is50Ohm' # Is the Low Frequency Modulation Input's Impedance 50 Ohm? (Is50Ohm/Not50Ohm)
},
'thermostat': {
'pwr_on': False, # Tec Power is On (True/False)

View File

@ -332,7 +332,7 @@ class MainWindow(QtWidgets.QMainWindow):
{'name': 'LD Current Set', 'type': 'float', 'suffix': 'A', 'siPrefix': True, 'readonly': True},
{'name': 'PD Current', 'type': 'float', 'suffix': 'A', 'siPrefix': True, 'readonly': True},
{'name': 'PD Power', 'type': 'float', 'suffix': 'W', 'siPrefix': True, 'readonly': True},
{'name': 'LF Mod Termination (50 Ohm)', 'type': 'list', 'limits': ['On', 'Off'], 'readonly': True}
{'name': 'LF Mod Impedance', 'type': 'list', 'limits': ['Is50Ohm', 'Not50Ohm'], 'readonly': True}
]},
{'name': 'Output Config', 'expanded': True, 'type': 'group', 'children': [
{'name': 'LD Current Set', 'type': 'float', 'value': 0, 'step': 1, 'decimals': 6, 'limits': (0, 1),
@ -818,7 +818,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.params[1].child('Readings', 'PD Power').setValue(report["pd_pwr"])
else:
self.params[1].child('Readings', 'PD Power').setValue(0)
self.params[1].child('Readings', 'LF Mod Termination (50 Ohm)').setValue(report["term_50ohm"])
self.params[1].child('Readings', 'LF Mod Impedance').setValue(report["term_status"])
except Exception as e:
logging.error(f"Params tree cannot be updated. Data:{report}", exc_info=True)
@ -898,7 +898,7 @@ class MainWindow(QtWidgets.QMainWindow):
try:
if not (self.kirdy.connecting() or self.kirdy.connected()):
self.status_lbl.setText("Connecting...")
await self.kirdy.start_session(host=host, port=port, timeout=5.0)
await self.kirdy.start_session(host=host, port=port, timeout=0.1)
await self._on_connection_changed(True)
else:
await self.bail()

View File

@ -10,7 +10,7 @@ use uom::si::{electric_current::{ampere, milliampere},
power::milliwatt};
use crate::{device::sys_timer::sleep,
laser_diode::{ld_ctrl::{Impedance50Ohm, LdCtrl},
laser_diode::{ld_ctrl::{Impedance, LdCtrl},
ld_current_out_ctrl_timer::LdCurrentOutCtrlTimer,
ld_pwr_exc_protector::{self, LdPwrExcProtector},
pd_mon_params}};
@ -66,7 +66,7 @@ pub struct StatusReport {
ld_i_set: ElectricCurrent,
pd_i: ElectricCurrent,
pd_pwr: Power,
term_50ohm: Impedance50Ohm,
term_status: Impedance,
}
pub struct LdDrive {
@ -210,7 +210,7 @@ impl LdDrive {
self.settings.default_pwr_on = pwr_on;
}
pub fn get_term_status(&mut self) -> Impedance50Ohm {
pub fn get_term_status(&mut self) -> Impedance {
self.ctrl.get_lf_mod_in_impedance()
}
@ -226,7 +226,7 @@ impl LdDrive {
ld_i_set: ld_i_set,
pd_i: self.get_pd_i(),
pd_pwr: self.get_pd_pwr(),
term_50ohm: self.get_term_status(),
term_status: self.get_term_status(),
}
}
@ -255,9 +255,6 @@ impl LdDrive {
self.settings.pd_mon_params = settings.pd_mon_params;
self.settings.ld_pwr_limit = settings.ld_pwr_limit;
self.settings.default_pwr_on = settings.default_pwr_on;
self.set_ld_power_limit(settings.ld_pwr_limit);
if self.settings.ld_terms_short {
self.ld_short();
} else {

View File

@ -11,9 +11,9 @@ use uom::si::{electric_current::ampere,
use crate::laser_diode::max5719::{self, Dac};
#[derive(Deserialize, Serialize, Debug, Clone, Copy)]
pub enum Impedance50Ohm {
On,
Off,
pub enum Impedance {
Is50Ohm,
Not50Ohm,
}
pub trait ChannelPins {
@ -66,11 +66,11 @@ impl LdCtrl {
self.phy.current_source_short_pin.set_high();
}
pub fn get_lf_mod_in_impedance(&mut self) -> Impedance50Ohm {
pub fn get_lf_mod_in_impedance(&mut self) -> Impedance {
if self.phy.termination_status_pin.is_high() {
Impedance50Ohm::On
Impedance::Is50Ohm
} else {
Impedance50Ohm::Off
Impedance::Not50Ohm
}
}

View File

@ -12,7 +12,7 @@ use stm32f4xx_hal::{adc::{config::{self, AdcConfig},
timer::pwm::PwmChannel};
use uom::si::{electric_potential::millivolt, f32::ElectricPotential, ratio::ratio};
use crate::{device::sys_timer::sleep, thermostat::ad5680};
use crate::thermostat::ad5680;
pub const PWM_FREQ_KHZ: KilohertzU32 = KilohertzU32::from_raw(20);
@ -77,7 +77,6 @@ pub struct MAX1968 {
pub phy: MAX1968Phy<Channel0>,
pub pins_adc: Adc<ADC1>,
pub dma_adc: DMA_Transfer<Stream2<DMA2>, 1, Adc<ADC2>, PeripheralToMemory, &'static mut [u16; 16]>,
pub dac_out_range: ElectricPotential,
prev_vtec_volt: ElectricPotential,
prev_itec_volt: ElectricPotential,
}
@ -116,7 +115,7 @@ static mut ADC2_FIRST_BUFFER: [u16; 16] = [0; 16];
static mut ADC2_LOCAL_BUFFER: [u16; 16] = [0; 16];
impl MAX1968 {
pub fn new(mut phy_ch0: MAX1968Phy<Channel0>, adc1: ADC1, adc2: ADC2, dma2: DMA2) -> Self {
pub fn new(phy_ch0: MAX1968Phy<Channel0>, adc1: ADC1, adc2: ADC2, dma2: DMA2) -> Self {
let adc_config = AdcConfig::default()
.clock(config::Clock::Pclk2_div_8)
.default_sample_time(config::SampleTime::Cycles_480);
@ -223,26 +222,10 @@ impl MAX1968 {
NVIC::unmask(interrupt::DMA2_STREAM2);
}
phy_ch0.dac.set(ad5680::MAX_VALUE).unwrap();
sleep(500);
let mut sample = 0;
for _ in 0..512 {
sample += pins_adc1.convert(
&phy_ch0.dac_feedback_pin,
stm32f4xx_hal::adc::config::SampleTime::Cycles_480,
) as u32;
}
let sample = sample / 512 as u32;
let mv = pins_adc1.sample_to_millivolts(sample as u16);
let dac_out_range = ElectricPotential::new::<millivolt>(mv as f32);
phy_ch0.dac.set(0).unwrap();
MAX1968 {
phy: phy_ch0,
pins_adc: pins_adc1,
dma_adc: dma_adc,
dac_out_range: dac_out_range,
prev_vtec_volt: ElectricPotential::new::<millivolt>(0.0),
prev_itec_volt: ElectricPotential::new::<millivolt>(0.0),
}

View File

@ -47,6 +47,11 @@ pub struct TecSettings {
}
impl TecSettings {
pub const DAC_OUT_V_MAX: ElectricPotential = ElectricPotential {
dimension: PhantomData,
units: PhantomData,
value: 3.0,
};
pub const TEC_VSEC_BIAS_V: ElectricPotential = ElectricPotential {
dimension: PhantomData,
units: PhantomData,
@ -232,8 +237,7 @@ impl Thermostat {
pub fn set_i(&mut self, i_tec: ElectricCurrent) -> ElectricCurrent {
let voltage = i_tec * 10.0 * R_SENSE + self.tec_settings.center_pt;
let voltage = self.max1968.set_dac(voltage, self.max1968.dac_out_range);
let voltage = self.max1968.set_dac(voltage, TecSettings::DAC_OUT_V_MAX);
self.tec_settings.i_set = (voltage - self.tec_settings.center_pt) / (10.0 * R_SENSE);
self.tec_settings.i_set
}
@ -331,7 +335,7 @@ impl Thermostat {
best_error = error;
start_value = prev_value;
let vref = (value as f32 / ad5680::MAX_VALUE as f32) * self.max1968.dac_out_range;
let vref = (value as f32 / ad5680::MAX_VALUE as f32) * TecSettings::DAC_OUT_V_MAX;
self.set_center_pt(vref);
}
prev_value = value;