ADC.h 2.87 KB
Newer Older
崔立宝's avatar
崔立宝 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/******************************************************************************
文 件 名:ADC.h
功能描述:ADC驱动库头文件
作    者:张暄
版    本:V1.0
日    期:2017.03.25
******************************************************************************/

#ifndef _ADC_H_
#define _ADC_H_

#include "stdint.h"
#include "mc9s12xhy256.h"
#include "CRG.h"

/******************************************************************************
ADC全局配置
******************************************************************************/
#define   ADC_RESOLUTION_BIT                10
#define   ADC_SAMPLE_POINT                  16
#define   ADC_CLOCK                         4000000
#define   ADC_VREF                          5000            //参考电压,单位:mV              
#define   ADC_MAX_CHANNEL_CNT               12
//#define ADC_CONV_VALUE_MAX                ----            //转换结果最大值,随分辨率一起定义

/******************************************************************************
ADC转换状态
******************************************************************************/
#define   ADC_CONV_COMPLETE                 0x00
#define   ADC_CONV_NOT_COMPLETE             (!ADC_CONV_COMPLETE)

/******************************************************************************
ADC参数预处理
******************************************************************************/

/*** 分辨率 ***/
#if   (ADC_RESOLUTION_BIT == 8)
#define ADC_ATDCTL1_VALUE                 0x0F
#define ADC_CONV_VALUE_MAX                255
#elif (ADC_RESOLUTION_BIT == 10)
#define ADC_ATDCTL1_VALUE                 0x2F
#define ADC_CONV_VALUE_MAX                1023
#else
#error Unsupported ADC resolution
#endif

/*** 采样点 ***/
#if   (ADC_SAMPLE_POINT == 4)
#define ADC_SMP_VALUE                     0x00
#elif (ADC_SAMPLE_POINT == 6)
#define ADC_SMP_VALUE                     0x20
#elif (ADC_SAMPLE_POINT == 8)
#define ADC_SMP_VALUE                     0x40
#elif (ADC_SAMPLE_POINT == 10)
#define ADC_SMP_VALUE                     0x60
#elif (ADC_SAMPLE_POINT == 12)
#define ADC_SMP_VALUE                     0x80
#elif (ADC_SAMPLE_POINT == 16)
#define ADC_SMP_VALUE                     0xA0
#elif (ADC_SAMPLE_POINT == 20)
#define ADC_SMP_VALUE                     0xC0
#elif (ADC_SAMPLE_POINT == 24)
#define ADC_SMP_VALUE                     0xE0
#else
#error Unsupported ADC sample point
#endif

/*** 时钟 ***/
#if (ADC_CLOCK < 250000)
#error ADC clock is too low
#elif (ADC_CLOCK > 8300000)
#error ADC clock is too high
#else
#define ADC_PRS_VALUE                     (BUSCLK / ADC_CLOCK / 2 - 1)
#endif

/******************************************************************************
函数声明
******************************************************************************/
void ADC_Init(void);
void ADC_Channel_Enable(uint8_t Ch);
void ADC_Start_Conversion(uint8_t Ch);
uint8_t   ADC_Get_Conversion_Status(void);
uint16_t  ADC_Get_Conversion_Result(void);

#endif