核心源碼
//寄存器列表
#define ComState_register (0)《《3
#define Mode_register (1)《《3
#define Config_register (2)《《3
#define Data_register (3)《《3
#define ID_register (4)《《3
#define GPOCON_register (5)《《3
#define Disorders_register (6)《《3
#define FullScale_register (7)《《3
//模式寄存器
#define MODE_ADC_OneByOne (0)《《21
#define MODE_ADC_OnlyOne (1)《《21
#define MODE_ADC_Free (2)《《21
#define MODE_ADC_SavePower (3)《《21
#define MODE_ADC_AdjustZero (4)《《21
#define MODE_ADC_AdjustFull (5)《《21
#define MODE_ADC_SysAdjustZero (6)《《21
#define MODE_ADC_SysAdjustFull (7)《《21
#define MODE_MCLK_OUTosc (0)《《18
#define MODE_MCLK_OUTclo (1)《《18
#define MODE_MCLK_IN (2)《《18
#define MODE_MCLK_INcloOut (3)《《18
#define MODE_SINC3 (1)《《15
#define MODE_ENPAR (1)《《13
#define MODE_Single (1)《《11
#define MODE_REJ60 (1)《《10
//#define MODE_Filter_Speed 0
//配置寄存器
#define Config_Chop_EN (1)《《23
#define Config_REFSEL_IO (1)《《20
#define Config_Burn_EN (1)《《7
#define Config_REFDET_EN (1)《《6
#define Config_BUF_EN (1)《《4
#define Config_UB_EN (1)《《3
#define Config_Ch0_A1A2 (1)《《8
#define Config_Ch1_A3A4 (1)《《9
#define Config_Ch2_temp (1)《《10
#define Config_Ch3_A2A2 (1)《《11
#define Config_Ch4_A1AC (1)《《12
#define Config_Ch5_A2AC (1)《《13
#define Config_Ch6_A3AC (1)《《14
#define Config_Ch7_A4AC (1)《《15
#define Config_ADC_Gain_1 0
#define Config_ADC_Gain_8 3
#define Config_ADC_Gain_16 4
#define Config_ADC_Gain_32 5
#define Config_ADC_Gain_64 6
#define Config_ADC_Gain_128 7
typedef struct {
u32 ADC_Mode;
u32 Return_state;
u32 ADC_SCLK;
u32 SINC3_EN;
u32 ENPAR;
u32 Single_EN;
u32 REJ60_EN;
u32 Filter;
}AD7190_MODE_SET;
typedef struct {
u32 Config_Channel;
u32 Config_ADC_Gain;
u32 Config_Chop; //斬波使能
u32 Config_REFSEL;
u32 Config_Burn;
u32 Config_REFDET;
u32 Config_BUF;
u32 Config_UB;
}AD7190_Config_SET;
//基本配置
void AD7190_config(void)
{
AD7190_MODE_SET Mode;
AD7190_Config_SET Config;
Config.Config_Channel = Config_Ch1_A3A4;
Config.Config_ADC_Gain = Config_ADC_Gain_1;
Config.Config_Chop = 1;
Config.Config_REFSEL = 0;
Config.Config_Burn = 0;
Config.Config_REFDET = 1;
Config.Config_BUF = 0;
Config.Config_UB = 1;
Mode.ADC_Mode = MODE_ADC_AdjustZero;
Mode.Return_state = 0;
Mode.ADC_SCLK = MODE_MCLK_IN;
Mode.SINC3_EN = 0;
Mode.ENPAR = 0;
Mode.Single_EN = 0;
Mode.REJ60_EN = 0;
Mode.Filter = 1;
}
//讀取轉換值
void ReadAD7190(unsigned char count, unsigned char *buf)
{
unsigned char i = 0;
unsigned char j = 0;
unsigned char RotateData = 0;
SET_SCL();
delay_us(1);
SET_CS();
delay_us(1);
CLR_CS();
delay_us(1);
for(j=count; j》0; j--)
{
for(i=0; i《8; i++)
{
CLR_SCL();
RotateData 《《= 1;
delay_us(1);
RotateData |= GP0DAT;
SET_SCL();
delay_us(1);
}
*(buf + j - 1)= RotateData;
RotateData=0;
}
SET_CS();
}
//初始化:
void AD7799_INIT(void)
{
unsigned long command;
command = AD7799_GetRegisterValue(AD7799_REG_CONF,2);
command &= ~AD7799_CONF_GAIN(0xFF);
command |= AD7799_CONF_GAIN(1);
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);
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);
}
//讀數程序:
while (1)
{
adcbuf=ADC_Num();
if(ADC_Channel==1)//see datasheet AIN3 AIN4
{
adcA3A4[i++]=adcbuf;
if(i》Num)
{
i=0;
adcA3A4value=GetAverage(adcA3A4,Num);
AD7190_DataFormatting(adcA3A4value , 2.5 ,1);
DataLCD(AD7190_DataFormatting(adcA3A4value , 2.5 ,1));
}
}
}
作為一款中低速高精度的ADC,AD7190有著4.8kHz的轉換頻率,兩路差分輸入或四路偽差分輸入,是個不錯的選擇,相比于AD7799雖然價格略高一些,但是他比AD7799的性能提高不少,特別是采樣速率,測試看來,超高的性價比和出色的性能讓它在同級別的ADC中也有很強的競爭能力。
評論
查看更多