Generate an arbitrary function by DAC

gchini
Posts: 18
Joined: Wed Jun 08, 2022 1:41 pm

Generate an arbitrary function by DAC

Postby gchini » Sat Jul 22, 2023 12:09 pm

Hello,

I would like to make a small project (a function generator) in wich the final goal is to generate an arbitrary function regulated form some setting. My aims is to imitate as much as possible the functions generated from this software below WHITHOUT GUI

Image

My aim is to have tha following features (without GUI)

Image
  • Two channels Left and Right
  • Generation of Sine, Square and Sawtooth wave
  • Modulation AM and FM at low rate (minimum 0.01hz - maximum 100hz)
  • SWEEP in frequency and apmlitude
I want create a function generator controlled by a rotary swith and some buttons but for now I want design only the function generator controlled by serial port.

QUESTIONS 1
Is this project feasable? I mean can i realize a device that generate a function at enought high frequency? My goal is to reach the wave frequency of 5000hz. Is it possible to implement it with ESP32?

QUESTIONS 2
How can I acheive my aim (for example) to generate a 5000hz with AM of 2hz wave?

QUESTIONS 3
I've tried this example that outputs from the DAC a value of -1.7v (0) and a value of 1.7v (255) and I found that the maximum frequency that i can go is around 27khz (see below). If is is like that do i have some chance to generate a 5000hz with AM of 2hz wave and let the microcontroller do other tasks for others (for example to talk via computer by serial)?

Code: Select all

#define DAC_CH1 25

void setup() {
}
 
void loop() {
  while(1){
    dacWrite(DAC_CH1, 0);
    dacWrite(DAC_CH1, 255);
  }
}
Image

THANKS

lbernstone
Posts: 829
Joined: Mon Jul 22, 2019 3:20 pm

Re: Generate an arbitrary function by DAC

Postby lbernstone » Sat Jul 22, 2023 5:11 pm

You can use the DAC cosine wave generator for sine waves at ~100KHz - 8MHz.
The docs for the math are in the technical reference manual (https://www.espressif.com/en/support/do ... -documents)
https://github.com/espressif/esp-idf/bl ... _dac.c#L84

You can use the I2S peripheral to output a generated signal to the DAC. You will need to figure out how to construct the I2S "wav file" (PDM) from your function. Google should have some info on this, maybe even ChatGPT.
https://docs.espressif.com/projects/esp ... s/dac.html
https://docs.espressif.com/projects/esp ... s/i2s.html

For arbitrary patterns, you can use the RMT device, but your frequencies will be lower, and it is a binary signal.
https://github.com/espressif/arduino-es ... oPixel.ino
https://docs.espressif.com/projects/esp ... s/rmt.html

gchini
Posts: 18
Joined: Wed Jun 08, 2022 1:41 pm

Re: Generate an arbitrary function by DAC

Postby gchini » Sun Jul 23, 2023 12:32 pm

I guess that ESP32 is not fast enought to process digital audio and generate enought fast signal... Is it true?

Do you have other arduino/raspberry pi - like boards that you can advice for my project?

Thanks

Who is online

Users browsing this forum: No registered users and 164 guests