forked from M-Labs/thermostat
Account for swapped current limits
This commit is contained in:
parent
ce4fb6090a
commit
1741acfc3b
@ -389,12 +389,20 @@ impl Channels {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_max_i_pos(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) {
|
pub fn get_max_i_pos(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) {
|
||||||
let duty = self.get_pwm(channel, PwmPin::MaxIPos);
|
let duty = if self.channel_state(channel).polarity_swapped {
|
||||||
|
self.get_pwm(channel, PwmPin::MaxINeg)
|
||||||
|
} else {
|
||||||
|
self.get_pwm(channel, PwmPin::MaxIPos)
|
||||||
|
};
|
||||||
(duty * MAX_TEC_I_DUTY_TO_CURRENT_RATE, MAX_TEC_I)
|
(duty * MAX_TEC_I_DUTY_TO_CURRENT_RATE, MAX_TEC_I)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_max_i_neg(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) {
|
pub fn get_max_i_neg(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) {
|
||||||
let duty = self.get_pwm(channel, PwmPin::MaxINeg);
|
let duty = if self.channel_state(channel).polarity_swapped {
|
||||||
|
self.get_pwm(channel, PwmPin::MaxIPos)
|
||||||
|
} else {
|
||||||
|
self.get_pwm(channel, PwmPin::MaxINeg)
|
||||||
|
};
|
||||||
(duty * MAX_TEC_I_DUTY_TO_CURRENT_RATE, MAX_TEC_I)
|
(duty * MAX_TEC_I_DUTY_TO_CURRENT_RATE, MAX_TEC_I)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,14 +458,22 @@ impl Channels {
|
|||||||
pub fn set_max_i_pos(&mut self, channel: usize, max_i_pos: ElectricCurrent) -> (ElectricCurrent, ElectricCurrent) {
|
pub fn set_max_i_pos(&mut self, channel: usize, max_i_pos: ElectricCurrent) -> (ElectricCurrent, ElectricCurrent) {
|
||||||
let max = ElectricCurrent::new::<ampere>(3.0);
|
let max = ElectricCurrent::new::<ampere>(3.0);
|
||||||
let duty = (max_i_pos.min(MAX_TEC_I).max(ElectricCurrent::zero()) / MAX_TEC_I_DUTY_TO_CURRENT_RATE).get::<ratio>();
|
let duty = (max_i_pos.min(MAX_TEC_I).max(ElectricCurrent::zero()) / MAX_TEC_I_DUTY_TO_CURRENT_RATE).get::<ratio>();
|
||||||
let duty = self.set_pwm(channel, PwmPin::MaxIPos, duty);
|
let duty = if self.channel_state(channel).polarity_swapped {
|
||||||
|
self.set_pwm(channel, PwmPin::MaxINeg, duty)
|
||||||
|
} else {
|
||||||
|
self.set_pwm(channel, PwmPin::MaxIPos, duty)
|
||||||
|
};
|
||||||
(duty * MAX_TEC_I_DUTY_TO_CURRENT_RATE, max)
|
(duty * MAX_TEC_I_DUTY_TO_CURRENT_RATE, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_max_i_neg(&mut self, channel: usize, max_i_neg: ElectricCurrent) -> (ElectricCurrent, ElectricCurrent) {
|
pub fn set_max_i_neg(&mut self, channel: usize, max_i_neg: ElectricCurrent) -> (ElectricCurrent, ElectricCurrent) {
|
||||||
let max = ElectricCurrent::new::<ampere>(3.0);
|
let max = ElectricCurrent::new::<ampere>(3.0);
|
||||||
let duty = (max_i_neg.min(MAX_TEC_I).max(ElectricCurrent::zero()) / MAX_TEC_I_DUTY_TO_CURRENT_RATE).get::<ratio>();
|
let duty = (max_i_neg.min(MAX_TEC_I).max(ElectricCurrent::zero()) / MAX_TEC_I_DUTY_TO_CURRENT_RATE).get::<ratio>();
|
||||||
let duty = self.set_pwm(channel, PwmPin::MaxINeg, duty);
|
let duty = if self.channel_state(channel).polarity_swapped {
|
||||||
|
self.set_pwm(channel, PwmPin::MaxIPos, duty)
|
||||||
|
} else {
|
||||||
|
self.set_pwm(channel, PwmPin::MaxINeg, duty)
|
||||||
|
};
|
||||||
(duty * MAX_TEC_I_DUTY_TO_CURRENT_RATE, max)
|
(duty * MAX_TEC_I_DUTY_TO_CURRENT_RATE, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user