forked from M-Labs/thermostat
Compare commits
4 Commits
15053f8864
...
3eeeb4bfa4
Author | SHA1 | Date | |
---|---|---|---|
3eeeb4bfa4 | |||
78dba747f7 | |||
24b996a5f3 | |||
c6040899dd |
@ -100,10 +100,10 @@ formatted as line-delimited JSON.
|
||||
| `report mode` | Show current report mode |
|
||||
| `report mode <off/on>` | Set report mode |
|
||||
| `pwm` | Show current PWM settings |
|
||||
| `pwm <0/1> max_i_pos <amp>` | Set maximum positive output current |
|
||||
| `pwm <0/1> max_i_neg <amp>` | Set maximum negative output current |
|
||||
| `pwm <0/1> max_v <volt>` | Set maximum output voltage |
|
||||
| `pwm <0/1> i_set <amp>` | Disengage PID, set fixed output current |
|
||||
| `pwm <0/1> max_i_pos <amp>` | Set maximum positive output current, clamped at [0, 2] |
|
||||
| `pwm <0/1> max_i_neg <amp>` | Set maximum negative output current, clamped at [0, 2] |
|
||||
| `pwm <0/1> max_v <volt>` | Set maximum output voltage, clamped at [0, 4] |
|
||||
| `pwm <0/1> i_set <amp>` | Disengage PID, set fixed output current, clamped at [-2, 2] |
|
||||
| `pwm <0/1> pid` | Let output current to be controlled by the PID |
|
||||
| `center <0/1> <volt>` | Set the MAX1968 0A-centerpoint to the specified fixed voltage |
|
||||
| `center <0/1> vref` | Set the MAX1968 0A-centerpoint to measure from VREF |
|
||||
|
@ -24,7 +24,7 @@ pub struct Channel<C: ChannelPins> {
|
||||
pub vref_meas: ElectricPotential,
|
||||
pub shdn: C::Shdn,
|
||||
pub vref_pin: C::VRefPin,
|
||||
pub itec_pin: C::ItecPin,
|
||||
pub itec_pin: C::ITecPin,
|
||||
/// feedback from `dac` output
|
||||
pub dac_feedback_pin: C::DacFeedbackPin,
|
||||
pub tec_u_meas_pin: C::TecUMeasPin,
|
||||
|
@ -16,6 +16,7 @@ use uom::si::{
|
||||
use crate::{
|
||||
ad7172,
|
||||
pid,
|
||||
config::PwmLimits,
|
||||
steinhart_hart as sh,
|
||||
command_parser::CenterPoint,
|
||||
};
|
||||
@ -32,6 +33,7 @@ pub struct ChannelState {
|
||||
pub center: CenterPoint,
|
||||
pub dac_value: ElectricPotential,
|
||||
pub i_set: ElectricCurrent,
|
||||
pub pwm_limits: PwmLimits,
|
||||
pub pid_engaged: bool,
|
||||
pub pid: pid::Controller,
|
||||
pub sh: sh::Parameters,
|
||||
@ -48,6 +50,11 @@ impl ChannelState {
|
||||
center: CenterPoint::Vref,
|
||||
dac_value: ElectricPotential::new::<volt>(0.0),
|
||||
i_set: ElectricCurrent::new::<ampere>(0.0),
|
||||
pwm_limits: PwmLimits {
|
||||
max_v: 0.0,
|
||||
max_i_pos: 0.0,
|
||||
max_i_neg: 0.0,
|
||||
},
|
||||
pid_engaged: false,
|
||||
pid: pid::Controller::new(pid::Parameters::default()),
|
||||
sh: sh::Parameters::default(),
|
||||
|
@ -390,19 +390,19 @@ impl Channels {
|
||||
pub fn get_max_v(&mut self, channel: usize) -> (ElectricPotential, ElectricPotential) {
|
||||
let max = 4.0 * ElectricPotential::new::<volt>(3.3);
|
||||
let duty = self.get_pwm(channel, PwmPin::MaxV);
|
||||
(duty * max, MAX_TEC_V)
|
||||
(duty * max, ElectricPotential::new::<volt>(self.channel_state(channel).pwm_limits.max_v))
|
||||
}
|
||||
|
||||
pub fn get_max_i_pos(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) {
|
||||
let max = ElectricCurrent::new::<ampere>(3.0);
|
||||
let duty = self.get_pwm(channel, PwmPin::MaxIPos);
|
||||
(duty * max, MAX_TEC_I)
|
||||
(duty * max, ElectricCurrent::new::<ampere>(self.channel_state(channel).pwm_limits.max_i_pos))
|
||||
}
|
||||
|
||||
pub fn get_max_i_neg(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) {
|
||||
let max = ElectricCurrent::new::<ampere>(3.0);
|
||||
let duty = self.get_pwm(channel, PwmPin::MaxINeg);
|
||||
(duty * max, MAX_TEC_I)
|
||||
(duty * max, ElectricCurrent::new::<ampere>(self.channel_state(channel).pwm_limits.max_i_neg))
|
||||
}
|
||||
|
||||
// Get current passing through TEC
|
||||
@ -446,6 +446,7 @@ impl Channels {
|
||||
let max = 4.0 * ElectricPotential::new::<volt>(3.3);
|
||||
let duty = (max_v.min(MAX_TEC_V).max(ElectricPotential::zero()) / max).get::<ratio>();
|
||||
let duty = self.set_pwm(channel, PwmPin::MaxV, duty);
|
||||
self.channel_state(channel).pwm_limits.max_v = max_v.get::<volt>();
|
||||
(duty * max, max)
|
||||
}
|
||||
|
||||
@ -453,6 +454,7 @@ impl Channels {
|
||||
let max = ElectricCurrent::new::<ampere>(3.0);
|
||||
let duty = (max_i_pos.min(MAX_TEC_I).max(ElectricCurrent::zero()) / max).get::<ratio>();
|
||||
let duty = self.set_pwm(channel, PwmPin::MaxIPos, duty);
|
||||
self.channel_state(channel).pwm_limits.max_i_pos = max_i_pos.get::<ampere>();
|
||||
(duty * max, max)
|
||||
}
|
||||
|
||||
@ -460,6 +462,7 @@ impl Channels {
|
||||
let max = ElectricCurrent::new::<ampere>(3.0);
|
||||
let duty = (max_i_neg.min(MAX_TEC_I).max(ElectricCurrent::zero()) / max).get::<ratio>();
|
||||
let duty = self.set_pwm(channel, PwmPin::MaxINeg, duty);
|
||||
self.channel_state(channel).pwm_limits.max_i_neg = max_i_neg.get::<ampere>();
|
||||
(duty * max, max)
|
||||
}
|
||||
|
||||
@ -518,7 +521,7 @@ impl Channels {
|
||||
PwmSummary {
|
||||
channel,
|
||||
center: CenterPointJson(self.channel_state(channel).center.clone()),
|
||||
i_set: (self.get_i(channel), MAX_TEC_I).into(),
|
||||
i_set: (self.get_i(channel), self.channel_state(channel).i_set).into(),
|
||||
max_v: self.get_max_v(channel).into(),
|
||||
max_i_pos: self.get_max_i_pos(channel).into(),
|
||||
max_i_neg: self.get_max_i_neg(channel).into(),
|
||||
@ -606,12 +609,12 @@ impl Serialize for CenterPointJson {
|
||||
#[derive(Serialize)]
|
||||
pub struct PwmSummaryField<T: Serialize> {
|
||||
value: T,
|
||||
max: T,
|
||||
set_value: T,
|
||||
}
|
||||
|
||||
impl<T: Serialize> From<(T, T)> for PwmSummaryField<T> {
|
||||
fn from((value, max): (T, T)) -> Self {
|
||||
PwmSummaryField { value, max }
|
||||
fn from((value, set_value): (T, T)) -> Self {
|
||||
PwmSummaryField { value, set_value }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,17 +72,17 @@ impl ChannelConfig {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
struct PwmLimits {
|
||||
max_v: f64,
|
||||
max_i_pos: f64,
|
||||
max_i_neg: f64,
|
||||
pub struct PwmLimits {
|
||||
pub max_v: f64,
|
||||
pub max_i_pos: f64,
|
||||
pub max_i_neg: f64,
|
||||
}
|
||||
|
||||
impl PwmLimits {
|
||||
pub fn new(channels: &mut Channels, channel: usize) -> Self {
|
||||
let (max_v, _) = channels.get_max_v(channel);
|
||||
let (max_i_pos, _) = channels.get_max_i_pos(channel);
|
||||
let (max_i_neg, _) = channels.get_max_i_neg(channel);
|
||||
let (_, max_v) = channels.get_max_v(channel);
|
||||
let (_, max_i_pos) = channels.get_max_i_pos(channel);
|
||||
let (_, max_i_neg) = channels.get_max_i_neg(channel);
|
||||
PwmLimits {
|
||||
max_v: max_v.get::<volt>(),
|
||||
max_i_pos: max_i_pos.get::<ampere>(),
|
||||
|
@ -61,7 +61,7 @@ pub trait ChannelPins {
|
||||
type DacSync: OutputPin;
|
||||
type Shdn: OutputPin;
|
||||
type VRefPin;
|
||||
type ItecPin;
|
||||
type ITecPin;
|
||||
type DacFeedbackPin;
|
||||
type TecUMeasPin;
|
||||
}
|
||||
@ -76,7 +76,7 @@ impl ChannelPins for Channel0 {
|
||||
type DacSync = PE4<Output<PushPull>>;
|
||||
type Shdn = PE10<Output<PushPull>>;
|
||||
type VRefPin = Channel0VRef;
|
||||
type ItecPin = PA6<Analog>;
|
||||
type ITecPin = PA6<Analog>;
|
||||
type DacFeedbackPin = PA4<Analog>;
|
||||
type TecUMeasPin = PC2<Analog>;
|
||||
}
|
||||
@ -91,7 +91,7 @@ impl ChannelPins for Channel1 {
|
||||
type DacSync = PF6<Output<PushPull>>;
|
||||
type Shdn = PE15<Output<PushPull>>;
|
||||
type VRefPin = Channel1VRef;
|
||||
type ItecPin = PB0<Analog>;
|
||||
type ITecPin = PB0<Analog>;
|
||||
type DacFeedbackPin = PA5<Analog>;
|
||||
type TecUMeasPin = PC3<Analog>;
|
||||
}
|
||||
@ -108,7 +108,7 @@ pub struct ChannelPinSet<C: ChannelPins> {
|
||||
pub dac_sync: C::DacSync,
|
||||
pub shdn: C::Shdn,
|
||||
pub vref_pin: C::VRefPin,
|
||||
pub itec_pin: C::ItecPin,
|
||||
pub itec_pin: C::ITecPin,
|
||||
pub dac_feedback_pin: C::DacFeedbackPin,
|
||||
pub tec_u_meas_pin: C::TecUMeasPin,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user