SigmaDelta

About

ESP32 provides a second-order sigma delta modulation module and 8 (4 for ESP32-C3) independent modulation channels. The channels are capable to output 1-bit signals (output index: 100 ~ 107) with sigma delta modulation.

ESP32 SoC

Number of SigmaDelta channels

ESP32

8

ESP32-S2

8

ESP32-S3

8

ESP32-C3

4

ESP32-C6

4

ESP32-H2

4

Arduino-ESP32 SigmaDelta API

sigmaDeltaAttach

This function is used to set up the SigmaDelta channel with the selected frequency and attach it to the selected pin.

bool sigmaDeltaAttach(uint8_t pin, uint32_t freq);
  • pin select GPIO pin.

  • freq select frequency.

    • range is 1-14 bits (1-20 bits for ESP32).

This function returns true if the configuration was successful. If false is returned, an error occurred and the SigmaDelta channel was not configured.

sigmaDeltaWrite

This function is used to set duty for the SigmaDelta pin.

bool sigmaDeltaWrite(uint8_t pin, uint8_t duty);
  • pin selects the GPIO pin.

  • duty selects the duty to be set for selected pin.

This function returns true if setting the duty was successful. If false is returned, error occurs and duty was not set.

sigmaDeltaDetach

This function is used to detach a pin from SigmaDelta and deinitialize the channel that was attached to the pin.

bool sigmaDeltaDetach(uint8_t pin);
  • pin select GPIO pin.

This function returns true if detaching was successful. If false is returned, an error occurred and pin was not detached.

Example Applications

Here is example use of SigmaDelta:

void setup()
{
    //setup on pin 18 with frequency 312500 Hz
    sigmaDeltaAttach(18, 312500);
    //set pin 18 to off
    sigmaDeltaWrite(18, 0);
}

void loop()
{
    //slowly ramp-up the value
    //will overflow at 256
    static uint8_t i = 0;
    sigmaDeltaWrite(18, i++);
    delay(100);
}