Add MAX1968 Startup Sequence

This commit is contained in:
linuswck 2023-12-20 14:51:34 +08:00
parent f6767b147b
commit 0179e7641a
2 changed files with 27 additions and 2 deletions

View File

@ -1,5 +1,6 @@
use super::{gpio, sys_timer, usb};
use crate::{laser_diode::current_sources::*, thermostat::max1968};
use crate::{laser_diode::current_sources::*};
use crate::{thermostat::max1968::MAX1968}
use fugit::ExtU32;
use log::info;
use stm32f4xx_hal::{
@ -9,6 +10,11 @@ use stm32f4xx_hal::{
watchdog::IndependentWatchdog,
};
use uom::si::{
electric_current::ampere,
f64::ElectricCurrent,
};
#[cfg(not(feature = "semihosting"))]
const WATCHDOG_PERIOD: u32 = 1000;
#[cfg(feature = "semihosting")]
@ -58,7 +64,12 @@ pub fn bootup(mut core_perif: CorePeripherals, perif: Peripherals) -> Independen
laser.setup();
laser.set_current(0.1).unwrap();
let tec_driver = max1968::MAX1968::new(max1968_phy, perif.ADC1);
let mut tec_driver = MAX1968::new(max1968_phy, perif.ADC1);
tec_driver.setup();
tec_driver.set_i(ElectricCurrent::new::<ampere>(1.0));
tec_driver.power_up();
let mut wd = IndependentWatchdog::new(perif.IWDG);
wd.start(WATCHDOG_PERIOD.millis());

View File

@ -143,6 +143,20 @@ impl MAX1968 {
}
}
pub fn setup(&mut self){
self.power_down();
let vref = self.adc_read(AdcReadTarget::VREF, 2048);
self.set_center_point(vref);
// Todo: Add Calibration here
self.set_max_v(ElectricPotential::new::<volt>(5.0));
self.set_max_i_pos(ElectricCurrent::new::<ampere>(1.0));
self.set_max_i_neg(ElectricCurrent::new::<ampere>(1.0));
self.set_i(ElectricCurrent::new::<ampere>(0.0));
}
pub fn power_down(&mut self) {
let _ = self.shdn.set_low();
}