aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/timer/pwm_input.rs6
-rw-r--r--examples/stm32f1/src/bin/pwm_input.rs9
-rw-r--r--examples/stm32f4/src/bin/pwm_input.rs9
3 files changed, 11 insertions, 13 deletions
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs
index d3fe7632a..7bcb7802a 100644
--- a/embassy-stm32/src/timer/pwm_input.rs
+++ b/embassy-stm32/src/timer/pwm_input.rs
@@ -114,8 +114,8 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
114 self.inner.get_capture_value(self.channel) 114 self.inner.get_capture_value(self.channel)
115 } 115 }
116 116
117 /// Get the duty tick count 117 /// Get the pulse width tick count
118 pub fn get_duty_ticks(&self) -> u32 { 118 pub fn get_width_ticks(&self) -> u32 {
119 self.inner.get_capture_value(match self.channel { 119 self.inner.get_capture_value(match self.channel {
120 Channel::Ch1 => Channel::Ch2, 120 Channel::Ch1 => Channel::Ch2,
121 Channel::Ch2 => Channel::Ch1, 121 Channel::Ch2 => Channel::Ch1,
@@ -129,6 +129,6 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
129 if period == 0 { 129 if period == 0 {
130 return 0.; 130 return 0.;
131 } 131 }
132 100. * (self.get_duty_ticks() as f32) / (period as f32) 132 100. * (self.get_width_ticks() as f32) / (period as f32)
133 } 133 }
134} 134}
diff --git a/examples/stm32f1/src/bin/pwm_input.rs b/examples/stm32f1/src/bin/pwm_input.rs
index de6949eb4..9883280cf 100644
--- a/examples/stm32f1/src/bin/pwm_input.rs
+++ b/examples/stm32f1/src/bin/pwm_input.rs
@@ -1,7 +1,6 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3 3
4use cortex_m::asm;
5use defmt::*; 4use defmt::*;
6use embassy_executor::Spawner; 5use embassy_executor::Spawner;
7use embassy_stm32::gpio::{Level, Output, Pull, Speed}; 6use embassy_stm32::gpio::{Level, Output, Pull, Speed};
@@ -44,9 +43,9 @@ async fn main(spawner: Spawner) {
44 43
45 loop { 44 loop {
46 Timer::after_millis(500).await; 45 Timer::after_millis(500).await;
47 let _per = pwm_input.get_period_ticks(); 46 let period = pwm_input.get_period_ticks();
48 let _dc = pwm_input.get_duty_ticks(); 47 let width = pwm_input.get_width_ticks();
49 let _pc = pwm_input.get_duty_cycle(); 48 let duty_cycle = pwm_input.get_duty_cycle();
50 asm::nop(); 49 info!("period ticks: {} width ticks: {} duty cycle: {}", period, width, duty_cycle);
51 } 50 }
52} 51}
diff --git a/examples/stm32f4/src/bin/pwm_input.rs b/examples/stm32f4/src/bin/pwm_input.rs
index 30cefac3a..8fe1fdb5b 100644
--- a/examples/stm32f4/src/bin/pwm_input.rs
+++ b/examples/stm32f4/src/bin/pwm_input.rs
@@ -1,7 +1,6 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3 3
4use cortex_m::asm;
5use defmt::*; 4use defmt::*;
6use embassy_executor::Spawner; 5use embassy_executor::Spawner;
7use embassy_stm32::gpio::{Level, Output, Pull, Speed}; 6use embassy_stm32::gpio::{Level, Output, Pull, Speed};
@@ -44,9 +43,9 @@ async fn main(spawner: Spawner) {
44 43
45 loop { 44 loop {
46 Timer::after_millis(500).await; 45 Timer::after_millis(500).await;
47 let _per = pwm_input.get_period_ticks(); 46 let period = pwm_input.get_period_ticks();
48 let _dc = pwm_input.get_duty_ticks(); 47 let width = pwm_input.get_width_ticks();
49 let _pc = pwm_input.get_duty_cycle(); 48 let duty_cycle = pwm_input.get_duty_cycle();
50 asm::nop(); 49 info!("period ticks: {} width ticks: {} duty cycle: {}", period, width, duty_cycle);
51 } 50 }
52} 51}