DAC124S085芯片的使用

Posted praiseslow

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DAC124S085芯片的使用相关的知识,希望对你有一定的参考价值。

DAC124S085芯片的使用
该芯片可以通过SPI对其进行操作。具备12bit的能力。
经过实测,该芯片在有基准电源的情况下,输出准确度非常高。
示例代码如下:

 1 #include "typedefs.h"
 2 
 3 #define DAC_DAC_A 0b00
 4 #define DAC_DAC_B 0b01
 5 #define DAC_DAC_C 0b10
 6 #define DAC_DAC_D 0b11
 7 
 8 #define DAC_WRITE_SPECIFIC_DO_NOT_UPDATE 0b00
 9 #define DAC_WRITE_SPECIFIC_AND_UPDATE    0b01
10 #define DAC_WRITE_ALL_AND_UPDATE         0b10
11 #define DAC_POWER_DOWN                   0b11
12 
13 /* must give the union some name, otherwise compile error in dcc.*/
14 struct DAC124S085_REG_tag{
15     union{
16         uint16_t R;
17         struct{
18             uint16_t reg_addr:2;
19             uint16_t action:2;
20             uint16_t raw_value:12;
21         } B;
22 
23     } U;
24 };

运行中代码为:

void dac_lld_update(uint8_t which_out, uint8_t which_action, uint16_t voltage_in_mv)
{
    static struct DAC124S085_REG_tag  dac_spi_last_command;

      uint16_t tmp16;
      uint32_t tmp32;
      tmp32 = voltage_in_mv*0xFFF;
      tmp16 = tmp32/4096; /* 4096 is the ref voltage. */

    switch(which_out)
    {
    case DAC_DAC_A:
        //
        dac_spi_command.U.B.reg_addr =  DAC_DAC_A;
        break;

    case DAC_DAC_B:
        dac_spi_command.U.B.reg_addr =  DAC_DAC_B;
        break;

    case DAC_DAC_C:
        dac_spi_command.U.B.reg_addr =  DAC_DAC_C;
        break;

    case DAC_DAC_D:
        dac_spi_command.U.B.reg_addr =  DAC_DAC_D;
        break;

    default:
        return;
    }

    switch(which_action)
    {
    case DAC_WRITE_SPECIFIC_DO_NOT_UPDATE:
        dac_spi_command.U.B.action =  DAC_WRITE_SPECIFIC_DO_NOT_UPDATE;
        break;

    case DAC_WRITE_SPECIFIC_AND_UPDATE:
        dac_spi_command.U.B.action =  DAC_WRITE_SPECIFIC_AND_UPDATE;
        break;

    case DAC_WRITE_ALL_AND_UPDATE:
        dac_spi_command.U.B.action =  DAC_WRITE_ALL_AND_UPDATE;
        break;

    case DAC_POWER_DOWN:
        dac_spi_command.U.B.action =  DAC_POWER_DOWN;
        break;

    default:
        dac_spi_command.U.B.action =  DAC_WRITE_SPECIFIC_AND_UPDATE;
    }

    dac_spi_command.U.B.raw_value =  tmp16;

    if(dac_spi_command.U.R != dac_spi_last_command.U.R)
    {
        DSPI_Send(1, 0b00000001,dac_spi_command.U.R); /* semd spi command */
    }
    dac_spi_last_command.U.R = dac_spi_command.U.R;
}

 

以上是关于DAC124S085芯片的使用的主要内容,如果未能解决你的问题,请参考以下文章

esp32怎么实现14位dac输出

4.8 51单片机-PCF8591(ADC/DAC)转换芯片

4.8 51单片机-PCF8591(ADC/DAC)转换芯片

STM32PWM DAC基本原理(实验:PWM实现DAC)

程序备忘_sub_DAC_OUT以及软硬件整理

CS4398音频解码替代芯片DP4398完全兼容DAC解码