Hi,
I am trying to generate a sine wave with my ESP32 DevKit C v4.
I’ve connected the Adafruit MCP4725 DAC via I2C and adapted the Adafruit examples.
I am creating a task for controlling the dac.
xTaskCreate(controlDac, "DAC", 25000, NULL, 2, NULL);
The task looks like this
#ifndef CONTROL_DAC_H
#define CONTROL_DAC_H
#include <Wire.h>
#include <Adafruit_MCP4725.h>
#include "sine.h"
Adafruit_MCP4725 dac;
void controlDac(void *param)
{
dac.begin(0x62);
while (1)
{
for (uint16_t i = 0; i < SINE_7BIT; i++)
{
uint16_t v = DACLookup_FullSine_7Bit[i];
dac.setVoltage(v, false);
}
}
}
#endif
I used the 7bit look up table from Adafruit sine.h
:
#ifndef SINE_H
#define SINE_H
#include "inttypes.h"
#define SINE_7BIT 128
const uint16_t DACLookup_FullSine_7Bit[SINE_7BIT] =
{
2048, 2148, 2248, 2348, 2447, 2545, 2642, 2737,
2831, 2923, 3013, 3100, 3185, 3267, 3346, 3423,
3495, 3565, 3630, 3692, 3750, 3804, 3853, 3898,
3939, 3975, 4007, 4034, 4056, 4073, 4085, 4093,
4095, 4093, 4085, 4073, 4056, 4034, 4007, 3975,
3939, 3898, 3853, 3804, 3750, 3692, 3630, 3565,
3495, 3423, 3346, 3267, 3185, 3100, 3013, 2923,
2831, 2737, 2642, 2545, 2447, 2348, 2248, 2148,
2048, 1947, 1847, 1747, 1648, 1550, 1453, 1358,
1264, 1172, 1082, 995, 910, 828, 749, 672,
600, 530, 465, 403, 345, 291, 242, 197,
156, 120, 88, 61, 39, 22, 10, 2,
0, 2, 10, 22, 39, 61, 88, 120,
156, 197, 242, 291, 345, 403, 465, 530,
600, 672, 749, 828, 910, 995, 1082, 1172,
1264, 1358, 1453, 1550, 1648, 1747, 1847, 1947};
#endif
And indeed, I am getting a nice sine wave.
BUT the frequency is only ~7hz and I do not understand that.
I can of course increase frequency by reducing the precision by using 5bit. But still then I cannot surpass ~31Hz.
The CPU is running at 240Mhz and I was expecting, that much higher frequency should be possible.
I’ve seen many Arduino tutorials with this DAC and they achieve higher frequencies with slower hardware.
In menuconfig I’ve set the cpu frequency to 240Mhz (originally 160mhz was set), but that didn’t change anything.
It seems not related to the cpu clock. Is it really that slow? I have a few other tasks, e.g. for OTA.
Any guidance is welcome …
Thanks