Benchmark: DAC versus Sigma-Delta
Posted: Sun Jun 10, 2018 4:45 pm
Hi,
I did a benchmark of DAC x Sigma-Delta:
Sigma-Delta have a very good time (0.32 us)
Why DAC is 1400% more slow than Sigma-Delta ?
I did a benchmark of DAC x Sigma-Delta:
Code: Select all
/*
* main.c
*
* Created on: 9 de jun de 2018
* Author: Joao Lopes
*/
#include <stdio.h>
#include <stddef.h>
#include "esp_types.h"
#include "esp_system.h"
#include "esp_log.h"
#include "sdkconfig.h"
#include "esp_timer.h"
#include <driver/dac.h>
#include "driver/gpio.h"
#include "driver/sigmadelta.h"
static const char *tag = "Benchmark";
void app_main()
{
ESP_LOGI (tag, "Main - Begin");
// Initialize DAC
dac_output_enable(DAC_CHANNEL_1);
// Initialize Sigma Delta
sigmadelta_config_t sigmadelta_cfg = {
.channel = SIGMADELTA_CHANNEL_0,
.sigmadelta_prescale = 80,
.sigmadelta_duty = 0,
.sigmadelta_gpio = 4,
};
sigmadelta_config(&sigmadelta_cfg);
// Variables
uint16_t times = 100;
uint64_t timeBegin;
float avg;
// Dac
timeBegin = esp_timer_get_time();
for (uint16_t i = 0; i<times; i++) {
dac_output_voltage(DAC_CHANNEL_1, 100);
}
uint32_t totalTimeDac = (esp_timer_get_time() - timeBegin);
avg = ((float) totalTimeDac / (float) times);
ESP_LOGI(tag, "*** DAC Time total %u avg %f", totalTimeDac, avg);
// SigmaDelta
timeBegin = esp_timer_get_time();
for (uint16_t i = 0; i<times; i++) {
sigmadelta_set_duty(SIGMADELTA_CHANNEL_0, 100);
}
uint32_t totalTimeSigmaDelta = (esp_timer_get_time() - timeBegin);
avg = ((float) totalTimeSigmaDelta / (float) times);
ESP_LOGI(tag, "*** SigmaDelta Time total %u avg %f", totalTimeSigmaDelta, avg);
ESP_LOGI(tag, "*** Factor Dac/SigmaDelta %.2f %%", (totalTimeDac / totalTimeSigmaDelta) * 100.0f);
ESP_LOGI (tag, "Main - End");
}
Code: Select all
Output on Monitor (@ 160MHz):
I (169)P(01) Benchmark: Main - Begin
I (169)P(00) Benchmark: *** DAC Time total 454 avg 4.540000
I (169)P(00) Benchmark: *** SigmaDelta Time total 32 avg 0.320000
I (169)P(00) Benchmark: *** Factor Dac/SigmaDelta 1400.00 %
I (179)P(10) Benchmark: Main - End
Why DAC is 1400% more slow than Sigma-Delta ?