current_source: add driver to read pd voltage

This commit is contained in:
linuswck 2024-01-09 16:05:08 +08:00
parent d1f7a20c15
commit a99dde8b38
1 changed files with 10 additions and 0 deletions

View File

@ -11,6 +11,7 @@ use stm32f4xx_hal::{
use uom::si::{ use uom::si::{
ratio::ratio, ratio::ratio,
electric_potential::millivolt,
f64::{ElectricPotential, ElectricCurrent}, f64::{ElectricPotential, ElectricCurrent},
}; };
@ -89,6 +90,15 @@ impl CurrentSource {
self.phy.current_source_short_pin.set_high(); self.phy.current_source_short_pin.set_high();
} }
pub fn get_pd_mon_v(&mut self) -> ElectricPotential{
let sample = self.pins_adc.convert(
&self.phy.pd_mon_pin,
stm32f4xx_hal::adc::config::SampleTime::Cycles_480,
);
let mv = self.pins_adc.sample_to_millivolts(sample as u16);
ElectricPotential::new::<millivolt>(mv as f64)
}
pub fn set_dac(&mut self, voltage: ElectricPotential, dac_out_v_max: ElectricPotential) -> ElectricPotential { pub fn set_dac(&mut self, voltage: ElectricPotential, dac_out_v_max: ElectricPotential) -> ElectricPotential {
let value = ((voltage / dac_out_v_max).get::<ratio>() let value = ((voltage / dac_out_v_max).get::<ratio>()
* (max5719::MAX_VALUE as f64)) as u32; * (max5719::MAX_VALUE as f64)) as u32;