宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

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); /* send spi command */
    }
    dac_spi_last_command.U.R = dac_spi_command.U.R;
}

 注:

1、适用于参考电压为4096v的情况。

2、SPI代码本文未提供。具体参数见该dac芯片的手册和主控芯片的参考手册。