AD7606是一款8通道最高16位200ksps的AD采样芯片。5V单模拟电源供电,真双极性模拟输入可以选择±10 V,±5 V两种量程。支持串口与并口两种读取方式。
硬件连接方式:
配置引脚 | 引脚功能 | 详细说明 |
OS2 OS1 OS2 | 过采样率配置 | 000 1倍过采样率 200K 011 2^3 8倍过采样率 200K/8=25K |
RANGE | 模拟信号量程配置 | 0表示正负5V, 1表示正负10V |
STBY | 待机省电 | 0有效可开启省电或关断,需配合RANGE脚, RANGE=1 待机 RANGE=0 关断 |
RESET | 复位信号 | 典型值高脉冲50ns,上电后需给出,给出后转换中断,输出寄存器清零 |
CONVSTA | 前半通道转换开始信号 | 控制前一半通道V1-V4,过采样末开启时启作用 |
CONVSTB | 后半通道转换开始信号 | 控制后一半通道V5-V8。CONVSTA,CONVSTB可以并联使用 |
PAR/SER/BYTE SEL | 并行/串行/字节选择 | 0 并行 。1串行(DB15=0)或字节 (DB15=1) 串行时RD/CLK 作为时钟输入 DB7,DB8作串行输出 字节模式下DB14=1 先高8位后低8位,0时相反 串行或字节模式下不用数字接口需要接地 |
RD/SCLK | 读取/时钟 | 并行模式:RD输入,RD=0 CS=0时开启输出总线 串行模式:CLK时钟输入 |
CS | 片选位 | 低电平有效 |
REF SELECT | 外部/内部基准选择 | 0:外部基准 REF需要输入2.5V 1:内部基准 REF端可提供2.5V基准。 |
BUSY | 忙信号 | 转换开始变高,转换完成变低。一般用下降沿来读数 |
FRSTDATA | 首数据输出 | 首数据时为高,首数据结束时为低,初始为高阻态 |
并口读取STM32F407硬件连接
程序代码:
#ifdef AD7606_C
#define AD7606_PRE
#else
#define AD7606_PRE extern
#endif
#include "sys.h"
#define AD7606_Data_CLK RCC_AHB1Periph_GPIOE
#define AD7606_Data_PORT GPIOE
#define AD7606_Data_PIN GPIO_Pin_All
#define AD7606_OS0_CLK RCC_AHB1Periph_GPIOC
#define AD7606_OS0_PORT GPIOC
#define AD7606_OS0_PIN GPIO_Pin_13
#define AD7606_OS1_CLK RCC_AHB1Periph_GPIOC
#define AD7606_OS1_PORT GPIOC
#define AD7606_OS1_PIN GPIO_Pin_14
#define AD7606_OS2_CLK RCC_AHB1Periph_GPIOC
#define AD7606_OS2_PORT GPIOC
#define AD7606_OS2_PIN GPIO_Pin_15
#define AD7606_RANGE_CLK RCC_AHB1Periph_GPIOC
#define AD7606_RANGE_PORT GPIOC
#define AD7606_RANGE_PIN GPIO_Pin_10
#define AD7606_CONVSTA_CLK RCC_AHB1Periph_GPIOC
#define AD7606_CONVSTA_PORT GPIOC
#define AD7606_CONVSTA_PIN GPIO_Pin_9
#define AD7606_CONVSTB_CLK RCC_AHB1Periph_GPIOC
#define AD7606_CONVSTB_PORT GPIOC
#define AD7606_CONVSTB_PIN GPIO_Pin_8
#define AD7606_RESET_CLK RCC_AHB1Periph_GPIOC
#define AD7606_RESET_PORT GPIOC
#define AD7606_RESET_PIN GPIO_Pin_7
#define AD7606_RD_CLK RCC_AHB1Periph_GPIOC
#define AD7606_RD_PORT GPIOC
#define AD7606_RD_PIN GPIO_Pin_6
#define AD7606_CS_CLK RCC_AHB1Periph_GPIOC
#define AD7606_CS_PORT GPIOC
#define AD7606_CS_PIN GPIO_Pin_2
#define AD7606_BUSY_CLK RCC_AHB1Periph_GPIOC
#define AD7606_BUSY_PORT GPIOC
#define AD7606_BUSY_PIN GPIO_Pin_11
#define AD7606_FRSTDATA_CLK RCC_AHB1Periph_GPIOC
#define AD7606_FRSTDATA_PORT GPIOC
#define AD7606_FRSTDATA_PIN GPIO_Pin_12
#define AD7606_RESET_H() GPIO_SetBits(AD7606_RESET_PORT, AD7606_RESET_PIN)
#define AD7606_RESET_L() GPIO_ResetBits(AD7606_RESET_PORT, AD7606_RESET_PIN)
#define AD7606_CS_H() GPIO_SetBits(AD7606_CS_PORT, AD7606_CS_PIN)
#define AD7606_CS_L() GPIO_ResetBits(AD7606_CS_PORT, AD7606_CS_PIN)
#define AD7606_RD_H() GPIO_SetBits(AD7606_RD_PORT, AD7606_RD_PIN)
#define AD7606_RD_L() GPIO_ResetBits(AD7606_RD_PORT, AD7606_RD_PIN)
#define AD7606_RANGE_H() GPIO_SetBits(AD7606_RANGE_PORT, AD7606_RANGE_PIN)
#define AD7606_RANGE_L() GPIO_ResetBits(AD7606_RANGE_PORT, AD7606_RANGE_PIN)
#define AD7606_OS2_H() GPIO_SetBits(AD7606_OS2_PORT, AD7606_OS2_PIN)
#define AD7606_OS2_L() GPIO_ResetBits(AD7606_OS2_PORT, AD7606_OS2_PIN)
#define AD7606_OS1_H() GPIO_SetBits(AD7606_OS1_PORT, AD7606_OS1_PIN)
#define AD7606_OS1_L() GPIO_ResetBits(AD7606_OS1_PORT, AD7606_OS1_PIN)
#define AD7606_OS0_H() GPIO_SetBits(AD7606_OS0_PORT, AD7606_OS0_PIN)
#define AD7606_OS0_L() GPIO_ResetBits(AD7606_OS0_PORT, AD7606_OS0_PIN)
#define READ_AD7606_CS() GPIO_ReadInputDataBit(AD7606_CS_PORT, AD7606_CS_PIN)
#define READ_AD7606_FRSTDATA() GPIO_ReadInputDataBit(AD7606_FRSTDATA_PORT, AD7606_FRSTDATA_PIN)
#define READ_AD7606_DATA() GPIO_ReadInputData(AD7606_Data_PORT)
#define AD7606_OS0 PCout(13)
#define AD7606_OS1 PCout(14)
#define AD7606_OS2 PCout(15)
#define AD7606_RANGE PCout(10)
AD7606_PRE s16 ADCData[512][8];
AD7606_PRE u16 ADCCnt;
// AD7606_PRE struct ADCStrc AD7606_ADC;
AD7606_PRE void ReadAD7606(void);
AD7606_PRE void AD7606Init(void);
AD7606_PRE void ReadAD7606(void);
AD7606_PRE void InitAD7606_Port(void);
AD7606_PRE void AD7606ChipCfg(void);
AD7606_PRE void AD7606ChipReset(void);
#define AD7606_C
#include "main.h"
// struct ADCStrc AD7606_ADC;
//**************************************************
void AD7606Init(void)
{
InitAD7606_Port();
AD7606ChipCfg();
AD7606ChipReset();
ADCCnt = 0;
}
//**********************************************************************************
void InitAD7606_Port(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_AHB1PeriphClockCmd(AD7606_OS0_CLK | AD7606_Data_CLK, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitStructure.GPIO_Pin = AD7606_Data_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(AD7606_Data_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = AD7606_OS0_PIN | AD7606_OS1_PIN | AD7606_OS2_PIN | AD7606_RANGE_PIN | AD7606_CONVSTA_PIN | AD7606_CONVSTB_PIN;
GPIO_Init(AD7606_OS0_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = AD7606_RESET_PIN | AD7606_RD_PIN | AD7606_CS_PIN;
GPIO_Init(AD7606_RESET_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = AD7606_CONVSTA_PIN | AD7606_CONVSTB_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(AD7606_CONVSTB_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(AD7606_CONVSTB_PORT, GPIO_PinSource8, GPIO_AF_TIM3);
GPIO_PinAFConfig(AD7606_CONVSTA_PORT, GPIO_PinSource9, GPIO_AF_TIM3);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = AD7606_BUSY_PIN | AD7606_FRSTDATA_PIN;
GPIO_Init(AD7606_BUSY_PORT, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource11);
EXTI_InitStructure.EXTI_Line = EXTI_Line11;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
//***************************************
// 配置7606
void AD7606ChipCfg(void)
{
AD7606_OS2_L();
AD7606_OS1_L();
AD7606_OS0_H(); // 001 两倍过采样率 最大64倍过采样率
AD7606_RANGE_L(); // L为5V,H为10V
AD7606_CS_L(); // 片选有效
AD7606_RD_H(); // 读取拉低 并行模式
}
//***************************************
// 复位7606
void AD7606ChipReset(void)
{
AD7606_RESET_H();
__NOP();
__NOP();
AD7606_RESET_L();
__NOP();
__NOP();
}
//***************************************
// 读数据0~7,0:CI,1:BI,2:CI,3:NC,4:CU,5:BU,6:AU,7:NC
void ReadAD7606(void)
{
u8 i;
AD7606_RD_H();
__NOP();
AD7606_CS_L();
__NOP();
for (i = 0; i < 8; i++)
{
AD7606_RD_L();
__NOP();
if (READ_AD7606_FRSTDATA())
i = 0; // 如果7606的第一个数据线为高
ADCData[ADCCnt][i] = READ_AD7606_DATA();
AD7606_RD_H();
__NOP();
}
ADCCnt++;
if (ADCCnt >= 512)
ADCCnt = 0;
AD7606_CS_H();
}
void EXTI15_10_IRQHandler(void)
{
if ((EXTI->PR & EXTI_Line11) != 0) //
{
EXTI->PR = EXTI_Line11;
ReadAD7606();
}
}