ESP32 IDF Linux and I2S

buzandy
Posts: 13
Joined: Mon Sep 11, 2017 3:50 pm

Re: ESP32 IDF Linux and I2S

Postby buzandy » Tue Sep 26, 2017 5:04 pm

I tried dacWrite and it behaves the same way.... one channel is about 1/4 the amplitude of the other for the same signal.


also DAC may be enabled on these pins all the time.... dac_output_enable or dac_output_disable did not seem to do anything....?????

buzandy
Posts: 13
Joined: Mon Sep 11, 2017 3:50 pm

Re: ESP32 IDF Linux and I2S

Postby buzandy » Tue Sep 26, 2017 10:57 pm

This thread was initially about ESP32 IDF on Linux and problems with I2S, but when I could not get the I2S example working I then tried on a windows pc with Arduino IDE and the ESP IDF tools etc. So all of the problem solving till now has be on windows with Arduino etc.

Now that I got 1 channel working via Arduino etc I thought I would try back on the Linux machine and still no sound out from the orig. example from the example folder. I then put in the Modified example code we had been working on and it gave me very bad distorted sound. I had to modify it all as in a main() function etc to get it to compile, but could not get a good sound.
On Linux I am just using the ESP IDF etc via a command line terminal....and using the vi editor etc and make menu config etc. and had flashed the board several times....all no errors but bad sound.
Then I decided to run Make Clean and then Make Flash again and this time got good sound and when I looked at it in Audacity both channels are same amplitude and in phase. So the Make Clean must have cleared out some rogue code that wasn't getting reset when flashed.

I tried it back on the windows machine, compiled and flashed from Arduino IDE and got good sound, both channels same amplitude and in phase.
So that seems to have sorted the problem but not sure what configs would have sorted it....I assume make clean clears all configs etc...???......
When the I2S_NUM_0 port is mapped to the DAC, Does that free up those I2S pins for other uses...????. eg, IO14, IO12 and IO4 which are touch pins..???.....
Thanks for your help......

buzandy
Posts: 13
Joined: Mon Sep 11, 2017 3:50 pm

Re: ESP32 IDF Linux and I2S

Postby buzandy » Wed Sep 27, 2017 12:49 am

Have also discovered that I can only send a waveform sample of amplitude up to max of about 100.
That is... sin(i/256*2*PI)*50+52. for 256 samples in array.
Any larger than this and it gets distorted starts to look like full wave rectifier again...????

But the smaller ..... *30 + 30 say ..... are good waveforms but low amplitude.

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

Re: ESP32 IDF Linux and I2S

Postby ESP_Sprite » Wed Sep 27, 2017 2:59 am

That is strange.. from memory, I can output over the full range and while I haven't connected a 'scope to it, my DAC output looks just fine. Are you sure it's not external hardware clipping the output?

buzandy
Posts: 13
Joined: Mon Sep 11, 2017 3:50 pm

Re: ESP32 IDF Linux and I2S

Postby buzandy » Wed Sep 27, 2017 1:55 pm

I am using the Firebeetle ESP32 board by DFROBOT DFR0478
There is a schematic on their web site and pinouts diag. and it doesnt show anything connected to the DAC pins.
And I don't see anything connected on the board. I have nothing else connected except the USB port.

It uses the DFROBOT ESP-WROOM-32 module on the board and I dont see anything connected on the pins of it on the schematic.

As far as I can see the DAC ports are Pins 3 and 4 on the firebeetle board, called D2 and D3, or GPIO25 and GPIO26,...connected to pins 10 and 11 of the WROOM module which is connected to pins 13 and 14 of the actual ESP32 chip.

And I am using Pin 15 on the firebeetle board as GND.


What I am finding is sine wave with amplitude factor above 80 in the calculation below gives distortion

Code: Select all

void setup()
{
  Serial.begin(115200);
  
  Serial.println("config done.");

        //initialize i2s with configurations above .....I put this bit in setup....????
                 
        i2s_set_pin((i2s_port_t)i2s_num, NULL);        // NULL here needed for BUILT_IN DAC
         
        i2s_driver_install((i2s_port_t)i2s_num, &i2s_config, 0, NULL);
                    
        Serial.println("I2S installed and started!");
  
    // Create Data below.....
    // Make sure data is between 0 and 1V
    
    for(int i = 0; i < 256; i++) {
      
         sin_float = ((sin(i / 256.0 * 2 * PI)+1) * 88);   //calc. sinewave all above zero, 1 cycle x 256 samples.
         
         //   Above line with amplitude of 80 and below works OK...no distortion
         //   81 and above distortion begins to appear......so the above line  at 88 gives distortion...????
       
         samples[i] =  ((uint32_t) (sin_float) << 8) + ((uint32_t) (sin_float) << 24);   //...output IO25 and output IO26...
                 
              }
    
    // Write data to the buffer. 
    
    i2s_write_bytes((i2s_port_t)i2s_num, (const char *)samples, 1024, portMAX_DELAY);
        
   }

buzandy
Posts: 13
Joined: Mon Sep 11, 2017 3:50 pm

Re: ESP32 IDF Linux and I2S

Postby buzandy » Thu Sep 28, 2017 11:30 pm

I have checked both DAC1 and DAC2 outputs on a scope and find that all I get out of both DAC pins is a about a 100 millivolt ripple on top of about a 250 millivolt DC voltage, when sending samples corresponding to an audio tone signal to the DAC. If I send a fixed value, any value between 0 to 255 I just get the 250 millivolts +/- the few millivolts depending on the value I send.

It doesn't matter if I send using dacWrite OR set_dac_voltage or using I2S-DAC.

When I send samples as per the sinewave calculation in previous post, for the value of 80 I get about 50 millivolt peak to peak on the scope, good sinewave and sounds OK played on an amplified speaker and looks good sinewave in Audacity. If I change the value to 88 I can still see the same wave on the scope but with distortion of the bottom of the peaks appearing and it sounds more "buzzing".

Is there anything else needs to be setup in registers etc. I have tried all the enable and disable I can find in the documents and tried it from Arduino on windows and from ESP_IDF on Linux....and no difference....?????
According to the Docs..Peripherals API......0 to 255 corresponds to 0 to 5 to 3.3 volts depending on VDD....and the example given sets to 0.78 of VDD by sending a value of 200.......200/255*3.3 is 2.59 volts. ......I am not getting that...????

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 164 guests