forked from M-Labs/thermostat
Compare commits
No commits in common. "00d5feaa8d8c46617fd6c7c38f5f469af5aa67bd" and "76547be90a4d06f71fd7fdbf898bfbeb92f8af9d" have entirely different histories.
00d5feaa8d
...
76547be90a
@ -18,17 +18,13 @@ use crate::{
|
|||||||
channel_state::ChannelState,
|
channel_state::ChannelState,
|
||||||
command_parser::{CenterPoint, PwmPin},
|
command_parser::{CenterPoint, PwmPin},
|
||||||
command_handler::JsonBuffer,
|
command_handler::JsonBuffer,
|
||||||
pins::{self, Channel0VRef, Channel1VRef},
|
pins,
|
||||||
steinhart_hart,
|
steinhart_hart,
|
||||||
hw_rev,
|
hw_rev,
|
||||||
};
|
};
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -134,11 +130,6 @@ 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,
|
||||||
@ -212,30 +203,20 @@ impl<'a> Channels<'a> {
|
|||||||
pub fn read_vref(&mut self, channel: usize) -> ElectricPotential {
|
pub fn read_vref(&mut self, channel: usize) -> ElectricPotential {
|
||||||
match channel {
|
match channel {
|
||||||
0 => {
|
0 => {
|
||||||
match &self.channel0.vref_pin {
|
let sample = self.pins_adc.convert(
|
||||||
Channel0VRef::Analog(vref_pin) => {
|
&self.channel0.vref_pin,
|
||||||
let sample = self.pins_adc.convert(
|
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||||
vref_pin,
|
);
|
||||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
let mv = self.pins_adc.sample_to_millivolts(sample);
|
||||||
);
|
ElectricPotential::new::<millivolt>(mv as f64)
|
||||||
let mv = self.pins_adc.sample_to_millivolts(sample);
|
|
||||||
ElectricPotential::new::<millivolt>(mv as f64)
|
|
||||||
},
|
|
||||||
Channel0VRef::Disabled(_) => ElectricPotential::new::<volt>(1.5)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
match &self.channel1.vref_pin {
|
let sample = self.pins_adc.convert(
|
||||||
Channel1VRef::Analog(vref_pin) => {
|
&self.channel1.vref_pin,
|
||||||
let sample = self.pins_adc.convert(
|
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||||
vref_pin,
|
);
|
||||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
let mv = self.pins_adc.sample_to_millivolts(sample);
|
||||||
);
|
ElectricPotential::new::<millivolt>(mv as f64)
|
||||||
let mv = self.pins_adc.sample_to_millivolts(sample);
|
|
||||||
ElectricPotential::new::<millivolt>(mv as f64)
|
|
||||||
},
|
|
||||||
Channel1VRef::Disabled(_) => ElectricPotential::new::<volt>(1.5)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,13 @@ 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;
|
||||||
|
|
||||||
@ -54,7 +56,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 as f32;
|
let scaled_current = self.abs_max_tec_i / MAX_TEC_I;
|
||||||
// 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);
|
||||||
|
26
src/pins.rs
26
src/pins.rs
@ -66,31 +66,21 @@ pub trait ChannelPins {
|
|||||||
type TecUMeasPin;
|
type TecUMeasPin;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Channel0VRef {
|
|
||||||
Analog(PA0<Analog>),
|
|
||||||
Disabled(PA0<Input<Floating>>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ChannelPins for Channel0 {
|
impl ChannelPins for Channel0 {
|
||||||
type DacSpi = Dac0Spi;
|
type DacSpi = Dac0Spi;
|
||||||
type DacSync = PE4<Output<PushPull>>;
|
type DacSync = PE4<Output<PushPull>>;
|
||||||
type Shdn = PE10<Output<PushPull>>;
|
type Shdn = PE10<Output<PushPull>>;
|
||||||
type VRefPin = Channel0VRef;
|
type VRefPin = PA0<Analog>;
|
||||||
type ItecPin = PA6<Analog>;
|
type ItecPin = PA6<Analog>;
|
||||||
type DacFeedbackPin = PA4<Analog>;
|
type DacFeedbackPin = PA4<Analog>;
|
||||||
type TecUMeasPin = PC2<Analog>;
|
type TecUMeasPin = PC2<Analog>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Channel1VRef {
|
|
||||||
Analog(PA3<Analog>),
|
|
||||||
Disabled(PA3<Input<Floating>>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ChannelPins for Channel1 {
|
impl ChannelPins for Channel1 {
|
||||||
type DacSpi = Dac1Spi;
|
type DacSpi = Dac1Spi;
|
||||||
type DacSync = PF6<Output<PushPull>>;
|
type DacSync = PF6<Output<PushPull>>;
|
||||||
type Shdn = PE15<Output<PushPull>>;
|
type Shdn = PE15<Output<PushPull>>;
|
||||||
type VRefPin = Channel1VRef;
|
type VRefPin = PA3<Analog>;
|
||||||
type ItecPin = PB0<Analog>;
|
type ItecPin = PB0<Analog>;
|
||||||
type DacFeedbackPin = PA5<Analog>;
|
type DacFeedbackPin = PA5<Analog>;
|
||||||
type TecUMeasPin = PC3<Analog>;
|
type TecUMeasPin = PC3<Analog>;
|
||||||
@ -160,17 +150,13 @@ impl Pins {
|
|||||||
gpioe.pe13, gpioe.pe14
|
gpioe.pe13, gpioe.pe14
|
||||||
);
|
);
|
||||||
|
|
||||||
let hwrev = HWRev::detect_hw_rev(&HWRevPins {hwrev0: gpiod.pd0, hwrev1: gpiod.pd1,
|
|
||||||
hwrev2: gpiod.pd2, hwrev3: gpiod.pd3});
|
|
||||||
let hw_settings = hwrev.settings();
|
|
||||||
|
|
||||||
let (dac0_spi, dac0_sync) = Self::setup_dac0(
|
let (dac0_spi, dac0_sync) = Self::setup_dac0(
|
||||||
clocks, spi4,
|
clocks, spi4,
|
||||||
gpioe.pe2, gpioe.pe4, gpioe.pe6
|
gpioe.pe2, gpioe.pe4, gpioe.pe6
|
||||||
);
|
);
|
||||||
let mut shdn0 = gpioe.pe10.into_push_pull_output();
|
let mut shdn0 = gpioe.pe10.into_push_pull_output();
|
||||||
let _ = shdn0.set_low();
|
let _ = shdn0.set_low();
|
||||||
let vref0_pin = if hwrev.major > 2 {Channel0VRef::Analog(gpioa.pa0.into_analog())} else {Channel0VRef::Disabled(gpioa.pa0)};
|
let vref0_pin = gpioa.pa0.into_analog();
|
||||||
let itec0_pin = gpioa.pa6.into_analog();
|
let itec0_pin = gpioa.pa6.into_analog();
|
||||||
let dac_feedback0_pin = gpioa.pa4.into_analog();
|
let dac_feedback0_pin = gpioa.pa4.into_analog();
|
||||||
let tec_u_meas0_pin = gpioc.pc2.into_analog();
|
let tec_u_meas0_pin = gpioc.pc2.into_analog();
|
||||||
@ -190,7 +176,7 @@ impl Pins {
|
|||||||
);
|
);
|
||||||
let mut shdn1 = gpioe.pe15.into_push_pull_output();
|
let mut shdn1 = gpioe.pe15.into_push_pull_output();
|
||||||
let _ = shdn1.set_low();
|
let _ = shdn1.set_low();
|
||||||
let vref1_pin = if hwrev.major > 2 {Channel1VRef::Analog(gpioa.pa3.into_analog())} else {Channel1VRef::Disabled(gpioa.pa3)};
|
let vref1_pin = gpioa.pa3.into_analog();
|
||||||
let itec1_pin = gpiob.pb0.into_analog();
|
let itec1_pin = gpiob.pb0.into_analog();
|
||||||
let dac_feedback1_pin = gpioa.pa5.into_analog();
|
let dac_feedback1_pin = gpioa.pa5.into_analog();
|
||||||
let tec_u_meas1_pin = gpioc.pc3.into_analog();
|
let tec_u_meas1_pin = gpioc.pc3.into_analog();
|
||||||
@ -212,6 +198,10 @@ impl Pins {
|
|||||||
channel1,
|
channel1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let hwrev = HWRev::detect_hw_rev(&HWRevPins {hwrev0: gpiod.pd0, hwrev1: gpiod.pd1,
|
||||||
|
hwrev2: gpiod.pd2, hwrev3: gpiod.pd3});
|
||||||
|
let hw_settings = hwrev.settings();
|
||||||
|
|
||||||
let leds = Leds::new(gpiod.pd9, gpiod.pd10.into_push_pull_output(), gpiod.pd11.into_push_pull_output());
|
let leds = Leds::new(gpiod.pd9, gpiod.pd10.into_push_pull_output(), gpiod.pd11.into_push_pull_output());
|
||||||
|
|
||||||
let eeprom_scl = gpiob.pb8.into_alternate().set_open_drain();
|
let eeprom_scl = gpiob.pb8.into_alternate().set_open_drain();
|
||||||
|
Loading…
Reference in New Issue
Block a user