Problem using DAC continuous

rickwise
Posts: 9
Joined: Sat Jan 22, 2022 4:39 pm

Problem using DAC continuous

Postby rickwise » Sat Jul 25, 2026 1:51 pm

I want to generate a complex waveform on an ESP32, using the DAC. I'm working with a sampling rate of 22,050 samp/s, it doesn't have to be high fidelity. To check the design, I built data for a sin wave, and it isn't generating the output I expect.

Here's the app main code:

Code: Select all

/* PWM Audio output
*/

#include <stdio.h>
#include <driver/dac_continuous.h>

dac_continuous_handle_t	dac_handle;

extern uint8_t	data[];
extern int		data_len;

void
app_main(void)
{
	dac_continuous_config_t	dac_config = {
		.chan_mask = DAC_CHANNEL_MASK_ALL,
		.desc_num = 8,
		.buf_size = 2048,
		.freq_hz = 22050,
		.offset = 0,
		.clk_src = DAC_DIGI_CLK_SRC_DEFAULT,
		.chan_mode = DAC_CHANNEL_MODE_SIMUL,
	};

	dac_continuous_new_channels ( & dac_config, & dac_handle);

	dac_continuous_enable (dac_handle);

	printf ("%d points\n", data_len);

	for (int i = 0; i < 22; i++) {
		printf ("%03d ", data[i]);
	}
	printf ("\n");

	dac_continuous_write_cyclically (dac_handle,
						(uint8_t *) data, data_len, NULL);
}
Here's the first part of data.c. I can provide it all, if it would help:

Code: Select all

#include <inttypes.h>

const uint8_t	data[] = {
	128,163,197,224,244,254,254,244,225,197,164,128,92,59,32,12,1,1,10,30,57,
	90,126,162,195,223,243,254,255,245,226,199,166,130,94,61,33,12,1,0,10,29,
	55,88,124,160,193,222,242,254,255,246,227,200,168,132,96,62,34,13,2,0,9,
	27,54,86,122,158,192,220,241,253,255,246,228,202,170,134,98,64,35,14,2,
	0,8,26,52,85,120,156,190,219,241,253,255,247,229,203,171,136,99,65,37,15,
	2,0,8,25,51,83,118,155,189,218,240,252,255,248,230,205,173,138,101,67,38,
	16,3,0,7,24,49,81,117,153,187,217,239,252,255,248,231,206,175,139,103,69,
Finally, here's the output waveform I'm getting:
https://flic.kr/p/2sr6ado

Any help is greatly appreciated.

Who is online

Users browsing this forum: No registered users and 0 guests