aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src/bin/adc.rs
diff options
context:
space:
mode:
authorGrant Miller <[email protected]>2022-10-24 15:01:16 -0500
committerGrant Miller <[email protected]>2022-10-24 15:27:12 -0500
commit7a6732adcfd09d72f5335f85cbe4e263234849e7 (patch)
treebf4f215356201de8b155eb5aee6c101d0e991339 /examples/stm32f4/src/bin/adc.rs
parent545cc9326b47efc27549a60b3539e93ea0d04d70 (diff)
Improve examples
Diffstat (limited to 'examples/stm32f4/src/bin/adc.rs')
-rw-r--r--examples/stm32f4/src/bin/adc.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs
index 5e036bb44..1c9a0b35d 100644
--- a/examples/stm32f4/src/bin/adc.rs
+++ b/examples/stm32f4/src/bin/adc.rs
@@ -24,14 +24,14 @@ async fn main(_spawner: Spawner) {
24 // Startup delay can be combined to the maximum of either 24 // Startup delay can be combined to the maximum of either
25 delay.delay_us(Temperature::start_time_us().max(VrefInt::start_time_us())); 25 delay.delay_us(Temperature::start_time_us().max(VrefInt::start_time_us()));
26 26
27 let vref_sample = adc.read_internal(&mut vrefint); 27 let vrefint_sample = adc.read_internal(&mut vrefint);
28 28
29 let convert_to_millivolts = |sample| { 29 let convert_to_millivolts = |sample| {
30 // From http://www.st.com/resource/en/datasheet/DM00071990.pdf 30 // From http://www.st.com/resource/en/datasheet/DM00071990.pdf
31 // 6.3.24 Reference voltage 31 // 6.3.24 Reference voltage
32 const VREF_MILLIVOLTS: u32 = 1210; // mV 32 const VREFINT_MV: u32 = 1210; // mV
33 33
34 (u32::from(sample) * VREF_MILLIVOLTS / u32::from(vref_sample)) as u16 34 (u32::from(sample) * VREFINT_MV / u32::from(vrefint_sample)) as u16
35 }; 35 };
36 36
37 let convert_to_celcius = |sample| { 37 let convert_to_celcius = |sample| {
@@ -45,6 +45,10 @@ async fn main(_spawner: Spawner) {
45 (sample_mv - V25) as f32 / AVG_SLOPE + 25.0 45 (sample_mv - V25) as f32 / AVG_SLOPE + 25.0
46 }; 46 };
47 47
48 info!("VrefInt: {}", vrefint_sample);
49 const MAX_ADC_SAMPLE: u16 = (1 << 12) - 1;
50 info!("VCCA: {} mV", convert_to_millivolts(MAX_ADC_SAMPLE));
51
48 loop { 52 loop {
49 // Read pin 53 // Read pin
50 let v = adc.read(&mut pin); 54 let v = adc.read(&mut pin);
@@ -57,7 +61,7 @@ async fn main(_spawner: Spawner) {
57 61
58 // Read internal voltage reference 62 // Read internal voltage reference
59 let v = adc.read_internal(&mut vrefint); 63 let v = adc.read_internal(&mut vrefint);
60 info!("VrefInt: {} ({} mV)", v, convert_to_millivolts(v)); 64 info!("VrefInt: {}", v);
61 65
62 Timer::after(Duration::from_millis(100)).await; 66 Timer::after(Duration::from_millis(100)).await;
63 } 67 }