I2S DAC overshooting signal form

dg9ngf
Posts: 40
Joined: Mon Sep 16, 2019 6:49 pm

I2S DAC overshooting signal form

Postby dg9ngf » Mon Sep 16, 2019 7:09 pm

Hello,

I'm playing with my first experiments using an ESP32. My current aim is to play a fixed frequency sine wave as long as a button is pressed. The tone should start and end smoothly and goes through an audio amplifier to a loudspeaker. In the future, the button presses will be analysed and Morse code will be decoded.

For now I'm having some issues with the waveform generation (like the frequency is wrong and the are noisy sounds at the start and end of a tone, but I'll look into this further and may create another topic for that). One of them is that the signal looks a bit strange to me. I've attached a screenshot of what I see on the oscilloscope, measuring the DAC output to ground. It looks the same with or without the amplifier in place. The DAC is connected over two resistors (10k and 330 Ω) to ground, in the middle point the amplifier may be connected.

The timing of the discrete voltage levels looks good, resulting in about 44 kHz sampling rate. Just the transistions between the levels look odd. Is this normal? Am I measuring wrong?

Here's some extract of my code from Arduino:

Code: Select all

#include "driver/i2s.h"

// I2S configuration 
int i2s_num = 0;   // I2S port number
i2s_config_t i2s_config =
{
  .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN),
  .sample_rate = 44100,
  .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
  .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
  .communication_format = I2S_COMM_FORMAT_I2S_MSB,
  .intr_alloc_flags = 0,   // Default interrupt priority
  .dma_buf_count = 8,
  .dma_buf_len = 55,
  .use_apll = false
};

void setup()
{
  // Initialize I2S with configurations above
  i2s_driver_install((i2s_port_t)i2s_num, &i2s_config, 0, NULL);
  i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN);   // Pin 25

  while (true)
  {
    // ...
    uint8_t buffer[i2s_config.dma_buf_len];
    // ...
    size_t bytes_written;
    i2s_write((i2s_port_t)i2s_num, buffer, i2s_config.dma_buf_len * sizeof(uint8_t), &bytes_written, 100);
  }
}

void loop()
{
}
Attachments
NewFile1_marked.png
Signal screenshot
NewFile1_marked.png (28.99 KiB) Viewed 9527 times

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

Re: I2S DAC overshooting signal form

Postby ESP_Sprite » Tue Sep 17, 2019 3:20 am

This looks more-or-less normal. Internally, the DAC consists of a bank of resistors that are switched on or off. The glitch you see is probably from the fact that not all switches switch at exactly the same time. I wouldn't worry about them: there is very little energy in them and the rest of your audio path is probably lowpass enough that it'll filter it out.

felixcollins
Posts: 125
Joined: Fri May 24, 2019 2:02 am

Re: I2S DAC overshooting signal form

Postby felixcollins » Mon Aug 24, 2020 4:49 am

This looks like normal ringing to me due to the fact that the dac is trying to make a square edge in a band limited system. Like the other answer says, your audio path will filter out most of the high frequency signal to leave only audio frequencies [https://en.wikipedia.org/wiki/Ringing_(signal)]

User avatar
jgustavoam
Posts: 165
Joined: Thu Feb 01, 2018 2:43 pm
Location: Belo Horizonte , Brazil
Contact:

Re: I2S DAC overshooting signal form

Postby jgustavoam » Wed Aug 26, 2020 2:40 am

Playing audio with 8 Bits DAC?
Of course, you are hearing noisy sound.
For audible audio, I suggest that you use at least a 12 or 16 bit DAC.
Retired IBM Brasil
Electronic hobbyist since 1976.

stevesch
Posts: 1
Joined: Mon Sep 21, 2020 9:53 am

Re: I2S DAC overshooting signal form

Postby stevesch » Sun Nov 05, 2023 12:23 pm

You can actually get pretty decent audio with a properly filtered 8-bit DAC output. An ideally reconstructed signal would apply a low-pass of half of your sampling rate to a stream of DAC impulses. Applying a the same low-pass to the sample-and-hold DAC will give you an approximately correct value (you're effectively adding a bunch of slightly phase-shifted versions of the same signal together across the period of the sample, or if you're familiar w/signal processing, your impulse train has been convolved with a boxcar filter). Like others have said, your audio system, intentionally or not, is usually some kind of low-pass filter. You can just hope for that to work, but you might do a bit better by applying a specifically-designed low-pass filter on the DAC output.

TL;DR: apply a low-pass (half of your sampling rate, or a bit less) to your signal. Simplest low-pass is just an RC filter. If you want better quality you can look up better low-pass filters.

felixcollins
Posts: 125
Joined: Fri May 24, 2019 2:02 am

Re: I2S DAC overshooting signal form

Postby felixcollins » Thu Nov 09, 2023 8:31 pm


Who is online

Users browsing this forum: No registered users and 148 guests