Available on crate feature
unstable only.Expand description
Sigma-delta modulation peripheral.
The sigma-delta modulator produces a pulse-density modulated output on a
GPIO matrix signal. Each channel is a peripheral singleton (SDM_CH0,
SDM_CH1, …). Configure a channel with a carrier frequency and pulse
density, then connect it to one output pin.
§Examples
Generate a sigma-delta output signal on a GPIO pin.
use esp_hal::{
sdm::{Channel, ChannelConfig},
time::Rate,
};
let config = ChannelConfig::new()
// Select the prescaler that produces the closest available frequency.
.with_frequency(Rate::from_khz(500))?
.with_duty(128);
let mut channel = Channel::new(peripherals.SDM_CH0, peripherals.GPIO2, config);
channel.set_duty(192); // duty ranges from 0 to 255
channel.set_pulse_density(0); // pulse density ranges from -128 to 127
§Clock source
The SDM function clock is derived from the APB clock.
Each channel’s prescaler divides this function clock to produce its output frequency.
Structs§
- AnySdm
Channel - Any SDM channel.
- Channel
- A connected sigma-delta channel.
- Channel
Config - Sigma-delta channel configuration.
Enums§
- Error
- Sigma-delta configuration or runtime error.