add vref_pin
This commit is contained in:
parent
3d6e1f18a6
commit
70127491f6
|
@ -19,6 +19,7 @@ pub struct Channel<C: ChannelPins> {
|
|||
pub shdn: C::Shdn,
|
||||
/// stm32f4 integrated adc
|
||||
pub adc: C::Adc,
|
||||
pub vref_pin: C::VRefPin,
|
||||
pub itec_pin: C::ItecPin,
|
||||
/// feedback from `dac` output
|
||||
pub dac_feedback_pin: C::DacFeedbackPin,
|
||||
|
@ -36,6 +37,7 @@ impl<C: ChannelPins> Channel<C> {
|
|||
dac,
|
||||
shdn: pins.shdn,
|
||||
adc: pins.adc,
|
||||
vref_pin: pins.vref_pin,
|
||||
itec_pin: pins.itec_pin,
|
||||
dac_feedback_pin: pins.dac_feedback_pin,
|
||||
tec_u_meas_pin: pins.tec_u_meas_pin,
|
||||
|
|
|
@ -142,6 +142,28 @@ impl Channels {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_vref(&mut self, channel: usize) -> Volts {
|
||||
match channel {
|
||||
0 => {
|
||||
let sample = self.channel0.adc.convert(
|
||||
&self.channel0.vref_pin,
|
||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||
);
|
||||
let mv = self.channel0.adc.sample_to_millivolts(sample);
|
||||
Volts(mv as f64 / 1000.0)
|
||||
}
|
||||
1 => {
|
||||
let sample = self.channel1.adc.convert(
|
||||
&self.channel1.vref_pin,
|
||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||
);
|
||||
let mv = self.channel1.adc.sample_to_millivolts(sample);
|
||||
Volts(mv as f64 / 1000.0)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_tec_u_meas(&mut self, channel: usize) -> Volts {
|
||||
match channel {
|
||||
0 => {
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -43,7 +43,7 @@ mod command_parser;
|
|||
use command_parser::{Command, ShowCommand, PwmPin};
|
||||
mod timer;
|
||||
mod units;
|
||||
use units::{Amps, Ohms, Volts};
|
||||
use units::{Ohms, Volts};
|
||||
mod pid;
|
||||
mod steinhart_hart;
|
||||
mod channels;
|
||||
|
@ -143,19 +143,19 @@ fn main() -> ! {
|
|||
Command::Show(ShowCommand::Input) => {
|
||||
for channel in 0..CHANNELS {
|
||||
if let Some(adc_data) = channels.channel_state(channel).adc_data {
|
||||
let vref = channels.read_vref(channel);
|
||||
let dac_feedback = channels.read_dac_feedback(channel);
|
||||
let dac_i = dac_feedback / Ohms(5.0);
|
||||
|
||||
let itec = channels.read_itec(channel);
|
||||
let tec_i = (itec - Volts(1.5)) / Ohms(0.4);
|
||||
let tec_i = -(itec - Volts(1.5)) / Ohms(0.4);
|
||||
|
||||
let tec_u_meas = channels.read_tec_u_meas(channel);
|
||||
|
||||
let state = channels.channel_state(channel);
|
||||
let _ = writeln!(
|
||||
socket, "t={} raw{}=0x{:06X} dac_feedback={}/{} itec={} tec={} tec_u_meas={}",
|
||||
socket, "t={} adc_raw{}=0x{:06X} vref={} dac_feedback={} itec={} tec={} tec_u_meas={}",
|
||||
state.adc_time, channel, adc_data,
|
||||
dac_feedback, dac_i,
|
||||
vref, dac_feedback,
|
||||
itec, tec_i,
|
||||
tec_u_meas,
|
||||
);
|
||||
|
|
|
@ -27,6 +27,7 @@ pub trait ChannelPins {
|
|||
type DacSync: OutputPin;
|
||||
type Shdn: OutputPin;
|
||||
type Adc;
|
||||
type VRefPin;
|
||||
type ItecPin;
|
||||
type DacFeedbackPin;
|
||||
type TecUMeasPin;
|
||||
|
@ -37,6 +38,7 @@ impl ChannelPins for Channel0 {
|
|||
type DacSync = PE4<Output<PushPull>>;
|
||||
type Shdn = PE10<Output<PushPull>>;
|
||||
type Adc = Adc<ADC1>;
|
||||
type VRefPin = PA0<Analog>;
|
||||
type ItecPin = PA6<Analog>;
|
||||
type DacFeedbackPin = PA4<Analog>;
|
||||
type TecUMeasPin = PC2<Analog>;
|
||||
|
@ -47,6 +49,7 @@ impl ChannelPins for Channel1 {
|
|||
type DacSync = PF6<Output<PushPull>>;
|
||||
type Shdn = PE15<Output<PushPull>>;
|
||||
type Adc = Adc<ADC2>;
|
||||
type VRefPin = PA3<Analog>;
|
||||
type ItecPin = PB0<Analog>;
|
||||
type DacFeedbackPin = PA5<Analog>;
|
||||
type TecUMeasPin = PC3<Analog>;
|
||||
|
@ -65,6 +68,7 @@ pub struct ChannelPinSet<C: ChannelPins> {
|
|||
pub dac_sync: C::DacSync,
|
||||
pub shdn: C::Shdn,
|
||||
pub adc: C::Adc,
|
||||
pub vref_pin: C::VRefPin,
|
||||
pub itec_pin: C::ItecPin,
|
||||
pub dac_feedback_pin: C::DacFeedbackPin,
|
||||
pub tec_u_meas_pin: C::TecUMeasPin,
|
||||
|
@ -120,6 +124,7 @@ impl Pins {
|
|||
let _ = shdn0.set_low();
|
||||
let mut adc0 = Adc::adc1(adc1, true, Default::default());
|
||||
adc0.enable();
|
||||
let vref0_pin = gpioa.pa0.into_analog();
|
||||
let itec0_pin = gpioa.pa6.into_analog();
|
||||
let dac_feedback0_pin = gpioa.pa4.into_analog();
|
||||
let tec_u_meas0_pin = gpioc.pc2.into_analog();
|
||||
|
@ -128,6 +133,7 @@ impl Pins {
|
|||
dac_sync: dac0_sync,
|
||||
shdn: shdn0,
|
||||
adc: adc0,
|
||||
vref_pin: vref0_pin,
|
||||
itec_pin: itec0_pin,
|
||||
dac_feedback_pin: dac_feedback0_pin,
|
||||
tec_u_meas_pin: tec_u_meas0_pin,
|
||||
|
@ -141,6 +147,7 @@ impl Pins {
|
|||
let _ = shdn1.set_low();
|
||||
let mut adc1 = Adc::adc2(adc2, true, Default::default());
|
||||
adc1.enable();
|
||||
let vref1_pin = gpioa.pa3.into_analog();
|
||||
let itec1_pin = gpiob.pb0.into_analog();
|
||||
let dac_feedback1_pin = gpioa.pa5.into_analog();
|
||||
let tec_u_meas1_pin = gpioc.pc3.into_analog();
|
||||
|
@ -149,6 +156,7 @@ impl Pins {
|
|||
dac_sync: dac1_sync,
|
||||
shdn: shdn1,
|
||||
adc: adc1,
|
||||
vref_pin: vref1_pin,
|
||||
itec_pin: itec1_pin,
|
||||
dac_feedback_pin: dac_feedback1_pin,
|
||||
tec_u_meas_pin: tec_u_meas1_pin,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use core::{
|
||||
fmt,
|
||||
ops::{Add, Div, Sub},
|
||||
ops::{Add, Div, Neg, Sub},
|
||||
};
|
||||
|
||||
macro_rules! impl_add_sub {
|
||||
|
@ -18,6 +18,13 @@ macro_rules! impl_add_sub {
|
|||
$Type(self.0 - rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Neg for $Type {
|
||||
type Output = $Type;
|
||||
fn neg(self) -> $Type {
|
||||
$Type(-self.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue