Skip to content

Commit

Permalink
Add example for sigma-delta modulation
Browse files Browse the repository at this point in the history
  • Loading branch information
katyo committed Oct 20, 2024
1 parent db8bab0 commit ba31e63
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions examples/src/bin/sdm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//! 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 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3

#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_hal::{
sdm::Sdm,
delay::Delay,
gpio::Io,
prelude::*,
};
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;
}
}

// Create SDM instances
//let mut sdm_config = SdmConfig::default();
//let mut sdm_pin = sdm_config.enable_pin(modulation_pin, 1.MHz());
//let mut sdm = Sdm::new(peripherals.GPIO_SD, sdm_config);

let mut sdm = Sdm::new(peripherals.GPIO_SD);
let mut sdm_ch = sdm.enable_pin(modulation_pin, 100.kHz()).unwrap();

let delay = Delay::new();

loop {
sdm_ch.set_pulse_density(0);
delay.delay_millis(1500);
}
}

0 comments on commit ba31e63

Please sign in to comment.