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

escher
Posts: 10
Joined: Mon Feb 18, 2019 11:12 am

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

Postby escher » Wed Feb 20, 2019 12:43 pm

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?

ESP_Sprite
Posts: 9709
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » 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.

escher
Posts: 10
Joined: Mon Feb 18, 2019 11:12 am

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

Postby escher » Sat Feb 23, 2019 1:17 pm

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?

ESP_Sprite
Posts: 9709
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Mon Feb 25, 2019 2:38 am

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.

heinzv
Posts: 7
Joined: Fri Sep 20, 2019 7:22 pm

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

Postby heinzv » Sat Feb 29, 2020 12:21 am

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.

Who is online

Users browsing this forum: No registered users and 92 guests