channels: add set_dac()
This commit is contained in:
parent
eb9aeb160a
commit
b9d05ff274
@ -58,24 +58,30 @@ impl Channels {
|
|||||||
};
|
};
|
||||||
if let Some(dac_value) = dac_value {
|
if let Some(dac_value) = dac_value {
|
||||||
// Forward PID output to i_set DAC
|
// Forward PID output to i_set DAC
|
||||||
match channel {
|
self.set_dac(channel.into(), dac_value);
|
||||||
0 => {
|
|
||||||
self.channel0.dac.set(dac_value).unwrap();
|
|
||||||
self.channel0.shdn.set_high().unwrap();
|
|
||||||
}
|
|
||||||
1 => {
|
|
||||||
self.channel1.dac.set(dac_value).unwrap();
|
|
||||||
self.channel1.shdn.set_high().unwrap();
|
|
||||||
}
|
|
||||||
_ =>
|
|
||||||
unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
channel
|
channel
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// i_set DAC
|
||||||
|
pub fn set_dac(&mut self, channel: usize, duty: u32) {
|
||||||
|
match channel {
|
||||||
|
0 => {
|
||||||
|
self.channel0.dac.set(duty).unwrap();
|
||||||
|
self.channel0.state.dac_value = duty;
|
||||||
|
self.channel0.shdn.set_high().unwrap();
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
self.channel1.dac.set(duty).unwrap();
|
||||||
|
self.channel1.state.dac_value = duty;
|
||||||
|
self.channel1.shdn.set_high().unwrap();
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn read_ref_adc(&mut self, channel: usize) -> u16 {
|
pub fn read_ref_adc(&mut self, channel: usize) -> u16 {
|
||||||
match channel {
|
match channel {
|
||||||
0 => self.channel0.ref_adc.convert(
|
0 => self.channel0.ref_adc.convert(
|
||||||
|
14
src/main.rs
14
src/main.rs
@ -16,7 +16,6 @@ use cortex_m_rt::entry;
|
|||||||
use stm32f4xx_hal::{
|
use stm32f4xx_hal::{
|
||||||
hal::{
|
hal::{
|
||||||
self,
|
self,
|
||||||
digital::v2::OutputPin,
|
|
||||||
watchdog::{WatchdogEnable, Watchdog},
|
watchdog::{WatchdogEnable, Watchdog},
|
||||||
},
|
},
|
||||||
rcc::RccExt,
|
rcc::RccExt,
|
||||||
@ -253,18 +252,7 @@ fn main() -> ! {
|
|||||||
}
|
}
|
||||||
Command::Pwm { channel, pin: PwmPin::ISet, duty } if duty <= ad5680::MAX_VALUE => {
|
Command::Pwm { channel, pin: PwmPin::ISet, duty } if duty <= ad5680::MAX_VALUE => {
|
||||||
channels.channel_state(channel).pid_engaged = false;
|
channels.channel_state(channel).pid_engaged = false;
|
||||||
match channel {
|
channels.set_dac(channel, duty);
|
||||||
0 => {
|
|
||||||
channels.channel0.dac.set(duty).unwrap();
|
|
||||||
channels.channel0.shdn.set_high().unwrap();
|
|
||||||
}
|
|
||||||
1 => {
|
|
||||||
channels.channel1.dac.set(duty).unwrap();
|
|
||||||
channels.channel1.shdn.set_high().unwrap();
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
channels.channel_state(channel).dac_value = duty;
|
|
||||||
let _ = writeln!(
|
let _ = writeln!(
|
||||||
socket, "channel {}: PWM duty cycle manually set to {}/{}",
|
socket, "channel {}: PWM duty cycle manually set to {}/{}",
|
||||||
channel, duty, ad5680::MAX_VALUE
|
channel, duty, ad5680::MAX_VALUE
|
||||||
|
Loading…
Reference in New Issue
Block a user