From 0179e7641aa852ebf23b4d3ac686ddb8e643092c Mon Sep 17 00:00:00 2001 From: linuswck Date: Wed, 20 Dec 2023 14:51:34 +0800 Subject: [PATCH] Add MAX1968 Startup Sequence --- src/device/boot.rs | 15 +++++++++++++-- src/thermostat/max1968.rs | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/device/boot.rs b/src/device/boot.rs index c5b14c0..8867363 100644 --- a/src/device/boot.rs +++ b/src/device/boot.rs @@ -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::(1.0)); + + tec_driver.power_up(); let mut wd = IndependentWatchdog::new(perif.IWDG); wd.start(WATCHDOG_PERIOD.millis()); diff --git a/src/thermostat/max1968.rs b/src/thermostat/max1968.rs index 0014a17..2b268fa 100644 --- a/src/thermostat/max1968.rs +++ b/src/thermostat/max1968.rs @@ -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::(5.0)); + self.set_max_i_pos(ElectricCurrent::new::(1.0)); + self.set_max_i_neg(ElectricCurrent::new::(1.0)); + + self.set_i(ElectricCurrent::new::(0.0)); + } + pub fn power_down(&mut self) { let _ = self.shdn.set_low(); }