From 1157b73f7f453b065368952c2cbaa8ea4df5043e Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 17 Sep 2020 01:00:47 +0200 Subject: [PATCH] max_i_pos/max_i_neg: remove vref from calculation full duty pwm is at vref already --- src/channels.rs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/channels.rs b/src/channels.rs index 02a6772..39b9cb5 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -318,22 +318,21 @@ impl Channels { pub fn get_max_v(&mut self, channel: usize) -> (ElectricPotential, ElectricPotential) { let vref = self.channel_state(channel).vref; + let max = 4.0 * vref; let duty = self.get_pwm(channel, PwmPin::MaxV); - (duty * 4.0 * vref, 4.0 * vref) + (duty * max, max) } pub fn get_max_i_pos(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) { - let vref = self.channel_state(channel).vref; - let scale = vref / ElectricPotential::new::(3.0) / ElectricCurrent::new::(1.0); + let max = ElectricCurrent::new::(3.0); let duty = self.get_pwm(channel, PwmPin::MaxIPos); - (duty / scale, 1.0 / scale) + (duty * max, max) } pub fn get_max_i_neg(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) { - let vref = self.channel_state(channel).vref; - let scale = vref / ElectricPotential::new::(3.0) / ElectricCurrent::new::(1.0); + let max = ElectricCurrent::new::(3.0); let duty = self.get_pwm(channel, PwmPin::MaxINeg); - (duty / scale, 1.0 / scale) + (duty * max, max) } fn set_pwm(&mut self, channel: usize, pin: PwmPin, duty: f64) -> f64 { @@ -365,24 +364,23 @@ impl Channels { pub fn set_max_v(&mut self, channel: usize, max_v: ElectricPotential) -> (ElectricPotential, ElectricPotential) { let vref = self.channel_state(channel).vref; - let duty = (max_v / 4.0 / vref).get::(); + let max = 4.0 * vref; + let duty = (max_v / max).get::(); let duty = self.set_pwm(channel, PwmPin::MaxV, duty); - (duty * 4.0 * vref, 4.0 * vref) + (duty * max, max) } pub fn set_max_i_pos(&mut self, channel: usize, max_i_pos: ElectricCurrent) -> (ElectricCurrent, ElectricCurrent) { - let vref = self.channel_state(channel).vref; - let scale = vref / ElectricPotential::new::(3.0) / ElectricCurrent::new::(1.0); - let duty = (max_i_pos * scale).get::(); + let max = ElectricCurrent::new::(3.0); + let duty = (max_i_pos / max).get::(); let duty = self.set_pwm(channel, PwmPin::MaxIPos, duty); - (duty / scale, 1.0 / scale) + (duty * max, max) } pub fn set_max_i_neg(&mut self, channel: usize, max_i_neg: ElectricCurrent) -> (ElectricCurrent, ElectricCurrent) { - let vref = self.channel_state(channel).vref; - let scale = vref / ElectricPotential::new::(3.0) / ElectricCurrent::new::(1.0); - let duty = (max_i_neg * scale).get::(); + let max = ElectricCurrent::new::(3.0); + let duty = (max_i_neg / max).get::(); let duty = self.set_pwm(channel, PwmPin::MaxINeg, duty); - (duty / scale, 1.0 / scale) + (duty * max, max) } }