A7799之STM32程序——STM32测试高精度ADC篇(二)

1.  AD7799概述


AD7799是ADI公司早期推出一款高精度低速率的ADC,性能参数如下

•均方根(RMS)噪声: 
27 nV(4.17 Hz、AD7799) 
65 nV(16.7 Hz、AD7799) 
40 nV(4.17 Hz、AD7798) 
85 nV(16.7 Hz、AD7798)

•功耗:380 µA(典型值)

•省电模式:最大1 µA

•低噪声可编程增益仪表放大器

•更新速率:4.17 Hz至470 Hz;3个差分输入(相比ADS1232多一个通道)

•内部时钟振荡器

•50 Hz/60 Hz同时抑制

•基准电压检测

•低端电源开关

•可编程数字输出

•熔断电流控制

•电源电压:2.7 V至5.25 V

•高达23.5个有效位


AD7799性价比很高,非常适用于静态变量的测试,如电子秤、应变计、气体分析、仪器仪表、压力传感器、血液分析、工业过程控制等应用。本人对AD7799做了一次比较测试,分享下测试的结果


2.  硬件设计分析


A7799之STM32程序——STM32测试高精度ADC篇(二)_第1张图片



        从结构图可以看出来,AD7799是模拟区域与数字区域完全独立的ADC,即AVDD给模拟区域供电,DVDD给数字区域供电,在原理图设计方面按照官方指导文档,需要对两个区域做独立的布线与隔离处理,才能让信噪比最佳。另可靠的基准电压是高精度ADC命根,本次试验选择TI公司推出的REF5025作基准参考,REF5025可低于3µVpp/V 噪声、3ppm/°C 漂移,性能是十分出色的。

A7799之STM32程序——STM32测试高精度ADC篇(二)_第2张图片

             由于经常做高频类项目,十分讨厌杜邦线/飞线测试方式,在高精度的领域,24位ADC梯度值2的2416777216,如果接入基准电压是2.5v,理论分辨率可达到0.149μV,做过高频的工程师深知杜邦线的罪恶,根据上面的技术分析,哪怕线路被引入1μV的干扰,也可以让精度打上一定折扣。为了让ADS1232性能得以充分体现,特意做了一个测试载板,载板的设计也是很关键,分割模拟数字区域同时,连接地方大量使用钽电容做旁路电路,以把波纹抑制到最小,合理的布局与布线也很重要,敷铜区域也需要模数分离,以磁珠或者0-5R/电感隔开。

A7799之STM32程序——STM32测试高精度ADC篇(二)_第3张图片


3.  时序图解说


A7799之STM32程序——STM32测试高精度ADC篇(二)_第4张图片

        由时序图看出来,AD7799读写是简单的3线串行读数方式,属于Microwire串行接口,STM32SPI接口可以
完美的与之匹配,当然也可以采用软仿SPI替代STM32的硬件SPI,这样的程序更具移植性。SPI时序实现也相对简单,
AD7799的CS线仅仅只是做片选使用(上图所示),而不用过多管理,保持低电平即可。特别需要注意的是在空闲时
候,SCLK时钟信号需要保持高电平,在SCLK半个周期当DIN接收到0x58后转换的数据才传入到DOUT总线,这时候
能读取数据。


 
  

4.  核心源码

寄存器列表(官方)
#define AD7799_CS_LOW  AD_CS_0()
#define AD7799_CS_HIGH  AD_CS_1()
#define ADC_RDY_DAT (AD_DO)
/*AD7799 Registers*/
#define AD7799_REG_COMM		0 /* Communications Register(WO, 8-bit) */
#define AD7799_REG_STAT	    0 /* Status Register	    (RO, 8-bit) */
#define AD7799_REG_MODE	    1 /* Mode Register	     	(RW, 16-bit */
#define AD7799_REG_CONF	    2 /* Configuration Register (RW, 16-bit)*/
#define AD7799_REG_DATA	    3 /* Data Register	     	(RO, 16-/24-bit) */
#define AD7799_REG_ID	    4 /* ID Register	     	(RO, 8-bit) */
#define AD7799_REG_IO	    5 /* IO Register	     	(RO, 8-bit) */
#define AD7799_REG_OFFSET   6 /* Offset Register	    (RW, 24-bit */
#define AD7799_REG_FULLSALE	7 /* Full-Scale Register	(RW, 24-bit */

