I2S DAC overshooting signal form
Posted: 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:
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()
{
}