使用Cordic进行数模转换

时间:2018-09-09 23:15:12

标签: c fpga digital-analog-converter

我是使用DAC的新手,但是基本上,我有一个运行Linux的FPGA(DE1-SOC)。连接到它的是LTC2607 DAC。就Linux在I2C上识别DAC而言,一切都运行顺利。

我的问题是关于如何使用cordic算法生成正弦波形。我有一个算法,输出一个16进制值的数组。

{0x00003243、0x00001DAC,0x00000FAD,0x000007F5等...}

运行I2c / DAC的代码接受一个16位的“ DAC代码”,然后将其转换为模拟输出:

uint16_t LTC2607_code(float dac_voltage, float LTC2607_lsb, float LTC2607_offset)
{
  uint16_t dac_code;
  float float_code;
  float_code = (dac_voltage - LTC2607_offset) / LTC2607_lsb;                                      // Calculate the DAC code
  float_code = (float_code > (floor(float_code) + 0.5)) ? ceil(float_code) : floor(float_code);   // Round
  if (float_code >= 65535.0)                                                                      // Limits the DAC code to 16 bits
    float_code = 65535.0;
  dac_code = (uint16_t) (float_code);                                                             // Convert to unsigned integer
  return (dac_code);
}

我知道要进行直接数字合成,您必须“插值”正弦曲线上的点(电压电平)。我的想法是,我将这些值一次一地发送到I2C上,但是无论那16个十六进制值在I2C上传递的速度如何快(由主(FPGA)时钟设置为〜10MHz)都是正弦波的频率会吗?

写入DAC的代码如下:

int8_t LTC2607_write(uint8_t i2c_address, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
{
    int fd;
    int ret;
    char *device;
    uint8_t command_byte;
    uint8_t buffer[3];

    command_byte = dac_command | dac_address; // Build the DAC command byte

    // Open the I2C device
    device = LTC2607_get_device_name();
    fd = open(device, O_RDWR);
    if (fd < 0)
    {
        return (1);
    }

    // Select the desired address
    ret = ioctl(fd, I2C_SLAVE, i2c_address);
    if (ret < 0)
    {
        close(fd);
        return (1);
    }

    // Build the I2C command
    buffer[0] = command_byte;
    buffer[1] = (dac_code >> 8) & 0xFF;
    buffer[2] = dac_code & 0xFF;

   // Write the command to the I2C bus
   ret = write(fd, buffer, 3);
   if (ret < 3)
   {
     close(fd);
     return (1);
   }

   // Close the device
   close(fd);

   return (0);
 }

如何使用上述LTC2607_write函数将16个十六进制值的字符串转换为正弦曲线?

0 个答案:

没有答案
相关问题