Compare commits

...

2 Commits

Author SHA1 Message Date
Astro 94e0525002 tec_u_meas: subtract vref offset 2020-09-17 01:20:47 +02:00
Astro 1157b73f7f max_i_pos/max_i_neg: remove vref from calculation
full duty pwm is at vref already
2020-09-17 01:03:57 +02:00
2 changed files with 17 additions and 19 deletions

View File

@ -318,22 +318,21 @@ impl Channels {
pub fn get_max_v(&mut self, channel: usize) -> (ElectricPotential, ElectricPotential) { pub fn get_max_v(&mut self, channel: usize) -> (ElectricPotential, ElectricPotential) {
let vref = self.channel_state(channel).vref; let vref = self.channel_state(channel).vref;
let max = 4.0 * vref;
let duty = self.get_pwm(channel, PwmPin::MaxV); 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) { pub fn get_max_i_pos(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) {
let vref = self.channel_state(channel).vref; let max = ElectricCurrent::new::<ampere>(3.0);
let scale = vref / ElectricPotential::new::<volt>(3.0) / ElectricCurrent::new::<ampere>(1.0);
let duty = self.get_pwm(channel, PwmPin::MaxIPos); 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) { pub fn get_max_i_neg(&mut self, channel: usize) -> (ElectricCurrent, ElectricCurrent) {
let vref = self.channel_state(channel).vref; let max = ElectricCurrent::new::<ampere>(3.0);
let scale = vref / ElectricPotential::new::<volt>(3.0) / ElectricCurrent::new::<ampere>(1.0);
let duty = self.get_pwm(channel, PwmPin::MaxINeg); 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 { 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) { pub fn set_max_v(&mut self, channel: usize, max_v: ElectricPotential) -> (ElectricPotential, ElectricPotential) {
let vref = self.channel_state(channel).vref; let vref = self.channel_state(channel).vref;
let duty = (max_v / 4.0 / vref).get::<ratio>(); let max = 4.0 * vref;
let duty = (max_v / max).get::<ratio>();
let duty = self.set_pwm(channel, PwmPin::MaxV, duty); 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) { pub fn set_max_i_pos(&mut self, channel: usize, max_i_pos: ElectricCurrent) -> (ElectricCurrent, ElectricCurrent) {
let vref = self.channel_state(channel).vref; let max = ElectricCurrent::new::<ampere>(3.0);
let scale = vref / ElectricPotential::new::<volt>(3.0) / ElectricCurrent::new::<ampere>(1.0); let duty = (max_i_pos / max).get::<ratio>();
let duty = (max_i_pos * scale).get::<ratio>();
let duty = self.set_pwm(channel, PwmPin::MaxIPos, duty); 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) { pub fn set_max_i_neg(&mut self, channel: usize, max_i_neg: ElectricCurrent) -> (ElectricCurrent, ElectricCurrent) {
let vref = self.channel_state(channel).vref; let max = ElectricCurrent::new::<ampere>(3.0);
let scale = vref / ElectricPotential::new::<volt>(3.0) / ElectricCurrent::new::<ampere>(1.0); let duty = (max_i_neg / max).get::<ratio>();
let duty = (max_i_neg * scale).get::<ratio>();
let duty = self.set_pwm(channel, PwmPin::MaxINeg, duty); let duty = self.set_pwm(channel, PwmPin::MaxINeg, duty);
(duty / scale, 1.0 / scale) (duty * max, max)
} }
} }

View File

@ -187,7 +187,7 @@ fn main() -> ! {
vref.into_format_args(volt, Abbreviation), dac_feedback.into_format_args(volt, Abbreviation), vref.into_format_args(volt, Abbreviation), dac_feedback.into_format_args(volt, Abbreviation),
itec.into_format_args(volt, Abbreviation), tec_i.into_format_args(ampere, Abbreviation), itec.into_format_args(volt, Abbreviation), tec_i.into_format_args(ampere, Abbreviation),
tec_u_meas.into_format_args(volt, Abbreviation), tec_u_meas.into_format_args(volt, Abbreviation),
(tec_u_meas / tec_i).into_format_args(ohm, Abbreviation), ((tec_u_meas - vref) / tec_i).into_format_args(ohm, Abbreviation),
); );
} else { } else {
let _ = writeln!(socket, "channel {}: no adc input", channel); let _ = writeln!(socket, "channel {}: no adc input", channel);
@ -269,7 +269,7 @@ fn main() -> ! {
match (state.get_adc(), state.get_sens(), state.get_temperature()) { match (state.get_adc(), state.get_sens(), state.get_temperature()) {
(Some(adc), Some(sens), Some(temp)) => { (Some(adc), Some(sens), Some(temp)) => {
let _ = writeln!( let _ = writeln!(
socket, "- adc={:.6} r={:.0} temp{}={:.3}K", socket, "- adc={:.6} r={:.0} temp{}={:.3}",
adc.into_format_args(volt, Abbreviation), adc.into_format_args(volt, Abbreviation),
sens.into_format_args(ohm, Abbreviation), sens.into_format_args(ohm, Abbreviation),
channel, channel,