rp: Add PWM input example
This commit is contained in:
parent
7ea2c3508a
commit
413b394d31
26
examples/rp/src/bin/pwm_input.rs
Normal file
26
examples/rp/src/bin/pwm_input.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
//! This example shows how to use the PWM module to measure the frequency of an input signal.
|
||||||
|
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
use defmt::*;
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_rp::pwm::{Config, InputMode, Pwm};
|
||||||
|
use embassy_time::{Duration, Ticker};
|
||||||
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
|
#[embassy_executor::main]
|
||||||
|
async fn main(_spawner: Spawner) {
|
||||||
|
let p = embassy_rp::init(Default::default());
|
||||||
|
|
||||||
|
let mut cfg: Config = Default::default();
|
||||||
|
let mut pwm = Pwm::new_input(p.PWM_CH2, p.PIN_5, InputMode::RisingEdge, cfg);
|
||||||
|
|
||||||
|
let mut ticker = Ticker::every(Duration::from_secs(1));
|
||||||
|
loop {
|
||||||
|
info!("Input frequency: {} Hz", pwm.counter());
|
||||||
|
pwm.set_counter(0);
|
||||||
|
ticker.next().await;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user