mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-12-29 21:00:46 +00:00
adc: exact cal
This commit is contained in:
parent
c90e4b3135
commit
ff1fb2dd6b
@ -33,13 +33,6 @@ impl<T: Instance> super::VrefConverter for T {
|
||||
const CHANNEL: u8 = 18;
|
||||
}
|
||||
|
||||
impl super::VrefInt {
|
||||
/// The value that vref would be if vdda was at 3300mv
|
||||
pub fn value(&self) -> u16 {
|
||||
crate::pac::VREFINTCAL.data().read()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Instance> super::TemperatureConverter for T {
|
||||
const CHANNEL: u8 = 16;
|
||||
}
|
||||
|
||||
@ -123,6 +123,14 @@ impl<T: Instance + VrefConverter> SealedAdcChannel<T> for VrefInt {
|
||||
}
|
||||
}
|
||||
|
||||
impl VrefInt {
|
||||
#[cfg(any(adc_f3v1, adc_f3v2))]
|
||||
/// The value that vref would be if vdda was at 3300mv
|
||||
pub fn calibrated_value(&self) -> u16 {
|
||||
crate::pac::VREFINTCAL.data().read()
|
||||
}
|
||||
}
|
||||
|
||||
/// Internal temperature channel.
|
||||
pub struct Temperature;
|
||||
impl<T: Instance + TemperatureConverter> AdcChannel<T> for Temperature {}
|
||||
|
||||
@ -47,7 +47,7 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
|
||||
loop {
|
||||
let vref = adc.read(&mut vrefint, SampleTime::CYCLES601_5).await;
|
||||
info!("read vref: {} (should be {})", vref, vrefint.value());
|
||||
info!("read vref: {} (should be {})", vref, vrefint.calibrated_value());
|
||||
|
||||
let temp = adc.read(&mut temperature, SampleTime::CYCLES601_5).await;
|
||||
info!("read temperature: {}", temp);
|
||||
@ -55,7 +55,7 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
let pin = adc.read(&mut p.PA0, SampleTime::CYCLES601_5).await;
|
||||
info!("read pin: {}", pin);
|
||||
|
||||
let pin_mv = (pin as u32 * vrefint.value() as u32 / vref as u32) * 3300 / 4095;
|
||||
let pin_mv = (pin as u32 * vrefint.calibrated_value() as u32 / vref as u32) * 3300 / 4095;
|
||||
info!("computed pin mv: {}", pin_mv);
|
||||
|
||||
Timer::after_millis(500).await;
|
||||
|
||||
@ -50,7 +50,7 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
|
||||
loop {
|
||||
let vref = adc.read(&mut vrefint, SampleTime::CYCLES601_5).await;
|
||||
info!("read vref: {} (should be {})", vref, vrefint.value());
|
||||
info!("read vref: {} (should be {})", vref, vrefint.calibrated_value());
|
||||
|
||||
let temp = adc.read(&mut temperature, SampleTime::CYCLES601_5).await;
|
||||
info!("read temperature: {}", temp);
|
||||
@ -58,7 +58,7 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
let buffer = adc.read(&mut buffer, SampleTime::CYCLES601_5).await;
|
||||
info!("read buffer: {}", buffer);
|
||||
|
||||
let pin_mv = (buffer as u32 * vrefint.value() as u32 / vref as u32) * 3300 / 4095;
|
||||
let pin_mv = (buffer as u32 * vrefint.calibrated_value() as u32 / vref as u32) * 3300 / 4095;
|
||||
info!("computed pin mv: {}", pin_mv);
|
||||
|
||||
Timer::after_millis(500).await;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user