diff options
Diffstat (limited to 'tests/stm32/src/bin/dac.rs')
| -rw-r--r-- | tests/stm32/src/bin/dac.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/tests/stm32/src/bin/dac.rs b/tests/stm32/src/bin/dac.rs index d34bbb255..747b11e7f 100644 --- a/tests/stm32/src/bin/dac.rs +++ b/tests/stm32/src/bin/dac.rs | |||
| @@ -10,7 +10,7 @@ use core::f32::consts::PI; | |||
| 10 | use common::*; | 10 | use common::*; |
| 11 | use defmt::assert; | 11 | use defmt::assert; |
| 12 | use embassy_executor::Spawner; | 12 | use embassy_executor::Spawner; |
| 13 | use embassy_stm32::adc::Adc; | 13 | use embassy_stm32::adc::{Adc, SampleTime}; |
| 14 | use embassy_stm32::dac::{DacCh1, Value}; | 14 | use embassy_stm32::dac::{DacCh1, Value}; |
| 15 | use embassy_time::Timer; | 15 | use embassy_time::Timer; |
| 16 | use micromath::F32Ext; | 16 | use micromath::F32Ext; |
| @@ -37,7 +37,7 @@ async fn main(_spawner: Spawner) { | |||
| 37 | dac.set(Value::Bit8(0)); | 37 | dac.set(Value::Bit8(0)); |
| 38 | // Now wait a little to obtain a stable value | 38 | // Now wait a little to obtain a stable value |
| 39 | Timer::after_millis(30).await; | 39 | Timer::after_millis(30).await; |
| 40 | let offset = adc.blocking_read(&mut adc_pin); | 40 | let offset = adc.blocking_read(&mut adc_pin, SampleTime::from_bits(0)); |
| 41 | 41 | ||
| 42 | for v in 0..=255 { | 42 | for v in 0..=255 { |
| 43 | // First set the DAC output value | 43 | // First set the DAC output value |
| @@ -48,7 +48,10 @@ async fn main(_spawner: Spawner) { | |||
| 48 | Timer::after_millis(30).await; | 48 | Timer::after_millis(30).await; |
| 49 | 49 | ||
| 50 | // Need to steal the peripherals here because PA4 is obviously in use already | 50 | // Need to steal the peripherals here because PA4 is obviously in use already |
| 51 | let measured = adc.blocking_read(&mut unsafe { embassy_stm32::Peripherals::steal() }.PA4); | 51 | let measured = adc.blocking_read( |
| 52 | &mut unsafe { embassy_stm32::Peripherals::steal() }.PA4, | ||
| 53 | SampleTime::from_bits(0), | ||
| 54 | ); | ||
| 52 | // Calibrate and normalize the measurement to get close to the dac_output_val | 55 | // Calibrate and normalize the measurement to get close to the dac_output_val |
| 53 | let measured_normalized = ((measured as i32 - offset as i32) / normalization_factor) as i16; | 56 | let measured_normalized = ((measured as i32 - offset as i32) / normalization_factor) as i16; |
| 54 | 57 | ||
