add tec_u_meas
This commit is contained in:
parent
28a71d34d7
commit
3d6e1f18a6
@ -22,6 +22,7 @@ pub struct Channel<C: ChannelPins> {
|
|||||||
pub itec_pin: C::ItecPin,
|
pub itec_pin: C::ItecPin,
|
||||||
/// feedback from `dac` output
|
/// feedback from `dac` output
|
||||||
pub dac_feedback_pin: C::DacFeedbackPin,
|
pub dac_feedback_pin: C::DacFeedbackPin,
|
||||||
|
pub tec_u_meas_pin: C::TecUMeasPin,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ChannelPins> Channel<C> {
|
impl<C: ChannelPins> Channel<C> {
|
||||||
@ -37,6 +38,7 @@ impl<C: ChannelPins> Channel<C> {
|
|||||||
adc: pins.adc,
|
adc: pins.adc,
|
||||||
itec_pin: pins.itec_pin,
|
itec_pin: pins.itec_pin,
|
||||||
dac_feedback_pin: pins.dac_feedback_pin,
|
dac_feedback_pin: pins.dac_feedback_pin,
|
||||||
|
tec_u_meas_pin: pins.tec_u_meas_pin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,12 @@ use crate::{
|
|||||||
|
|
||||||
pub const CHANNELS: usize = 2;
|
pub const CHANNELS: usize = 2;
|
||||||
|
|
||||||
|
// TODO: -pub
|
||||||
pub struct Channels {
|
pub struct Channels {
|
||||||
pub channel0: Channel<Channel0>,
|
pub channel0: Channel<Channel0>,
|
||||||
pub channel1: Channel<Channel1>,
|
pub channel1: Channel<Channel1>,
|
||||||
pub adc: ad7172::Adc<pins::AdcSpi, pins::AdcNss>,
|
pub adc: ad7172::Adc<pins::AdcSpi, pins::AdcNss>,
|
||||||
|
pub tec_u_meas_adc: pins::TecUMeasAdc,
|
||||||
pub pwm: pins::PwmPins,
|
pub pwm: pins::PwmPins,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,6 +23,7 @@ impl Channels {
|
|||||||
pub fn new(pins: pins::Pins) -> Self {
|
pub fn new(pins: pins::Pins) -> Self {
|
||||||
let channel0 = Channel::new(pins.channel0);
|
let channel0 = Channel::new(pins.channel0);
|
||||||
let channel1 = Channel::new(pins.channel1);
|
let channel1 = Channel::new(pins.channel1);
|
||||||
|
let tec_u_meas_adc = pins.tec_u_meas_adc;
|
||||||
let pwm = pins.pwm;
|
let pwm = pins.pwm;
|
||||||
|
|
||||||
let mut adc = ad7172::Adc::new(pins.adc_spi, pins.adc_nss).unwrap();
|
let mut adc = ad7172::Adc::new(pins.adc_spi, pins.adc_nss).unwrap();
|
||||||
@ -43,7 +46,7 @@ impl Channels {
|
|||||||
adc.setup_channel(1, ad7172::Input::Ain2, ad7172::Input::Ain3).unwrap();
|
adc.setup_channel(1, ad7172::Input::Ain2, ad7172::Input::Ain3).unwrap();
|
||||||
adc.start_continuous_conversion().unwrap();
|
adc.start_continuous_conversion().unwrap();
|
||||||
|
|
||||||
Channels { channel0, channel1, adc, pwm }
|
Channels { channel0, channel1, adc, tec_u_meas_adc, pwm }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn channel_state<I: Into<usize>>(&mut self, channel: I) -> &mut ChannelState {
|
pub fn channel_state<I: Into<usize>>(&mut self, channel: I) -> &mut ChannelState {
|
||||||
@ -138,4 +141,26 @@ impl Channels {
|
|||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read_tec_u_meas(&mut self, channel: usize) -> Volts {
|
||||||
|
match channel {
|
||||||
|
0 => {
|
||||||
|
let sample = self.tec_u_meas_adc.convert(
|
||||||
|
&self.channel0.tec_u_meas_pin,
|
||||||
|
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||||
|
);
|
||||||
|
let mv = self.tec_u_meas_adc.sample_to_millivolts(sample);
|
||||||
|
Volts(mv as f64 / 1000.0)
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
let sample = self.tec_u_meas_adc.convert(
|
||||||
|
&self.channel1.tec_u_meas_pin,
|
||||||
|
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||||
|
);
|
||||||
|
let mv = self.tec_u_meas_adc.sample_to_millivolts(sample);
|
||||||
|
Volts(mv as f64 / 1000.0)
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ fn main() -> ! {
|
|||||||
clocks, dp.TIM1, dp.TIM3,
|
clocks, dp.TIM1, dp.TIM3,
|
||||||
dp.GPIOA, dp.GPIOB, dp.GPIOC, dp.GPIOE, dp.GPIOF, dp.GPIOG,
|
dp.GPIOA, dp.GPIOB, dp.GPIOC, dp.GPIOE, dp.GPIOF, dp.GPIOG,
|
||||||
dp.SPI2, dp.SPI4, dp.SPI5,
|
dp.SPI2, dp.SPI4, dp.SPI5,
|
||||||
dp.ADC1, dp.ADC2,
|
dp.ADC1, dp.ADC2, dp.ADC3,
|
||||||
);
|
);
|
||||||
let mut channels = Channels::new(pins);
|
let mut channels = Channels::new(pins);
|
||||||
timer::setup(cp.SYST, clocks);
|
timer::setup(cp.SYST, clocks);
|
||||||
@ -149,12 +149,15 @@ fn main() -> ! {
|
|||||||
let itec = channels.read_itec(channel);
|
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 state = channels.channel_state(channel);
|
||||||
let _ = writeln!(
|
let _ = writeln!(
|
||||||
socket, "t={} raw{}=0x{:06X} dac_feedback={}/{} itec={} tec={}",
|
socket, "t={} raw{}=0x{:06X} dac_feedback={}/{} itec={} tec={} tec_u_meas={}",
|
||||||
state.adc_time, channel, adc_data,
|
state.adc_time, channel, adc_data,
|
||||||
dac_feedback, dac_i,
|
dac_feedback, dac_i,
|
||||||
itec, tec_i,
|
itec, tec_i,
|
||||||
|
tec_u_meas,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
src/pins.rs
17
src/pins.rs
@ -16,7 +16,7 @@ use stm32f4xx_hal::{
|
|||||||
rcc::Clocks,
|
rcc::Clocks,
|
||||||
pwm::{self, PwmChannels},
|
pwm::{self, PwmChannels},
|
||||||
spi::{Spi, NoMiso},
|
spi::{Spi, NoMiso},
|
||||||
stm32::{ADC1, ADC2, GPIOA, GPIOB, GPIOC, GPIOE, GPIOF, GPIOG, SPI2, SPI4, SPI5, TIM1, TIM3},
|
stm32::{ADC1, ADC2, ADC3, GPIOA, GPIOB, GPIOC, GPIOE, GPIOF, GPIOG, SPI2, SPI4, SPI5, TIM1, TIM3},
|
||||||
time::U32Ext,
|
time::U32Ext,
|
||||||
};
|
};
|
||||||
use crate::channel::{Channel0, Channel1};
|
use crate::channel::{Channel0, Channel1};
|
||||||
@ -29,6 +29,7 @@ pub trait ChannelPins {
|
|||||||
type Adc;
|
type Adc;
|
||||||
type ItecPin;
|
type ItecPin;
|
||||||
type DacFeedbackPin;
|
type DacFeedbackPin;
|
||||||
|
type TecUMeasPin;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChannelPins for Channel0 {
|
impl ChannelPins for Channel0 {
|
||||||
@ -38,6 +39,7 @@ impl ChannelPins for Channel0 {
|
|||||||
type Adc = Adc<ADC1>;
|
type Adc = Adc<ADC1>;
|
||||||
type ItecPin = PA6<Analog>;
|
type ItecPin = PA6<Analog>;
|
||||||
type DacFeedbackPin = PA4<Analog>;
|
type DacFeedbackPin = PA4<Analog>;
|
||||||
|
type TecUMeasPin = PC2<Analog>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChannelPins for Channel1 {
|
impl ChannelPins for Channel1 {
|
||||||
@ -47,6 +49,7 @@ impl ChannelPins for Channel1 {
|
|||||||
type Adc = Adc<ADC2>;
|
type Adc = Adc<ADC2>;
|
||||||
type ItecPin = PB0<Analog>;
|
type ItecPin = PB0<Analog>;
|
||||||
type DacFeedbackPin = PA5<Analog>;
|
type DacFeedbackPin = PA5<Analog>;
|
||||||
|
type TecUMeasPin = PC3<Analog>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SPI peripheral used for communication with the ADC
|
/// SPI peripheral used for communication with the ADC
|
||||||
@ -55,6 +58,7 @@ pub type AdcNss = PB12<Output<PushPull>>;
|
|||||||
type Dac0Spi = Spi<SPI4, (PE2<Alternate<AF5>>, NoMiso, PE6<Alternate<AF5>>)>;
|
type Dac0Spi = Spi<SPI4, (PE2<Alternate<AF5>>, NoMiso, PE6<Alternate<AF5>>)>;
|
||||||
type Dac1Spi = Spi<SPI5, (PF7<Alternate<AF5>>, NoMiso, PF9<Alternate<AF5>>)>;
|
type Dac1Spi = Spi<SPI5, (PF7<Alternate<AF5>>, NoMiso, PF9<Alternate<AF5>>)>;
|
||||||
|
|
||||||
|
pub type TecUMeasAdc = Adc<ADC3>;
|
||||||
|
|
||||||
pub struct ChannelPinSet<C: ChannelPins> {
|
pub struct ChannelPinSet<C: ChannelPins> {
|
||||||
pub dac_spi: C::DacSpi,
|
pub dac_spi: C::DacSpi,
|
||||||
@ -63,11 +67,13 @@ pub struct ChannelPinSet<C: ChannelPins> {
|
|||||||
pub adc: C::Adc,
|
pub adc: C::Adc,
|
||||||
pub itec_pin: C::ItecPin,
|
pub itec_pin: C::ItecPin,
|
||||||
pub dac_feedback_pin: C::DacFeedbackPin,
|
pub dac_feedback_pin: C::DacFeedbackPin,
|
||||||
|
pub tec_u_meas_pin: C::TecUMeasPin,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Pins {
|
pub struct Pins {
|
||||||
pub adc_spi: AdcSpi,
|
pub adc_spi: AdcSpi,
|
||||||
pub adc_nss: AdcNss,
|
pub adc_nss: AdcNss,
|
||||||
|
pub tec_u_meas_adc: TecUMeasAdc,
|
||||||
pub pwm: PwmPins,
|
pub pwm: PwmPins,
|
||||||
pub channel0: ChannelPinSet<Channel0>,
|
pub channel0: ChannelPinSet<Channel0>,
|
||||||
pub channel1: ChannelPinSet<Channel1>,
|
pub channel1: ChannelPinSet<Channel1>,
|
||||||
@ -80,7 +86,7 @@ impl Pins {
|
|||||||
tim1: TIM1, tim3: TIM3,
|
tim1: TIM1, tim3: TIM3,
|
||||||
gpioa: GPIOA, gpiob: GPIOB, gpioc: GPIOC, gpioe: GPIOE, gpiof: GPIOF, gpiog: GPIOG,
|
gpioa: GPIOA, gpiob: GPIOB, gpioc: GPIOC, gpioe: GPIOE, gpiof: GPIOF, gpiog: GPIOG,
|
||||||
spi2: SPI2, spi4: SPI4, spi5: SPI5,
|
spi2: SPI2, spi4: SPI4, spi5: SPI5,
|
||||||
adc1: ADC1, adc2: ADC2,
|
adc1: ADC1, adc2: ADC2, adc3: ADC3,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let gpioa = gpioa.split();
|
let gpioa = gpioa.split();
|
||||||
let gpiob = gpiob.split();
|
let gpiob = gpiob.split();
|
||||||
@ -97,6 +103,8 @@ impl Pins {
|
|||||||
let adc_spi = Self::setup_spi_adc(clocks, spi2, gpiob.pb10, gpiob.pb14, gpiob.pb15);
|
let adc_spi = Self::setup_spi_adc(clocks, spi2, gpiob.pb10, gpiob.pb14, gpiob.pb15);
|
||||||
let adc_nss = gpiob.pb12.into_push_pull_output();
|
let adc_nss = gpiob.pb12.into_push_pull_output();
|
||||||
|
|
||||||
|
let tec_u_meas_adc = Adc::adc3(adc3, true, Default::default());
|
||||||
|
|
||||||
let pwm = PwmPins::setup(
|
let pwm = PwmPins::setup(
|
||||||
clocks, tim1, tim3,
|
clocks, tim1, tim3,
|
||||||
gpioc.pc6, gpioc.pc7,
|
gpioc.pc6, gpioc.pc7,
|
||||||
@ -114,6 +122,7 @@ impl Pins {
|
|||||||
adc0.enable();
|
adc0.enable();
|
||||||
let itec0_pin = gpioa.pa6.into_analog();
|
let itec0_pin = gpioa.pa6.into_analog();
|
||||||
let dac_feedback0_pin = gpioa.pa4.into_analog();
|
let dac_feedback0_pin = gpioa.pa4.into_analog();
|
||||||
|
let tec_u_meas0_pin = gpioc.pc2.into_analog();
|
||||||
let channel0 = ChannelPinSet {
|
let channel0 = ChannelPinSet {
|
||||||
dac_spi: dac0_spi,
|
dac_spi: dac0_spi,
|
||||||
dac_sync: dac0_sync,
|
dac_sync: dac0_sync,
|
||||||
@ -121,6 +130,7 @@ impl Pins {
|
|||||||
adc: adc0,
|
adc: adc0,
|
||||||
itec_pin: itec0_pin,
|
itec_pin: itec0_pin,
|
||||||
dac_feedback_pin: dac_feedback0_pin,
|
dac_feedback_pin: dac_feedback0_pin,
|
||||||
|
tec_u_meas_pin: tec_u_meas0_pin,
|
||||||
};
|
};
|
||||||
|
|
||||||
let (dac1_spi, dac1_sync) = Self::setup_dac1(
|
let (dac1_spi, dac1_sync) = Self::setup_dac1(
|
||||||
@ -133,6 +143,7 @@ impl Pins {
|
|||||||
adc1.enable();
|
adc1.enable();
|
||||||
let itec1_pin = gpiob.pb0.into_analog();
|
let itec1_pin = gpiob.pb0.into_analog();
|
||||||
let dac_feedback1_pin = gpioa.pa5.into_analog();
|
let dac_feedback1_pin = gpioa.pa5.into_analog();
|
||||||
|
let tec_u_meas1_pin = gpioc.pc3.into_analog();
|
||||||
let channel1 = ChannelPinSet {
|
let channel1 = ChannelPinSet {
|
||||||
dac_spi: dac1_spi,
|
dac_spi: dac1_spi,
|
||||||
dac_sync: dac1_sync,
|
dac_sync: dac1_sync,
|
||||||
@ -140,10 +151,12 @@ impl Pins {
|
|||||||
adc: adc1,
|
adc: adc1,
|
||||||
itec_pin: itec1_pin,
|
itec_pin: itec1_pin,
|
||||||
dac_feedback_pin: dac_feedback1_pin,
|
dac_feedback_pin: dac_feedback1_pin,
|
||||||
|
tec_u_meas_pin: tec_u_meas1_pin,
|
||||||
};
|
};
|
||||||
|
|
||||||
Pins {
|
Pins {
|
||||||
adc_spi, adc_nss,
|
adc_spi, adc_nss,
|
||||||
|
tec_u_meas_adc,
|
||||||
pwm,
|
pwm,
|
||||||
channel0,
|
channel0,
|
||||||
channel1,
|
channel1,
|
||||||
|
Loading…
Reference in New Issue
Block a user