ESP32: Do You Know What DAC Is?

About: Do you like technology? Follow my channel on Youtube and my Blog. In them I put videos every week of microcontrollers, arduinos, networks, among other subjects. New tutorials on Tuesdays and Fridays.

Today, we’ll talk about two issues. The first one is the DAC (Digital-to-Analog Converter). I consider it to be important, because through it, for example, we make an audio output in ESP32. The second issue we are going to address today is the oscilloscope. We’ll then compile a basic DAC code in ESP32, and visualize with oscilloscope the analog waveform signals generated by a microcontroller.

The assembly today is simple, so much so that I did not record a demonstration. It’s easy enough to understand with just the image placed here. Basically, we have an ESP32 that, through a program, will generate several types of waveforms.

We use the GPIO25 as output, and the GND as a reference.

Step 1: Resources Used

• ESP32

• Oscilloscope

• Protoboard (optional)

• Jumpers

Step 2: Pine Used

In this example, we will use the GPIO 25, which corresponds to the DAC_1.

Another example that can be used is the GPIO 26, which corresponds to the DAC_2.

Step 3: ESP32 Code - Wave Matrix

We have a source code that will generate four types of waveforms.

First, we assemble a two-dimensional matrix.

Here, I specify the shape of the sine and triangular waves.

In onde of the images, I display the shape of the tooth of the saw and the square.

As for the source code, no action is necessary in the Setup. In the Loop, I determine the matrix position corresponding to the wave type and use a square wave example. We write the data stored in the matrix on pin 25. Check if "i" is in the last column of the array. If so, the "i" is reset and we go back to the beginning.

I want to make it clear that this DAC inside the ESP32 of the STM32, that is, of the chips, in general, is of small capacity. They are for more generic use. To generate high-frequency waves, there is the DAC chip itself, offered by Texas or Analog Devices, for example.

void setup()
{ //Serial.begin(115200); } //TESTE SEM POSICIONAMENTO (MAIOR FREQUENCIA) /* void loop() { dacWrite(25, 0xff); //25 ou 26 dacWrite(25, 0x00); //25 ou 26 //delayMicroseconds(10); } */ //TESTE COM POSICIONAMENTO (MENOR FREQUENCIA) void loop() { byte wave_type = 0; // Sine //byte wave_type = 1; // Triangle //byte wave_type = 2; // Sawtooth //byte wave_type = 3; // Square dacWrite(25, WaveFormTable[wave_type][i]); //25 ou 26 i++; if (i >= Num_Samples) i = 0; }

Reference Id:

Step 4: Professional Generator

I bring here an example of a professional generator, just to give you an idea of the cost of this equipment. It could be used, for example, to simulate a source and generate a crash. We could inject an electrical noise into an STM microcontroller, analyzing how much the noise would disrupt the chip. This model also has an automatic function to generate electrical noise.

Step 5: Hantek DSO 4102C 100mhz Oscilloscope With Arbitrary Functions Generator

This is tip concerning cheaper equipment options. It costs around $245 on Aliexpress. I like it, because it has a function generator, not to mention that it facilitates the location of errors in the circuit.

Step 6: ​Waves Obtained With the Oscilloscope:

We first capture waves in sinusoidal form, Triangular, Sawtooth, and, finally, the Square.

Step 7: Download the Files:



    • Sensors Contest

      Sensors Contest
    • Fandom Contest

      Fandom Contest
    • Pets Challenge

      Pets Challenge