关于此dac芯片的一些配置,添加到工程里稍微改改头文件就可以拿来用,里面配置的比较粗糙,有待细化。
AD5624R/AD5644R/AD5664R均属于nanoDAC®系列,分别是低功耗、四通道、12/14/16位缓冲电压输出DAC,采用2.7 V至5.5 V单电源供电,通过设计保证单调性。
AD5624R/AD5644R/AD5664R均内置一个片内基准电压源。AD56x4R-3内置一个1.25 V、5 ppm/°C基准电压源,满量程输出范围可达到2.5 V;AD56x4R-5内置一个2.5 V、 5 ppm/°C基准电压源,满量程输出范围可达到5 V。上电时,片内基准电压源关闭,因而可以用外部基准电压源。所有器件均可以采用2.7 V至5.5 V单电源供电。内部基准电压源通过软件写操作来使能。
上述器件内置一个上电复位电路,确保DAC上电后输出0 V并保持该电平,直到执行一次有效的写操作为止。此外还具有各通道独立关断特性,在关断模式下,器件在5 V时的功耗降至480 nA,并提供软件可选的输出负载。在正常工作模式下,该器件具有低功耗特性,非常适合便携式电池供电设备。
AD5624R/AD5644R/AD5664R采用多功能三线式串行接口,能够以最高50 MHz的时钟速率工作,并与标准SPI、QSPI™、MICROWIRE™、DSP接口标准兼容。它内置片内精密输出放大器,能够实现轨到轨输出摆幅。
AD5624中文资料
产品聚焦
1. 四通道、12/14/16位DAC。
2. 1.25 V/2.5 V、5 ppm/ºC片内基准电压源。
3. 提供3 mm × 3 mm、10引脚MSOP和10引脚LFCSP_WD 两种封装。
4. 低功耗:3 V时典型功耗为1.32 mW,5 V时为2.2 mW。
单片机源程序如下:
- #include "AD5624.h"
- /*
- *@name: AD5624_Init
- *@function:dac芯片初始化
- *@parameter: 无
- */
-
- /* 短暂延时 */
- void AD5624R_delay(){
- u8 i=20;
- while(i>0){
- i--;
- }
- }
-
- void AD5624_Init(void){
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);//使能GPIOB时钟
- //GPIOC7 片选
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;//PB14
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//输出
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
- GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化
- AD5624_CS = 1;
- SPI1_Init(); //初始化SPI
- SPI1_SetSpeed(SPI_BaudRatePrescaler_4); //设置为21M时钟,高速模式
- AD5664_InternalRefSetUp(INSETREFVOL_SETUP,DAC_C); //开启内部基准电压源
- AD5664_PowerDown(MODE_NORMAL,DAC_C); //上电
- }
- // Vout = (5*D)/65535
- /*
- *@name: AD5268_SetVal
- *@function:设置输出电压
- *@parameter:
- * @cmd:命令
- * @addr:输出地址
- * @data:电压值(最大值为4095)
- */
- void AD5268_SetVal(u8 cmd,u8 addr,u16 data){
- u8 size1=0,size2=0,size3=0;
- AD5624_CS = 0;
- size1 = (cmd<<3)|addr;
- size2 = (data>>8)&0xff;
- size3 = (data&0xff)<<4;
- //拉低片选
- SPI1_ReadWriteByte(size1);
- SPI1_ReadWriteByte(size2);
- SPI1_ReadWriteByte(size3);
- AD5624R_delay();
- AD5624_CS = 1;
- AD5624R_delay();
-
- }
- //写入寄存器
- void AD5624R_WriteToInputReg(u16 DACValue,u16 addr){
- u8 size1=0,size2=0,size3=0;
- size1 = ((DAC_WRITE_REG)<<3)|addr;
- size2 = (DACValue>>8)&0xff;
- size3 = (DACValue&0xff)<<4;
- AD5624_CS = 0;
- SPI1_ReadWriteByte(size1);
- SPI1_ReadWriteByte(size2);
- SPI1_ReadWriteByte(size3);
- AD5624R_delay();
- AD5624_CS = 1;
- AD5624R_delay();
- }
- //更新dac
- void AD5624R_UpdataDac(u8 addr){
- u8 size1=0,size2=0,size3=0;
- size1 = ((DAC_WRITE_UPDATAALL_REG)<<3)|addr;
- AD5624_CS = 0;
- SPI1_ReadWriteByte(size1);
- SPI1_ReadWriteByte(size2);
- SPI1_ReadWriteByte(size3);
- AD5624R_delay();
- AD5624_CS = 1;
- AD5624R_delay();
- }
- //写入寄存器并更新所有adc
- void AD5664_WriteToInputRegAndUpdateDACs(u16 DACValue,u16 addr){
- u8 size1=0,size2=0,size3=0;
- size1 = ((DAC_WRITE_UPDATAALL_REG)<<3)|(addr);
- size2 = (DACValue>>8)&0xff;
- size3 = (DACValue&0xff)<<4;
- AD5624_CS = 0;
- SPI1_ReadWriteByte(size1);
- SPI1_ReadWriteByte(size2);
- SPI1_ReadWriteByte(size3);
- AD5624R_delay();
- AD5624_CS = 1;
- AD5624R_delay();
- }
- //写入寄存器并更新指定adc
- void AD5664_WriteToInputRegDAC(u16 DACValue,u16 addr){
- u8 size1=0,size2=0,size3=0;
- size1 = ((DAC_WRITE_UPDATA_REG)<<3)|addr;
- size2 = (DACValue>>8)&0xff;
- size3 = (DACValue&0xff)<<4;
- AD5624_CS = 0;
- SPI1_ReadWriteByte(size1);
- SPI1_ReadWriteByte(size2);
- SPI1_ReadWriteByte(size3);
- AD5624R_delay();
- AD5624_CS = 1;
- AD5624R_delay();
- }
- //上电/掉电√
- void AD5664_PowerDown(u8 mode,u16 addr){
- u8 size1=0,size2=0,size3=0;
- size1 = ((DAC_POWER)<<3)|addr;
- size3 = (mode<<4)|addr;
-
- AD5624_CS = 0;
- SPI1_ReadWriteByte(size1);
- SPI1_ReadWriteByte(size2);
- SPI1_ReadWriteByte(size3);
- AD5624R_delay();
- AD5624_CS = 1;
- AD5624R_delay();
- }
- //复位
- void AD5664_Reset(u16 addr,u8 mode){
- u8 size1=0,size2=0,size3=0;
- size1 = ((DAC_RESET)<<3)|addr;
- size3 |= mode;
- AD5624_CS = 0;
- SPI1_ReadWriteByte(size1);
- SPI1_ReadWriteByte(size2);
- SPI1_ReadWriteByte(size3);
- AD5624R_delay();
- AD5624_CS = 1;
- AD5624R_delay();
- }
- //DAC寄存器设置
- void AD5664_LDACRegSetUp(u16 addr){
- u8 size1=0,size2=0,size3=0;
- size1 = ((DAC_SET_REG)<<3)|addr;
- size3 = addr;
- AD5624_CS = 0;
- SPI1_ReadWriteByte(size1);
- SPI1_ReadWriteByte(size2);
- SPI1_ReadWriteByte(size3);
- AD5624R_delay();
- AD5624_CS = 1;
- AD5624R_delay();
- }
- //内部基准电压源设置(开启/关闭)√
- void AD5664_InternalRefSetUp(u8 mode,u16 addr){
- u8 size1=0,size2=0,size3=0;
- size1 = ((DAC_INSIDE_REFVOL)<<3)|addr;
- size3 |= mode;
- AD5624_CS = 0;
- SPI1_ReadWriteByte(size1);
- SPI1_ReadWriteByte(size2);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
AD5624R.zip
(907.18 KB, 下载次数: 80)
|