forked from esp-rs/esp-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for sigma-delta modulation
Issue esp-rs#2370
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! Connect an oscilloscope to an IO pin and see the modulation sine wave. | ||
//! | ||
//! Also you may connect low-pass filter to SDM output. | ||
//! | ||
//! The following wiring is assumed for ESP32: | ||
//! - SDM pin => GPIO32 | ||
//! The following wiring is assumed for ESP32S2/S3: | ||
//! - SDM pin => GPIO3 | ||
//! The following wiring is assumed for others: | ||
//! - SDM pin => GPIO2 | ||
//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use esp_backtrace as _; | ||
use esp_hal::{delay::Delay, gpio::Io, prelude::*, sdm::Sdm}; | ||
use esp_println::println; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let peripherals = esp_hal::init(esp_hal::Config::default()); | ||
|
||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); | ||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "esp32")] { | ||
let modulation_pin = io.pins.gpio32; | ||
} else if #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] { | ||
let modulation_pin = io.pins.gpio3; | ||
} else { | ||
let modulation_pin = io.pins.gpio2; | ||
} | ||
} | ||
|
||
let mut sdm = Sdm::new(peripherals.GPIO_SD); | ||
let mut sdm_ch = sdm.enable_pin(modulation_pin, 100.kHz()).unwrap(); | ||
|
||
let delay = Delay::new(); | ||
|
||
println!("Sigma-delta modulation is on"); | ||
|
||
loop { | ||
sdm_ch.set_pulse_density(0); | ||
delay.delay_millis(1500); | ||
} | ||
} |