AD7606 数据采集模块,16位ADC,8通道同时200KHz频率采集,每秒8*200K样本。SPI接口或8080 16位并口,可自行选择。
AD7606 数据采集模块特性:使用AD7606 高精度16位ADC芯片
8路模拟输入。阻抗1M欧姆。【无需负电源,无需前端模拟运放电路,可直接接传感器输出】
输入范围正负5V,正负10V。可通过IO控制量程。
分辨率 16位。
CS | 片选,低电平有效 |
BUSY | 输出繁忙,低电平时可读取数据 |
FRSTDATA | 数字输出,表示何时回读数据 |
REF | 基准电压选择 |
DB0~DB15 | 16位读取数据输出 |
AD7606c文件 AD7606头文件 延时函数源文件 延时函数头文件
#include "AD7606.h"
#include "DELAY.h"
/***********************************************************************************************
AD7606并口数据读取
************************************************************************************************/
int16_t AD7606_ReadPin(void)
{
int16_t data = 0;
data = (DB15_State << 15) + (DB14_State << 14) + (DB13_State << 13) + (DB12_State << 12) + (DB11_State << 11) + (DB10_State << 10) + (DB9_State << 9) + (DB8_State << 8) +
(DB7_State << 7 ) + (DB6_State << 6) + (DB5_State << 5) + (DB4_State << 4) + (DB3_State << 3 ) + (DB2_State << 2) + (DB1_State << 1 ) + DB0_State ;
return data;
}
/***********************************************************************************************
AD7606读取8组数据
***********************************************************************************************/
uint8_t AD7606_Read(float *Data)
{
uint8_t i = 0;
uint32_t Busy_TimeOut = 0;
AD7606_RESET_H();delay_1us();AD7606_RESET_L();delay_1us();
AD7606_CONVT_L();delay_1us();AD7606_CONVT_H();delay_1us(); //输入一个低脉冲转换信号
if(BUSY_State == 0)
{
while((BUSY_State == 0)&& (Busy_TimeOut < 168)) //等待BUSY信号下降沿
{
Busy_TimeOut++; //读一次需要6ns,10us就是16800
} //等待BUSY信号上升沿
}
Busy_TimeOut = 0;
while((BUSY_State == 1)&& (Busy_TimeOut < 1680)) //等待BUSY信号下降沿
{
Busy_TimeOut++; //读一次需要6ns,10us就是16800
}
if(Busy_TimeOut > 1680)
{
AD7606_RESET_H();delay_1us();AD7606_RESET_L();delay_1us();
return 0;
}
delay_1us();
for(i = 0;i < 8;i++)
{
AD7606_CS_L(); //延时<25ns
delay_1us();;//;;;;; //一个指令周期为5.9ns
Data[i] = AD7606_ReadPin() ;
Data[i] = Data[i] *5.0f /32768.0f;
AD7606_CS_H(); //延时>22ns
delay_1us();//;;;;;;
}
return 1;
}
#ifndef AD7606_HEAD
#define AD7606_HEAD
#include "stm32f4xx_hal.h"
#include "main.h"
/***********************************************************控制部分(输出)**********************************************************/
#define AD7606_CS_H() (HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin ,GPIO_PIN_SET))
#define AD7606_CS_L() (HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin ,GPIO_PIN_RESET))
#define OS0_H() (HAL_GPIO_WritePin(OS0_GPIO_Port, OS0_Pin ,GPIO_PIN_SET))
#define OS0_L() (HAL_GPIO_WritePin(OS0_GPIO_Port, OS0_Pin ,GPIO_PIN_RESET))
#define OS1_H() (HAL_GPIO_WritePin(OS1_GPIO_Port, OS1_Pin ,GPIO_PIN_SET))
#define OS1_L() (HAL_GPIO_WritePin(OS1_GPIO_Port, OS1_Pin ,GPIO_PIN_RESET))
#define OS2_H() (HAL_GPIO_WritePin(OS2_GPIO_Port, OS2_Pin ,GPIO_PIN_SET))
#define OS2_L() (HAL_GPIO_WritePin(OS2_GPIO_Port, OS2_Pin ,GPIO_PIN_RESET))
#define RANGE_H() (HAL_GPIO_WritePin(RANGE_GPIO_Port, RANGE_Pin ,GPIO_PIN_SET))
#define RANGE_L() (HAL_GPIO_WritePin(RANGE_GPIO_Port, RANGE_Pin ,GPIO_PIN_RESET))
#define STBY_H() (HAL_GPIO_WritePin(STBY_GPIO_Port , STBY_Pin ,GPIO_PIN_SET))
#define STBY_L() (HAL_GPIO_WritePin(STBY_GPIO_Port , STBY_Pin ,GPIO_PIN_RESET))
#define AD7606_RESET_H() (HAL_GPIO_WritePin(RESET_GPIO_Port, RESET_Pin ,GPIO_PIN_SET))
#define AD7606_RESET_L() (HAL_GPIO_WritePin(RESET_GPIO_Port, RESET_Pin ,GPIO_PIN_RESET))
#define AD7606_CONVT_H() (HAL_GPIO_WritePin(CONVST_GPIO_Port, CONVST_Pin ,GPIO_PIN_SET))
#define AD7606_CONVT_L() (HAL_GPIO_WritePin(CONVST_GPIO_Port, CONVST_Pin ,GPIO_PIN_RESET))
#define AD7606_ON() (HAL_GPIO_WritePin(STBY_GPIO_Port, STBY_Pin ,GPIO_PIN_SET))
#define AD7606_OFF() (HAL_GPIO_WritePin(STBY_GPIO_Port, STBY_Pin ,GPIO_PIN_RESET))
/***********************************************************数据读取部分(输入)**********************************************************/
#define FRST_State (HAL_GPIO_ReadPin(FRST_GPIO_Port, FRST_Pin))
#define BUSY_State (HAL_GPIO_ReadPin(BUSY_GPIO_Port, BUSY_Pin))
#define DB0_State (HAL_GPIO_ReadPin(DB0_GPIO_Port , DB0_Pin))
#define DB1_State (HAL_GPIO_ReadPin(DB1_GPIO_Port , DB1_Pin))
#define DB2_State (HAL_GPIO_ReadPin(DB2_GPIO_Port , DB2_Pin))
#define DB3_State (HAL_GPIO_ReadPin(DB3_GPIO_Port , DB3_Pin))
#define DB4_State (HAL_GPIO_ReadPin(DB4_GPIO_Port , DB4_Pin))
#define DB5_State (HAL_GPIO_ReadPin(DB5_GPIO_Port , DB5_Pin))
#define DB6_State (HAL_GPIO_ReadPin(DB6_GPIO_Port , DB6_Pin))
#define DB7_State (HAL_GPIO_ReadPin(DB7_GPIO_Port , DB7_Pin))
#define DB8_State (HAL_GPIO_ReadPin(DB8_GPIO_Port , DB8_Pin))
#define DB9_State (HAL_GPIO_ReadPin(DB9_GPIO_Port , DB9_Pin))
#define DB10_State (HAL_GPIO_ReadPin(DB10_GPIO_Port, DB10_Pin))
#define DB11_State (HAL_GPIO_ReadPin(DB11_GPIO_Port, DB11_Pin))
#define DB12_State (HAL_GPIO_ReadPin(DB12_GPIO_Port, DB12_Pin))
#define DB13_State (HAL_GPIO_ReadPin(DB13_GPIO_Port, DB13_Pin))
#define DB14_State (HAL_GPIO_ReadPin(DB14_GPIO_Port, DB14_Pin))
#define DB15_State (HAL_GPIO_ReadPin(DB15_GPIO_Port, DB15_Pin))
#define Power_ON() (HAL_GPIO_WritePin(P_EN_GPIO_Port, P_EN_Pin ,GPIO_PIN_SET))
#define Power_OFF() (HAL_GPIO_WritePin(P_EN_GPIO_Port, P_EN_Pin ,GPIO_PIN_RESET))
#define SPower_ON() (HAL_GPIO_WritePin(S_EN_GPIO_Port, S_EN_Pin ,GPIO_PIN_RESET))
#define SPower_OFF() (HAL_GPIO_WritePin(S_EN_GPIO_Port, S_EN_Pin ,GPIO_PIN_SET))
void AD7606_WORK_ON(void);
void AD7606_WORK_OFF(void);
/***********************************************************函数部分**********************************************************/
void AD7606_Init(void);
uint8_t AD7606_Read(float *Data);
uint8_t AD7606_ReadHEX(int *Data);
#endif
#include "DELAY.h"
#define DWT_CYCCNT *(volatile uint32_t *)0xE0001004
#define DWT_CR *(volatile uint32_t *)0xE0001000
#define DEM_CR_TRCENA (1 << 24)
#define DEM_CR *(volatile uint32_t *)0xE000EDFC
#define DWT_CR_CYCCNTENA (1 << 0)
void Delay_Init(void)
{
//打开CYCCNT功能,并把计数器清零,最后打开计数器对cpu时钟进行向上计数
DEM_CR |= DEM_CR_TRCENA;
// DWT_CYCCNT = 0u; //根据需要如果调试,或其他程序要使用CYCCNT时注释掉,否则可直接清零
DWT_CR |= DWT_CR_CYCCNTENA;
}
void delay_nus(uint32_t us)
{
uint32_t temp;
temp= DWT_CYCCNT;
us *= SystemCoreClock/1000000; //SystemCoreClock官方库自带
while((uint32_t)( DWT_CYCCNT - temp)< us); //溢出也没关系
}
void delay_1us(void)
{
uint32_t temp,us = 1;
temp= DWT_CYCCNT;
us *= SystemCoreClock/1000000; //SystemCoreClock官方库自带
while((uint32_t)( DWT_CYCCNT - temp)< us); //溢出也没关系
}
void delay_nms(uint32_t ms)
{
uint32_t temp;
temp= DWT_CYCCNT;
ms *= SystemCoreClock/1000; //SystemCoreClock官方库自带
while((uint32_t)( DWT_CYCCNT - temp)< ms); //溢出也没关系
}
void delay_1ms(void)
{
uint32_t temp,ms = 1;
temp= DWT_CYCCNT;
ms *= SystemCoreClock/1000; //SystemCoreClock官方库自带
while((uint32_t)( DWT_CYCCNT - temp)< ms); //溢出也没关系
}
#ifndef DELAY_HEAD_
#define DELAY_HEAD_
#include "BSP_Type.h"
void delay_nus(uint32_t us);
void delay_nms(uint32_t ms);
void delay_1us(void);
void delay_1ms(void);
void Delay_Init(void);
#endif
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2022 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "AD7606.h"
#include "DELAY.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
/* USER CODE BEGIN PFP */
float ad [8];
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
Delay_Init();
STBY_H();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
AD7606_Read(ad);
delay_nus(1000);
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LASER_ON_GPIO_Port, LASER_ON_Pin, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(CONVST_GPIO_Port, CONVST_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, STBY_Pin|RESET_Pin|CS_Pin|BUSY_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : DB15_Pin DB14_Pin DB13_Pin */
GPIO_InitStruct.Pin = DB15_Pin|DB14_Pin|DB13_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pins : DB12_Pin DB11_Pin DB10_Pin DB9_Pin
DB8_Pin DB3_Pin */
GPIO_InitStruct.Pin = DB12_Pin|DB11_Pin|DB10_Pin|DB9_Pin
|DB8_Pin|DB3_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/*Configure GPIO pins : DB7_Pin DB6_Pin DB5_Pin DB1_Pin
DB0_Pin DB2_Pin */
GPIO_InitStruct.Pin = DB7_Pin|DB6_Pin|DB5_Pin|DB1_Pin
|DB0_Pin|DB2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : DB4_Pin */
GPIO_InitStruct.Pin = DB4_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(DB4_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : LASER_ON_Pin CONVST_Pin */
GPIO_InitStruct.Pin = LASER_ON_Pin|CONVST_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/*Configure GPIO pins : STBY_Pin RESET_Pin CS_Pin BUSY_Pin */
GPIO_InitStruct.Pin = STBY_Pin|RESET_Pin|CS_Pin|BUSY_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pin : FRST_Pin */
GPIO_InitStruct.Pin = FRST_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(FRST_GPIO_Port, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/