What's the advantage of SigmaDelta?

human890209
Posts: 54
Joined: Wed Aug 15, 2018 8:56 am

What's the advantage of SigmaDelta?

Postby human890209 » Thu Aug 16, 2018 2:38 am

Hi,
Cause I'm just landed ESP32 world, and I'm from Arduino Island.
I've found there seems no "analogWrite()" here, but LEDC and SigmaDelta. Then I'm thinking which one should I used to replace the Arduino Word "analogWrite()".

I did some research,
LEDC channel number is 16, while SigmaDelta's is 8, LEDC is better.
LEDC's Duty Resolution is 1-16bits, while SigmaDelta's is 8, LEDC is better.
LEDC's Frequency is depended on Resolution, And I got the result of 8-bit resolution is 312.5KHz, which is same as SigmaDelta's, draw.
LEDC can't reach its Full Power, but which should be okay for a PWM...
For duty resolution of 8 buts, the maximal frequency is 312.5 kHz.
The available duty levels are (2^bit_num)-1, where bit_num can be 1-15.
The maximal frequency is 80000000 / 2^bit_num
It seems the score between LEDC and SigmaDelta is 3:1, LEDC is the winner.
But I guess that SigmaDelta should have some advantage, which I don't know. Or it should not be created.

Is LEDC slow? consume more calculation resources? I'm not a tech geek.
Please help me find SigmaDelta's advantage. Thanks.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: What's the advantage of SigmaDelta?

Postby kolban » Thu Aug 16, 2018 9:24 pm

Have you considered using the Digital to Analog technology described here:

https://esp-idf.readthedocs.io/en/lates ... s/dac.html
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

Re: What's the advantage of SigmaDelta?

Postby JoaoLopesF » Thu Aug 16, 2018 10:11 pm

Hi, I have one project with 6 channels of leds, and I migrate it to Sigma-Delta.

From what I've seen, sigma-delta is more advanced than simple PWM (LedChannel, Motor PWM).
(I just googled: sigma-delta pwm)

Of course this depends on each application, which may be better in one, cannot be in another ...

In my project I generate frequencies (Square, Square w/ ramp, sinusoidal or semi-sinusoidal) from 0,2 to 75 HZ,
and Sigma-Delta of Esp32 works very well, faster too.

human890209
Posts: 54
Joined: Wed Aug 15, 2018 8:56 am

Re: What's the advantage of SigmaDelta?

Postby human890209 » Fri Aug 17, 2018 12:57 am

Hi,

Thanks, kolban.
I saw the Real DAC in ESP32's GitHub readme, it's cool which Arduino doesn't have.
I will test it some other day.
Cause I'm an Arduino user. My first thought is if my sketches could run in this So Advanced MCU/Board :D
And ESP32 shocked me with analogWrite(). :shock:

Thanks, JoaoLopesF.
You said "Faster", is the difference big?
And you mentioned "Square, Square w/ ramp, sinusoidal or semi-sinusoidal". How do you do that?
I only find this https://github.com/espressif/arduino-es ... gmadelta.h
Can you tell me how to do sinusoidal with ESP32?

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: What's the advantage of SigmaDelta?

Postby Archibald » Fri Aug 17, 2018 2:58 pm

human890209 wrote:Can you tell me how to do sinusoidal with ESP32?
You can include proper ESP32 code in your Arduino code. This code generates a sinusoidal waveform from one of the digital to analogue converters . . . . .

Code: Select all

extern "C" {
#include "dac.h"
}

float theta;

void setup() {
  dac_output_enable(DAC_CHANNEL_1); // pin 25
  dac_i2s_disable();
}

void loop() {
  for (theta=0 ; theta<2*PI ; theta=theta+0.02)
  {
    dac_output_voltage ( DAC_CHANNEL_1, 128+127*sin(theta) );
    delayMicroseconds(10);
  }
}
Output is on pin 25.

I'm not sure whether the line of code to disable I²S is necessary.

human890209
Posts: 54
Joined: Wed Aug 15, 2018 8:56 am

Re: What's the advantage of SigmaDelta?

Postby human890209 » Sat Aug 18, 2018 2:12 am

