Page 1 of 1

How do I access the contents of the CW generator / DAC?

Posted: Wed Feb 20, 2019 12:43 pm
by escher
I'm trying to do a little steady-state signal processing on a circuit, making use of the cosine waveform (CW) generator as per this repo. The code there doesn't actually allow me to retrieve the current CW value and so at the moment I have to do my own CW lookup table (costing CPU and memory).

Is there a way I can avoid this and actually get the current CW value in a way that I can perform calculations with it?

Re: How do I access the contents of the CW generator / DAC?

Posted: Thu Feb 21, 2019 8:59 am
by ESP_Sprite
No, but you have a 240MHz processor at your disposal; there's very little stopping you from generating the waveform yourself.

Re: How do I access the contents of the CW generator / DAC?

Posted: Sat Feb 23, 2019 1:17 pm
by escher
ESP_Sprite wrote:
Thu Feb 21, 2019 8:59 am
No, but you have a 240MHz processor at your disposal; there's very little stopping you from generating the waveform yourself.
Despite this, the best I can get out of this loop is 120kHz square wave:

Code: Select all

    while(1) {
        dac_output_voltage( DAC_EXAMPLE_CHANNEL, 0 );
        dac_output_voltage( DAC_EXAMPLE_CHANNEL, 255 );
    }
Using a 51-value lookup table for a sine wave reduces the waveform frequency to 2.4kHz:

Code: Select all

    uint8_t timestamp = 0
    while(1) {
        dac_output_voltage( DAC_EXAMPLE_CHANNEL, sine_lookup_table[timestamp++%51] );
    }
This isn't enough. Calling dac_output_voltage seems to be taking a very long time; the other timestamp arithmetic is MHz fast.

I need a 15kHz sine including access to the actual waveform values - is there a way to do it?

Re: How do I access the contents of the CW generator / DAC?

Posted: Mon Feb 25, 2019 2:38 am
by ESP_Sprite
Don't try to write to the dac directly, you'll get jitter and the CPU use will be high. Instead, configure I2S to output to the internal DACs and feed it entire chunks of memory. (You can use the ESP-IDF I2S driver to do this.) The hardware will take care of writing to the DACs. You should be able to get up to some MHz that way, if memory serves.

Re: How do I access the contents of the CW generator / DAC?

Posted: Sat Feb 29, 2020 12:21 am
by heinzv
I need a high precison sine tone sweep generator (200 to 8000Hz at least) and I found a working solution using the CW generator.
I used this source: https://github.com/krzychb/dac-cosine
Now I found your hint, that I should not go the the internal DAC directly but via the I2S.
That is axcatly what I need because I want to use an external DAC + Amp like the PCM5102 or MAX98357 for higher output voltage/wattage.
Can anybody give me a hint (code snipped) how to use the cos/sin generator (from the source link) how to use the generated sine wave and connect it to the I2S (external DAC not internal).
A shoht hint for volume adjustment would be also appreciated.