/* Communications Register Bit Designations (AD7799_REG_COMM) */
#define AD7799_COMM_WEN		(1 << 7) 			/* Write Enable */
#define AD7799_COMM_WRITE	(0 << 6) 			/* Write Operation */
#define AD7799_COMM_READ    (1 << 6) 			/* Read Operation */
#define AD7799_COMM_ADDR(x)	(((x) & 0x7) << 3)	/* Register Address */
#define AD7799_COMM_CREAD	(1 << 2) 			/* Continuous Read of Data Register */

/* Status Register Bit Designations (AD7799_REG_STAT) */
#define AD7799_STAT_RDY		(1 << 7) /* Ready */
#define AD7799_STAT_ERR		(1 << 6) /* Error (Overrange, Underrange) */
#define AD7799_STAT_CH3		(1 << 2) /* Channel 3 */
#define AD7799_STAT_CH2		(1 << 1) /* Channel 2 */
#define AD7799_STAT_CH1		(1 << 0) /* Channel 1 */

/* Mode Register Bit Designations (AD7799_REG_MODE) */
#define AD7799_MODE_SEL(x)		(((x) & 0x7) << 13)	/* Operation Mode Select */
#define AD7799_MODE_PSW(x)		(1 << 12)			/* Power Switch Control Bit */	
#define AD7799_MODE_RATE(x)		((x) & 0xF) 		/* Filter Update Rate Select */

/* AD7799_MODE_SEL(x) options */
#define AD7799_MODE_CONT		 0 /* Continuous Conversion Mode */
#define AD7799_MODE_SINGLE		 1 /* Single Conversion Mode */
#define AD7799_MODE_IDLE		 2 /* Idle Mode */
#define AD7799_MODE_PWRDN		 3 /* Power-Down Mode */
#define AD7799_MODE_CAL_INT_ZERO 4 /* Internal Zero-Scale Calibration */
#define AD7799_MODE_CAL_INT_FULL 5 /* Internal Full-Scale Calibration */
#define AD7799_MODE_CAL_SYS_ZERO 6 /* System Zero-Scale Calibration */
#define AD7799_MODE_CAL_SYS_FULL 7 /* System Full-Scale Calibration */

/* Configuration Register Bit Designations (AD7799_REG_CONF) */
#define AD7799_CONF_BO_EN	  (1 << 13) 			/* Burnout Current Enable */
#define AD7799_CONF_UNIPOLAR  (1 << 12) 			/* Unipolar/Bipolar Enable */
#define AD7799_CONF_GAIN(x)	  (((x) & 0x7) << 8) 	/* Gain Select */
#define AD7799_CONF_REFDET(x) (((x) & 0x1) << 5) 	/* Reference detect function */
#define AD7799_CONF_BUF		  (1 << 4) 				/* Buffered Mode Enable */
#define AD7799_CONF_CHAN(x)	  ((x) & 0x7) 			/* Channel select */

/* AD7799_CONF_GAIN(x) options */
#define AD7799_GAIN_1       0
#define AD7799_GAIN_2       1
#define AD7799_GAIN_4       2
#define AD7799_GAIN_8       3
#define AD7799_GAIN_16      4
#define AD7799_GAIN_32      5
#define AD7799_GAIN_64      6
#define AD7799_GAIN_128     7

/* AD7799_CONF_REFDET(x) options */
#define AD7799_REFDET_ENA   1	
#define AD7799_REFDET_DIS   0

/* AD7799_CONF_CHAN(x) options */
#define AD7799_CH_AIN1P_AIN1M	0 /* AIN1(+) - AIN1(-) */
#define AD7799_CH_AIN2P_AIN2M	1 /* AIN2(+) - AIN2(-) */
#define AD7799_CH_AIN3P_AIN3M	2 /* AIN3(+) - AIN3(-) */
#define AD7799_CH_AIN1M_AIN1M	3 /* AIN1(-) - AIN1(-) */
#define AD7799_CH_AVDD_MONITOR	7 /* AVDD Monitor */

/* ID Register Bit Designations (AD7799_REG_ID) */
#define AD7799_ID			0x9
#define AD7799_ID_MASK		0xF

/* IO (Excitation Current Sources) Register Bit Designations (AD7799_REG_IO) */
#define AD7799_IOEN			(1 << 6)
#define AD7799_IO1(x)		(((x) & 0x1) << 4)
#define AD7799_IO2(x)		(((x) & 0x1) << 5)
初始化程序
unsigned char AD7799_Init(void)
{ 
	unsigned char status = 0x1;
	u32 ID=AD7799_GetRegisterValue(AD7799_REG_ID, 1);
	if( (ID& 0x0F) != AD7799_ID)
	{
		status = 0x0;
	}
	
	return(status);
}