Hi, Archibald
Thanks for your reply. But I'm getting confused now.
I'm comparing LECC and Sigma-delta and create this topic to ask.
And JoaoLopesF mentioned he used Sigma-Delta to perform a sinusoidal waveform.
Do you use DAC to created the sinusoidal waveform? This is not an advantage of SigmaDelta, I guess. :mrgreen:

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: What's the advantage of SigmaDelta?

Postby Archibald » Sat Aug 18, 2018 7:55 am

Hi Human,

You asked how to do sinusoidal with ESP32 :) .

PWM and sigma-delta are digital signals so you need to filter them to get an analogue signal.

Using a DAC is very much better but you have only two channels available. The output from a DAC includes some unwanted signal components because the output voltage changes in tiny steps and because the DACs have 8-bit resolution. Those unwanted components are very, very much smaller than with PWM or sigma-delta so in practice you probably would not need any filtering.
Last edited by Archibald on Mon Aug 20, 2018 6:16 pm, edited 1 time in total.

JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

Re: What's the advantage of SigmaDelta?

Postby JoaoLopesF » Mon Aug 20, 2018 2:46 pm

Hi @human89020
human890209 wrote: You said "Faster", is the difference big?
The DAC is better to generate real voltage signals (as related by @kolban and @Archibald).

But the DAC in ESP32, have a limitations as:
  • - Only 2 channels
    - Is very slow comparate a Sigma-Delta, if you want generate frequencies it can be a problem.
    I did a benchmark see in: viewtopic.php?f=2&t=6042
human890209 wrote: And you mentioned "Square, Square w/ ramp, sinusoidal or semi-sinusoidal". How do you do that?
I only find this https://github.com/espressif/arduino-es ... gmadelta.h
In this my project, I use Sigma-Delta to generate the frequencies (up to 6 channels),
And I can enable 2 DAC channels, to monitor and view waveforms generated (2 ch only) on the scopemeter.

In this project, the waveform generator is all done by my code,
and as it is for a commercial device, I can not publish it here.

But here are some tips:
  • - How do I use a fixed timer to generate the waves, of only 100 micros
       and not want have any interruptions (by FreeRTOS),
    I choose to dedicate CPU 1 only to this.
       I am using Timer Group 0, initialized by a task in CPU1.
    (esp_timer have a one task to callbacks in CPU 0, and due it is not used)

    - Except for square wave, the whole wave is calculated before, especially the sine waves (sinf and cosf are slow).
    I use fastmath.h to improve performance.
    And this project supports frequency ramps, for example: starting at 2 Hz and ending at 10 Hz, this in 10 minutes,
    with frequency is increased from time to time.
    Due this, I need to recalculate the frequencies from time to time and this needed to be very fast.

    - Optimize the Sigma-Delta calls, saving the last value of channel and calling it only it is need.
human890209 wrote: Can you tell me how to do sinusoidal with ESP32?
The DAC in ESP32 have a Cosine generator.
I not use it, due I need 6 channels.

Please see ESP-IDF DAC documentation
I found one example in esp-idf/examples/system/app_trace_to_host/main/app_trace_to_host_test.c

Please search in Gooogle more examples how do it, as (You can search C codes not only for ESP32):
https://github.com/krzychb/dac-cosine
https://github.com/G6EJD/ESP32-DAC-Examples

Resuming: Use DAC where this limits (2 ch and speed) is not important, else use Sigma-Delta or another PWM.

I hope to helped

human890209
Posts: 54
Joined: Wed Aug 15, 2018 8:56 am

Re: What's the advantage of SigmaDelta?

Postby human890209 » Fri Aug 24, 2018 12:39 am

Thanks, JoaoLopesF
SigmaDelta is faster than DAC.
And have you compared SigmaDelta with LEDC? If just for PWM usage, is SigmaDelta still got an advantage over LEDC?

JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

Re: What's the advantage of SigmaDelta?

Postby JoaoLopesF » Sat Aug 25, 2018 8:39 pm

Hi @human890209, I not tested it yet, For my application the Sigma-Delta works fine
Regards

Who is online

Users browsing this forum: Bing [Bot] and 54 guests