Compare commits

..

1 Commits

Author SHA1 Message Date
atse e1e5a8a71c Limit i_set within range of MAX1968 chip 2024-04-10 12:49:01 +08:00
2 changed files with 12 additions and 14 deletions

View File

@ -25,6 +25,10 @@ use crate::{
pub const CHANNELS: usize = 2;
pub const R_SENSE: f64 = 0.05;
// as stated in the MAX1968 datasheet
pub const MAX_TEC_I: f64 = 3.0;
// DAC chip outputs 0-5v, which is then passed through a resistor dividor to provide 0-3v range
const DAC_OUT_V_MAX: f64 = 3.0;
@ -129,16 +133,12 @@ impl<'a> Channels<'a> {
voltage
}
pub fn set_i(&mut self, channel: usize, mut i_set: ElectricCurrent) -> ElectricCurrent {
// Silently clamp i_set to available range of MAX1968 chip
let min = ElectricCurrent::new::<ampere>(-3.0);
let max = ElectricCurrent::new::<ampere>(3.0);
if i_set < min {
i_set = min;
}
if i_set > max {
i_set = max;
}
pub fn set_i(&mut self, channel: usize, i_set: ElectricCurrent) -> ElectricCurrent {
// Silently clamp i_set
let i_ceiling = ElectricCurrent::new::<ampere>(MAX_TEC_I);
let i_floor = ElectricCurrent::new::<ampere>(-MAX_TEC_I);
let i_set = i_set.min(i_ceiling).max(i_floor);
let vref_meas = match channel.into() {
0 => self.channel0.vref_meas,
1 => self.channel1.vref_meas,

View File

@ -11,13 +11,11 @@ use uom::si::{
use crate::{
hw_rev::HWSettings,
command_handler::JsonBuffer,
channels::MAX_TEC_I,
};
pub type FanPin = PwmChannels<TIM8, pwm::C4>;
// as stated in the schematics
const MAX_TEC_I: f32 = 3.0;
const MAX_USER_FAN_PWM: f32 = 100.0;
const MIN_USER_FAN_PWM: f32 = 1.0;
@ -56,7 +54,7 @@ impl FanCtrl {
pub fn cycle(&mut self, abs_max_tec_i: ElectricCurrent) {
self.abs_max_tec_i = abs_max_tec_i.get::<ampere>() as f32;
if self.fan_auto && self.hw_settings.fan_available {
let scaled_current = self.abs_max_tec_i / MAX_TEC_I;
let scaled_current = self.abs_max_tec_i / MAX_TEC_I as f32;
// do not limit upper bound, as it will be limited in the set_pwm()
let pwm = (MAX_USER_FAN_PWM * (scaled_current * (scaled_current * self.k_a + self.k_b) + self.k_c)) as u32;
self.set_pwm(pwm);