读取寄存器值
unsigned long AD7799_GetRegisterValue(unsigned char regAddress, unsigned char size)
{
	unsigned char data[5] = {0x00, 0x00, 0x00, 0x00, 0x00};
	unsigned long receivedData = 0x00;	
	data[0] = AD7799_COMM_READ |  AD7799_COMM_ADDR(regAddress);
	AD7799_CS_LOW;  
	SPI_Write(data,1);
	SPI_Read(data,size);
	AD7799_CS_HIGH;
	if(size == 1)
	{
		receivedData += (data[0] << 0);
	}
	if(size == 2)
	{
		receivedData += (data[0] << 8);
		receivedData += (data[1] << 0);
	}
	if(size == 3)
	{
		receivedData += (data[0] << 16);
		receivedData += (data[1] << 8);
		receivedData += (data[2] << 0);
	}
        return receivedData;
}



写寄存器
void AD7799_SetRegisterValue(unsigned char regAddress,
                             unsigned long regValue, 
                             unsigned char size)
{
    unsigned char data[5] = {0x03, 0x00, 0x00, 0x00, 0x00};	
	    data[0] = AD7799_COMM_WRITE |  AD7799_COMM_ADDR(regAddress);
    if(size == 1)
    {
        data[1] = (unsigned char)regValue;
    }
    if(size == 2)
    {
		   data[2] = (unsigned char)((regValue & 0x0000FF) >> 0);
        data[1] = (unsigned char)((regValue & 0x00FF00) >> 8);
    }
    if(size == 3)
    {
		  data[3] = (unsigned char)((regValue & 0x0000FF) >> 0);
		  data[2] = (unsigned char)((regValue & 0x00FF00) >> 8);
          data[1] = (unsigned char)((regValue & 0xFF0000) >> 16);
    }
    AD7799_CS_LOW;	    
    SPI_Write(data,(1 + size));
    AD7799_CS_HIGH;
}
复位
void AD7799_Reset(void)
{
	unsigned char dataToSend[5] = {0x03, 0xff, 0xff, 0xff, 0xff};
	AD7799_CS_LOW;	    
	SPI_Write(dataToSend,4);
	AD7799_CS_HIGH;	
}
初始化:
void AD7799_INIT(void)
{
    unsigned long command;
    command = AD7799_GetRegisterValue(AD7799_REG_CONF,2);
    command &= ~AD7799_CONF_GAIN(0xFF);
    command |= AD7799_CONF_GAIN(1); / 不使用内部PGA
    AD7799_SetRegisterValue(AD7799_REG_CONF,command,2);
    AD7799_SetReference();
    command = AD7799_GetRegisterValue(AD7799_REG_CONF,2);
    command &= ~AD7799_CONF_CHAN(0xFF);
    command |= AD7799_CONF_CHAN(2); // 第三通道 AIN3+ —— AIN3-
    AD7799_SetRegisterValue(AD7799_REG_CONF,command,2);
    command = AD7799_GetRegisterValue(AD7799_REG_MODE,2);
    command &= ~AD7799_MODE_SEL(0xFF);
    command |= AD7799_MODE_SEL(0);// 连续转换模式
    AD7799_SetRegisterValue(AD7799_REG_MODE,command,2);
}



5.  测试结果


测试条件Vref=2.5v(REF5025调理过后输出)、Gain=1、Updata Reat=4.17Hz
A7799之STM32程序——STM32测试高精度ADC篇(二)_第5张图片

测试源是AVDD电阻分压后的电压值,实际加入电压是:2.217452v(8位半表实测),通过误差曲线的分析,

摆幅稳定在±4µV,效果还是很理想的,官方测试条件Gain=64,加入片内放大器后噪声干扰还是不小的(下图,Y轴

单位LBS),有将近60个LBS的波动,当然主抗匹配也有一定的原因。因此在使用前零度和满度校准是十分必要的。

A7799之STM32程序——STM32测试高精度ADC篇(二)_第6张图片
 
  
 
  

6.  总结

作为一款低速高精度的ADC,AD7799是个不错的选择,相比于ADS1232虽然价格上是高了,但是他比

ADS1232多了一个差分通道,转换速率可以到达470Hz,在本次测试看来,就性能上看起来稍比ADS1232好一点,

是相差无几,同样,超高的性价比和出色的性能让它在同级别的ADC中也有很强的竞争能力。欢迎大家多交流技术

Q Q:1625874998,可提供部分资料,供大家设计参考。



你可能感兴趣的:(STM32读写高精度ADC)