Strange behaviour of DAC cosine wave generator

gzmoio
Posts: 1
Joined: Mon Mar 22, 2021 4:14 pm

Strange behaviour of DAC cosine wave generator

Postby gzmoio » Mon Mar 22, 2021 4:31 pm

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!

alve89
Posts: 4
Joined: Thu Apr 23, 2020 2:36 pm

Re: Strange behaviour of DAC cosine wave generator

Postby alve89 » Tue May 11, 2021 3:27 pm

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!

Who is online

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