diff options
| author | Raul Alimbekov <[email protected]> | 2025-12-16 09:05:22 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-16 09:05:22 +0300 |
| commit | c9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch) | |
| tree | 6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /tests/stm32/src/bin/dac.rs | |
| parent | cde24a3ef1117653ba5ed4184102b33f745782fb (diff) | |
| parent | 5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff) | |
Merge branch 'main' into main
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 | ||
