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-C3

4

ESP32-S3

8

Arduino-ESP32 SigmaDelta API

sigmaDeltaSetup

This function is used to setup the SigmaDelta channel frequency and resolution.

uint32_t sigmaDeltaSetup(uint8_t pin, uint8_t channel, uint32_t freq);
  • pin select GPIO pin.

  • channel select SigmaDelta channel.

  • freq select frequency.

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

This function will return frequency configured for the SigmaDelta channel. If 0 is returned, error occurs and the SigmaDelta channel was not configured.

sigmaDeltaWrite

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

void sigmaDeltaWrite(uint8_t channel, uint8_t duty);
  • channel select SigmaDelta channel.

  • duty select duty to be set for selected channel.

sigmaDeltaRead

This function is used to get configured duty for the SigmaDelta channel.

uint8_t sigmaDeltaRead(uint8_t channel)
  • channnel select SigmaDelta channel.

This function will return duty configured for the selected SigmaDelta channel.

sigmaDeltaDetachPin

This function is used to detach pin from SigmaDelta.

void sigmaDeltaDetachPin(uint8_t pin);
  • pin select GPIO pin.

Example Applications

Here is example use of SigmaDelta:

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

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