Skip to main content

Module sdm

Module sdm 

Source
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 global IOMUX_FUNCTION_CLOCK. Its source is shared by every consumer of that clock and is therefore configured globally instead of through Channel. The available sources and the default for the selected target are listed by IomuxFunctionClockConfig.

The source can be selected as part of the global clock configuration before initializing the HAL.

Each channel’s prescaler divides this function clock to produce its output frequency.

Structs§

AnySdmChannel
Any SDM channel.
Channel
A connected sigma-delta channel.
ChannelConfig
Sigma-delta channel configuration.

Enums§

Error
Sigma-delta configuration or runtime error.