From baefd4f27d5498636309866c556958e65c96f490 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Sun, 27 Aug 2023 21:37:06 +0200 Subject: [PATCH] adjust sampling --- firmware/Cargo.lock | 2 +- firmware/app/Cargo.toml | 2 +- firmware/app/src/main.rs | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/firmware/Cargo.lock b/firmware/Cargo.lock index 21847db..a62f438 100644 --- a/firmware/Cargo.lock +++ b/firmware/Cargo.lock @@ -1452,7 +1452,7 @@ dependencies = [ [[package]] name = "watchful" -version = "0.2.1" +version = "0.2.2" dependencies = [ "byte-slice-cast 1.2.2", "cortex-m 0.7.7", diff --git a/firmware/app/Cargo.toml b/firmware/app/Cargo.toml index b18d3f4..418632b 100644 --- a/firmware/app/Cargo.toml +++ b/firmware/app/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2021" name = "watchful" -version = "0.2.1" +version = "0.2.2" license = "MIT OR Apache-2.0" build = "build.rs" diff --git a/firmware/app/src/main.rs b/firmware/app/src/main.rs index 110ca59..6a4ca72 100644 --- a/firmware/app/src/main.rs +++ b/firmware/app/src/main.rs @@ -171,7 +171,8 @@ async fn main(s: Spawner) { bat_config.resistor = saadc::Resistor::BYPASS; bat_config.reference = saadc::Reference::INTERNAL; bat_config.time = saadc::Time::_40US; - let adc_config = saadc::Config::default(); + let mut adc_config = saadc::Config::default(); + adc_config.resolution = saadc::Resolution::_10BIT; let saadc = saadc::Saadc::new(p.SAADC, Irqs, adc_config, [bat_config]); let mut battery = Battery::new(saadc, Input::new(p.P0_12.degrade(), Pull::Up)); @@ -430,8 +431,8 @@ impl<'a> Battery<'a> { pub async fn measure(&mut self) -> u32 { let mut buf = [0i16; 1]; self.adc.sample(&mut buf).await; - //let voltage = buf[0] as u32 * (8 * 600) / 1024; - let voltage = buf[0] as u32 * 2000 / 1241; + let voltage = buf[0] as u32 * (8 * 600) / 1024; + //let voltage = buf[0] as u32 * 2000 / 1241; approximate_charge(voltage) }