ESP32 基于arduino平台的DAC模拟输出IQ通道模拟

先上代码

#include <Arduino.h>
#include <esp32-hal-dac.h>
#define DAC1 (*(volatile unsigned long *)0x3ff48484)//ADC数值寄存器
#define DAC2 (*(volatile unsigned long *)0x3ff48488)
#define LED1 25
#define LED2 26
#define pi 3.14159
#define totalStep 1000
unsigned long IOutputQueue[totalStep];
unsigned long QOutputQueue[totalStep];
unsigned long i;

void setup()
{
    delay(100);
    Serial.begin(115200);
    Serial.println("123");

    for (i = 0; i < totalStep; i++)
    {
        IOutputQueue[i] = sin(2 * pi * i / totalStep) * 127 + 128;
        IOutputQueue[i] = ((IOutputQueue[i] & 0x000000ff) << (19)) | 0xc0060400;
    }
    for (i = 0; i < totalStep; i++)
    {
        QOutputQueue[i] = cos(2 * pi * i / totalStep) * 127 + 128;
        QOutputQueue[i] = ((QOutputQueue[i] & 0x000000ff) << (19)) | 0xc0060400;
    }
    
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT);
    dacWrite(LED1, 0);
    dacWrite(LED2, 0);
    Serial.printf("%x", DAC1);//在这里我们可以观察到寄存配置应该是0xc0060400 
}

void loop()
{
    while (1)
    {
        i++;
        if (i >= totalStep)
            i = 0;
        DAC1 = IOutputQueue[i];
        DAC2 = QOutputQueue[i];
    }
}

示波器可以看到输出是正交的
附上寄存器说明
X*Y是个圆圈说明应该正交吧

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页