⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad7707.c

📁 The firmware driver in External ADC IC C for the AD7XXX & AD8XXXseries.
💻 C
字号:
//  Driver routines for the AD7707 chip

#define AD7707_DRDY  PIN_B0
#define AD7707_DO    PIN_B1
#define AD7707_DI    PIN_B2
#define AD7707_CLK   PIN_C0
#define AD7707_CS    PIN_C1
#define AD7707_RESET PIN_C2

#define ADC_CHANNEL_NO		31
#define CUTOFF_FREQ			0.6	 //10000L	//100.00 %

unsigned long adc_data[32];

void AD7707_write_byte(byte data) 
{
   byte i;

   output_low(AD7707_CS);

   for(i=1;i<=8;++i) {
      output_low(AD7707_CLK);
      output_bit(AD7707_DI, shift_left(&data,1,0));
      output_high(AD7707_CLK);
   }
   output_high(AD7707_CS);
}


unsigned long AD7707_read_word(void) 
{
   byte i;
   long data;

   output_low(AD7707_CS);
   for(i=1;i<=16;++i) {
      output_low(AD7707_CLK);
      output_high(AD7707_CLK);
      shift_left(&data,2,input(AD7707_DO));
   }
   output_high(AD7707_CS);
   return data;
}

unsigned long AD7707_read_value(void) 
{
	float temp;
	byte i;
	temp=0.0;
	i=5;
//0DRDY/RS2/RS1/RS0/RW/STBY/CH1/CH0
//  0  / 0 / 1 / 1 /1 / 0 / 1 / 1	// 0x38 : Ch3狼 Data Register read operation
	while(i){
		i--;
		AD7707_write_byte(0x3b);	// Data Register ch3 read operation
		while(input(AD7707_DRDY));
		temp += (float)AD7707_read_word();
	}
	temp /= 5.0;
	return (unsigned long)temp;
}


unsigned long AD7707_read_value_filtered(byte ch) 
{
	float temp;
	temp = (float)AD7707_read_value();
	temp = temp * (1.0-CUTOFF_FREQ) + (float)adc_data[ch] * CUTOFF_FREQ;		
	adc_data[ch] = (unsigned long)temp;
	return adc_data[ch];
}

void AD7707_init() 
{
	byte i;

	set_tris_b(0x03);  	 //0b00000011, mux4 out/mux3 out/mux2 out/mux1 out/mux0 out/ad7707di out/ad7707do in/ad7707drdy in

	output_low(AD7707_RESET);
    output_high(AD7707_CLK);
	output_high(AD7707_RESET);	//Set high to AD7715 reset low pin
	output_high(AD7707_CS);	//Set low to AD7715 chip select low pin
	delay_ms(100);

//0DRDY/RS2/RS1/RS0/RW/STBY/CH1/CH0
//  0  / 0 / 1 / 0 /0 / 0 / 1 / 1	// 0x13 : Ch3狼 clock write operation
	AD7707_write_byte(0x23);			//Communications Register
//zero/zero/clkdis/clkdiv/clk/fs2/fs1/fs0
// 0  /  0 /  0   /   1  / 0 / 0 / 0 / 0
	AD7707_write_byte(0x10);			//Clock Register

//0DRDY/RS2/RS1/RS0/RW/STBY/CH1/CH0
//  0  / 0 / 0 / 1 /0 / 0 / 1 / 1	// 0x13 : Ch3狼 setup register write operation
	AD7707_write_byte(0x13);			//Communications Register
// MD1/MD0/G2/G1/G0/BU/BUF/FSYNC
//  0 / 1 / 0/ 0/ 0/ 0/ 0 / 0		// Gain=1 bipolar, buffer off, 
//	AD7707_write_byte(0x40);		// self calib
	AD7707_write_byte(0x50);

//	AD7707_write_byte(0x13);			//Communications Register
//	AD7707_write_byte(0xc0);		// fullscale cailb

	while(input(AD7707_DRDY));

	for(i=0;i<ADC_CHANNEL_NO;i++){
		output_b(i<<3);
		delay_ms(30);
		adc_data[i] = AD7707_read_value();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -