adc: exact cal

This commit is contained in:
xoviat 2025-11-10 12:49:23 -06:00
parent c90e4b3135
commit ff1fb2dd6b
4 changed files with 12 additions and 11 deletions

View File

@ -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;
}

View File

@ -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 {}

View File

@ -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;

View File

@ -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;