Page 1 of 1

Strange behaviour of DAC cosine wave generator

Posted: Mon Mar 22, 2021 4:31 pm
by gzmoio
Hi all,

I'm using the DAC cosine wave generator as documented here: https://docs.espressif.com/projects/esp ... or_enablev

I am not able to get a 100KHz output, it maxes out at about 55KHz. It is claimed that the max frequency should be 100KHz, as mentioned here: https://docs.espressif.com/projects/esp ... ig_t4freqE

However, the freq member of the dac_cw_config_t struct has tricky wording in the documentation:
Set frequency of cosine wave generator output. Range: 130(130Hz) ~ 55000(100KHz).
So maybe the promised 100KHz max is a typo, and the max is actually 55KHz as would be suggested by the max value of the freq member (55000). Is this true?

Also, the offset setting is strange as well. I would like no offset, so i set offset to zero in the dac_cw_config_t struct. See relevant docs here: https://docs.espressif.com/projects/esp ... _t6offsetE

However, it seems that setting offset to zero results in a rather high offset, actually the same as the max offset of 128. Setting offset to 1 or -1 returns the wave to roughly where it should be given those offsets.

Here is the code:

Code: Select all

void app_main(void)
{
    dac_cw_config_t dac_cw_config = {
        .en_ch = DAC_CHANNEL_1,
        .scale = DAC_CW_SCALE_1,
        .phase = DAC_CW_PHASE_180,
        .freq = 55000,
        .offset = 127
    };
    printf("Hello world!\n");
    dac_cw_generator_config(&dac_cw_config);
    dac_output_enable(DAC_CHANNEL_1);
    dac_cw_generator_enable();
    while (true) {
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}
Any insights to the strange frequency and offset behaviour? Should I revert to I2S driven DAC for now to get higher output frequencies and stable offset behaviour?

Thank you!

Re: Strange behaviour of DAC cosine wave generator

Posted: Tue May 11, 2021 3:27 pm
by alve89
Hi gzmoio,

this post was the only helpful I found on Google. I tried your code but unfortunately I got the error messages, that none of the dac_cw_xxxx functions are declared in that scope (dac_output_enable() works).

I'm using the Arduino IDE 2.0, using an ESP32 Pico and I use

Code: Select all

#include <driver/dac.h>
but still no success (I wasn't able to include

Code: Select all

driver/include/driver/dac_common.h
). The documentation you linked (where I actually started my research) was not helpful about this.

Can you please tell me which libraries you included to compile the settings for the DAC?

Many thanks in advance!

Re: Strange behaviour of DAC cosine wave generator

Posted: Sat Aug 17, 2024 7:10 pm
by Nibbelodean
@gizmo: I noticed that behavior too. The offset is shifting the average voltage for the cosine. It is helpful when using attenuation to produce 1/2, 1/4, or 1/8 VDD amplitudes and you want to shift that smaller cosine's average voltage up or down. So, the offset can be negative as well. I am not happy about the frequency either. Have you been able to identify the actual frequency range?

@alve89: I couldn't use the cosine feature in the Arduino IDE. At the moment, it seems to be an ESP-IDF-supported feature only.