Change temperature handling

Headroom goes *above* the limit, not below. Replace the max safe temp
thing with a window delta below the limit where attenuation begins.

Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
Hector Martin 2023-10-29 00:26:37 +09:00
parent b12c8b69da
commit 21023ec426
2 changed files with 10 additions and 10 deletions

View file

@ -82,7 +82,7 @@ impl Blackbox {
sample_rate: self.blocks[0].sample_rate, sample_rate: self.blocks[0].sample_rate,
channels: self.globals.channels, channels: self.globals.channels,
t_ambient: self.globals.t_ambient, t_ambient: self.globals.t_ambient,
t_safe_max: self.globals.t_safe_max, t_window: self.globals.t_window,
t_hysteresis: self.globals.t_hysteresis, t_hysteresis: self.globals.t_hysteresis,
blocks: null blocks: null
}; };

View file

@ -186,7 +186,7 @@ pub struct Globals {
pub channels: usize, pub channels: usize,
pub period: usize, pub period: usize,
pub t_ambient: f32, pub t_ambient: f32,
pub t_safe_max: f32, pub t_window: f32,
pub t_hysteresis: f32, pub t_hysteresis: f32,
pub ctl_vsense: String, pub ctl_vsense: String,
pub ctl_isense: String, pub ctl_isense: String,
@ -201,7 +201,7 @@ impl Globals {
channels: helpers::parse_int(config, "Globals", "channels"), channels: helpers::parse_int(config, "Globals", "channels"),
period: helpers::parse_int(config, "Globals", "period"), period: helpers::parse_int(config, "Globals", "period"),
t_ambient: helpers::parse_float(config, "Globals", "t_ambient"), t_ambient: helpers::parse_float(config, "Globals", "t_ambient"),
t_safe_max: helpers::parse_float(config, "Globals", "t_safe_max"), t_window: helpers::parse_float(config, "Globals", "t_window"),
t_hysteresis: helpers::parse_float(config, "Globals", "t_hysteresis"), t_hysteresis: helpers::parse_float(config, "Globals", "t_hysteresis"),
ctl_vsense: helpers::parse_string(config, "Controls", "vsense"), ctl_vsense: helpers::parse_string(config, "Controls", "vsense"),
ctl_isense: helpers::parse_string(config, "Controls", "isense"), ctl_isense: helpers::parse_string(config, "Controls", "isense"),
@ -286,16 +286,16 @@ impl Speaker {
s.t_coil = if cold_boot { s.t_coil = if cold_boot {
// Assume warm but not warm enough to limit // Assume warm but not warm enough to limit
globals.t_safe_max as f64 - 1f64 (new_speaker.t_limit - globals.t_window) as f64 - 1f64
} else { } else {
// Worst case startup assumption // Worst case startup assumption
(new_speaker.t_limit - new_speaker.t_headroom) as f64 new_speaker.t_limit as f64
}; };
s.t_magnet = globals.t_ambient as f64 s.t_magnet = globals.t_ambient as f64
+ (s.t_coil - globals.t_ambient as f64) + (s.t_coil - globals.t_ambient as f64)
* (new_speaker.tr_magnet / (new_speaker.tr_magnet + new_speaker.tr_coil)) as f64; * (new_speaker.tr_magnet / (new_speaker.tr_magnet + new_speaker.tr_coil)) as f64;
let max_dt = new_speaker.t_limit - new_speaker.t_headroom - globals.t_ambient; let max_dt = new_speaker.t_limit - globals.t_ambient;
let max_pwr = max_dt / (new_speaker.tr_magnet + new_speaker.tr_coil); let max_pwr = max_dt / (new_speaker.tr_magnet + new_speaker.tr_coil);
let amp_gain = new_speaker.alsa_iface.get_amp_gain(ctl); let amp_gain = new_speaker.alsa_iface.get_amp_gain(ctl);
@ -307,7 +307,7 @@ impl Speaker {
assert!(new_speaker.is_chan < globals.channels); assert!(new_speaker.is_chan < globals.channels);
assert!(new_speaker.vs_chan < globals.channels); assert!(new_speaker.vs_chan < globals.channels);
assert!(new_speaker.t_limit - new_speaker.t_headroom > globals.t_safe_max); assert!(new_speaker.t_limit - globals.t_window > globals.t_ambient);
info!(" Group: {}", new_speaker.group); info!(" Group: {}", new_speaker.group);
info!(" Max temperature: {:.1} °C", new_speaker.t_limit); info!(" Max temperature: {:.1} °C", new_speaker.t_limit);
@ -341,13 +341,13 @@ impl Speaker {
s.t_coil = t_coil_target * alpha_coil + s.t_coil * (1. - alpha_coil); s.t_coil = t_coil_target * alpha_coil + s.t_coil * (1. - alpha_coil);
s.t_magnet = t_magnet_target * alpha_magnet + s.t_magnet * (1. - alpha_magnet); s.t_magnet = t_magnet_target * alpha_magnet + s.t_magnet * (1. - alpha_magnet);
if s.t_coil > self.t_limit as f64 { if s.t_coil > (self.t_limit + self.t_headroom) as f64 {
panic!( panic!(
"{}: Coil temperature limit exceeded ({} > {})", "{}: Coil temperature limit exceeded ({} > {})",
self.name, s.t_coil, self.t_limit self.name, s.t_coil, self.t_limit
); );
} }
if s.t_magnet > self.t_limit as f64 { if s.t_magnet > (self.t_limit + self.t_headroom) as f64 {
panic!( panic!(
"{}: Magnet temperature limit exceeded ({} > {})", "{}: Magnet temperature limit exceeded ({} > {})",
self.name, s.t_magnet, self.t_limit self.name, s.t_magnet, self.t_limit
@ -371,7 +371,7 @@ impl Speaker {
let temp = s.t_coil_hyst.max(s.t_magnet_hyst); let temp = s.t_coil_hyst.max(s.t_magnet_hyst);
let reduction = let reduction =
(temp - self.g.t_safe_max) / (self.t_limit - self.t_headroom - self.g.t_safe_max); (temp - (self.t_limit - self.g.t_window)) / self.g.t_window;
let gain = s.min_gain * reduction.max(0.); let gain = s.min_gain * reduction.max(0.);
s.gain = gain; s.gain = gain;