Limit i_set within range of MAX1968 chip #102
|
@ -25,6 +25,10 @@ use crate::{
|
||||||
|
|
||||||
pub const CHANNELS: usize = 2;
|
pub const CHANNELS: usize = 2;
|
||||||
pub const R_SENSE: f64 = 0.05;
|
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
|
// 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;
|
const DAC_OUT_V_MAX: f64 = 3.0;
|
||||||
|
|
||||||
|
@ -130,6 +134,11 @@ impl<'a> Channels<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_i(&mut self, channel: usize, i_set: ElectricCurrent) -> ElectricCurrent {
|
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() {
|
let vref_meas = match channel.into() {
|
||||||
0 => self.channel0.vref_meas,
|
0 => self.channel0.vref_meas,
|
||||||
1 => self.channel1.vref_meas,
|
1 => self.channel1.vref_meas,
|
||||||
|
|
|
@ -11,13 +11,11 @@ use uom::si::{
|
||||||
use crate::{
|
use crate::{
|
||||||
hw_rev::HWSettings,
|
hw_rev::HWSettings,
|
||||||
command_handler::JsonBuffer,
|
command_handler::JsonBuffer,
|
||||||
|
channels::MAX_TEC_I,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type FanPin = PwmChannels<TIM8, pwm::C4>;
|
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 MAX_USER_FAN_PWM: f32 = 100.0;
|
||||||
const MIN_USER_FAN_PWM: f32 = 1.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) {
|
pub fn cycle(&mut self, abs_max_tec_i: ElectricCurrent) {
|
||||||
self.abs_max_tec_i = abs_max_tec_i.get::<ampere>() as f32;
|
self.abs_max_tec_i = abs_max_tec_i.get::<ampere>() as f32;
|
||||||
if self.fan_auto && self.hw_settings.fan_available {
|
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()
|
// 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;
|
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);
|
self.set_pwm(pwm);
|
||||||
|
|
Loading…
Reference in New Issue