Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
391fa4adc8 | |||
5556ced41f |
31
README.md
31
README.md
@ -255,21 +255,18 @@ Use the bare `report` command to obtain a single report. Enable
|
||||
continuous reporting with `report mode on`. Reports are JSON objects
|
||||
with the following keys.
|
||||
|
||||
| Key | Unit | Description |
|
||||
| --- | :---: | --- |
|
||||
| `channel` | Integer | Channel `0`, or `1` |
|
||||
| `time` | Seconds | Temperature measurement time |
|
||||
| `adc` | Volts | AD7172 input |
|
||||
| `sens` | Ohms | Thermistor resistance derived from `adc` |
|
||||
| `temperature` | Degrees Celsius | Steinhart-Hart conversion result derived from `sens` |
|
||||
| `pid_engaged` | Boolean | `true` if in closed-loop mode |
|
||||
| `i_set` | Amperes | TEC output current |
|
||||
| `dac_value` | Volts | AD5680 output derived from `i_set` |
|
||||
| `dac_feedback` | Volts | ADC measurement of the AD5680 output |
|
||||
| `i_tec` | Volts | MAX1968 TEC current monitor |
|
||||
| `tec_i` | Amperes | TEC output current feedback derived from `i_tec` |
|
||||
| `tec_u_meas` | Volts | Measurement of the voltage across the TEC |
|
||||
| `pid_output` | Amperes | PID control output |
|
||||
| Key | Unit | Description |
|
||||
| --- | :---: | --- |
|
||||
| `channel` | Integer | Channel `0`, or `1` |
|
||||
| `time` | Seconds | Report timestamp (since thermostat reset) |
|
||||
| `interval` | Seconds | ADC Sampling Interval |
|
||||
| `sens` | Ohms | Thermistor resistance |
|
||||
| `temperature` | Degrees Celsius | Temperature derived from thermistor resistance |
|
||||
| `pid_engaged` | Boolean | `true` if in closed-loop mode |
|
||||
| `pid_output` | Amperes | PID control output |
|
||||
| `i_set` | Amperes | Set TEC output current |
|
||||
| `i_meas` | Amperes | Measured current passing through TEC |
|
||||
| `v_meas` | Volts | Measured voltage across TEC |
|
||||
|
||||
Note: With Thermostat v2 and below, the voltage and current readouts `i_tec` and `tec_i` are noisy without the hardware fix shown in [this PR][https://git.m-labs.hk/M-Labs/thermostat/pulls/105].
|
||||
|
||||
@ -280,10 +277,10 @@ The thermostat implements a PID control loop for each of the TEC channels, more
|
||||
## Fan control
|
||||
|
||||
Fan control commands are available for thermostat revisions with an integrated fan system:
|
||||
1. `fan` - show fan stats: `fan_pwm`, `abs_max_tec_i`, `auto_mode`, `k_a`, `k_b`, `k_c`.
|
||||
1. `fan` - show fan stats: `fan_pwm`, `max_abs_i_meas`, `auto_mode`, `k_a`, `k_b`, `k_c`.
|
||||
2. `fan auto` - enable auto speed controller mode, where fan speed is controlled by the fan curve `fcurve`.
|
||||
3. `fan <value>` - set the fan power with the value from `1` to `100` and disable auto mode. There is no way to completely disable the fan.
|
||||
Please note that power doesn't correlate with the actual speed linearly.
|
||||
4. `fcurve <a> <b> <c>` - set coefficients of the controlling curve `a*x^2 + b*x + c`, where `x` is `abs_max_tec_i/MAX_TEC_I`, a normalized value in range [0,1],
|
||||
4. `fcurve <a> <b> <c>` - set coefficients of the controlling curve `a*x^2 + b*x + c`, where `x` is `max_abs_i_meas/MAX_TEC_I`, a normalized value in range [0,1],
|
||||
i.e. the (linear) proportion of current output capacity used, on the channel with the largest current flow. The controlling curve is also clamped to [0,1].
|
||||
5. `fcurve default` - restore fan curve coefficients to defaults: `a = 1.0, b = 0.0, c = 0.0`.
|
||||
|
@ -405,13 +405,13 @@ impl Channels {
|
||||
(duty * max, MAX_TEC_I)
|
||||
}
|
||||
|
||||
// Get current passing through TEC
|
||||
pub fn get_tec_i(&mut self, channel: usize) -> ElectricCurrent {
|
||||
// Measure current passing through TEC
|
||||
pub fn get_i_meas(&mut self, channel: usize) -> ElectricCurrent {
|
||||
(self.adc_read(channel, PinsAdcReadTarget::ITec, 16) - self.adc_read(channel, PinsAdcReadTarget::VREF, 16)) / ElectricalResistance::new::<ohm>(0.4)
|
||||
}
|
||||
|
||||
// Get voltage across TEC
|
||||
pub fn get_tec_v(&mut self, channel: usize) -> ElectricPotential {
|
||||
// Measure voltage across TEC
|
||||
pub fn get_v_meas(&mut self, channel: usize) -> ElectricPotential {
|
||||
(self.adc_read(channel, PinsAdcReadTarget::VTec, 16) - ElectricPotential::new::<volt>(1.5)) * 4.0
|
||||
}
|
||||
|
||||
@ -465,27 +465,22 @@ impl Channels {
|
||||
|
||||
fn report(&mut self, channel: usize) -> Report {
|
||||
let i_set = self.get_i(channel);
|
||||
let i_tec = self.adc_read(channel, PinsAdcReadTarget::ITec, 16);
|
||||
let tec_i = self.get_tec_i(channel);
|
||||
let dac_value = self.get_dac(channel);
|
||||
let i_meas = self.get_i_meas(channel);
|
||||
let v_meas = self.get_v_meas(channel);
|
||||
let state = self.channel_state(channel);
|
||||
let pid_output = ElectricCurrent::new::<ampere>(state.pid.y1);
|
||||
Report {
|
||||
channel,
|
||||
time: state.get_adc_time(),
|
||||
interval: state.get_adc_interval(),
|
||||
adc: state.get_adc(),
|
||||
sens: state.get_sens(),
|
||||
temperature: state.get_temperature()
|
||||
.map(|temperature| temperature.get::<degree_celsius>()),
|
||||
pid_engaged: state.pid_engaged,
|
||||
i_set,
|
||||
dac_value,
|
||||
dac_feedback: self.adc_read(channel, PinsAdcReadTarget::DacVfb, 1),
|
||||
i_tec,
|
||||
tec_i,
|
||||
tec_u_meas: self.get_tec_v(channel),
|
||||
pid_output,
|
||||
i_set,
|
||||
i_meas,
|
||||
v_meas,
|
||||
}
|
||||
}
|
||||
|
||||
@ -560,9 +555,9 @@ impl Channels {
|
||||
serde_json_core::to_vec(&summaries)
|
||||
}
|
||||
|
||||
pub fn current_abs_max_tec_i(&mut self) -> ElectricCurrent {
|
||||
pub fn max_abs_i_meas(&mut self) -> ElectricCurrent {
|
||||
(0..CHANNELS)
|
||||
.map(|channel| self.get_tec_i(channel).abs())
|
||||
.map(|channel| self.get_i_meas(channel).abs())
|
||||
.max_by(|a, b| a.partial_cmp(b).unwrap_or(core::cmp::Ordering::Equal))
|
||||
.unwrap()
|
||||
}
|
||||
@ -573,17 +568,13 @@ pub struct Report {
|
||||
channel: usize,
|
||||
time: Time,
|
||||
interval: Time,
|
||||
adc: Option<ElectricPotential>,
|
||||
sens: Option<ElectricalResistance>,
|
||||
temperature: Option<f64>,
|
||||
pid_engaged: bool,
|
||||
i_set: ElectricCurrent,
|
||||
dac_value: ElectricPotential,
|
||||
dac_feedback: ElectricPotential,
|
||||
i_tec: ElectricPotential,
|
||||
tec_i: ElectricCurrent,
|
||||
tec_u_meas: ElectricPotential,
|
||||
pid_output: ElectricCurrent,
|
||||
i_set: ElectricCurrent,
|
||||
i_meas: ElectricCurrent,
|
||||
v_meas: ElectricPotential,
|
||||
}
|
||||
|
||||
pub struct CenterPointJson(CenterPoint);
|
||||
|
@ -27,7 +27,7 @@ pub struct FanCtrl {
|
||||
k_a: f32,
|
||||
k_b: f32,
|
||||
k_c: f32,
|
||||
abs_max_tec_i: f32,
|
||||
max_abs_i_meas: f32,
|
||||
hw_settings: HWSettings,
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ impl FanCtrl {
|
||||
k_a: hw_settings.fan_k_a,
|
||||
k_b: hw_settings.fan_k_b,
|
||||
k_c: hw_settings.fan_k_c,
|
||||
abs_max_tec_i: 0f32,
|
||||
max_abs_i_meas: 0f32,
|
||||
hw_settings,
|
||||
};
|
||||
if fan_ctrl.fan_auto {
|
||||
@ -51,10 +51,10 @@ impl FanCtrl {
|
||||
fan_ctrl
|
||||
}
|
||||
|
||||
pub fn cycle(&mut self, abs_max_tec_i: ElectricCurrent) {
|
||||
self.abs_max_tec_i = abs_max_tec_i.get::<ampere>() as f32;
|
||||
pub fn cycle(&mut self, max_abs_i_meas: ElectricCurrent) {
|
||||
self.max_abs_i_meas = max_abs_i_meas.get::<ampere>() as f32;
|
||||
if self.fan_auto && self.hw_settings.fan_available {
|
||||
let scaled_current = self.abs_max_tec_i / MAX_TEC_I.get::<ampere>() as f32;
|
||||
let scaled_current = self.max_abs_i_meas / MAX_TEC_I.get::<ampere>() 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);
|
||||
@ -65,7 +65,7 @@ impl FanCtrl {
|
||||
if self.hw_settings.fan_available {
|
||||
let summary = FanSummary {
|
||||
fan_pwm: self.get_pwm(),
|
||||
abs_max_tec_i: self.abs_max_tec_i,
|
||||
abs_max_tec_i: self.max_abs_i_meas,
|
||||
auto_mode: self.fan_auto,
|
||||
k_a: self.k_a,
|
||||
k_b: self.k_b,
|
||||
|
@ -185,7 +185,7 @@ fn main() -> ! {
|
||||
server.for_each(|_, session| session.set_report_pending(channel.into()));
|
||||
}
|
||||
|
||||
fan_ctrl.cycle(channels.current_abs_max_tec_i());
|
||||
fan_ctrl.cycle(channels.max_abs_i_meas());
|
||||
|
||||
if channels.pid_engaged() {
|
||||
leds.g3.on();
|
||||
|
Loading…
Reference in New Issue
Block a user