其中需要用到ADCCON,ADCDAT,ADCMUX
单个A/D转化频率=ADC的时钟源频率/(预分频值+1)
A/D转化时间=A/D周期数/单个A/D转换的频率
例子:假如ADC的时钟源频率为100MHZ,预分频值为99,ADC周期数为5
A/D转换时间=5/1MHZ=5/1 000 000=5 000 ms =5 us
(最大输入电压 X ADCDAT_Value)/ 2分辨率位数 =实际电压
#include "exynos_4412.h"
void delay(unsigned int i)
{
while(i--);
}
void ADC_Init()
{
/* 配置ADC分辨率 12bit*/
ADCCON |= (1 << 16);
/* 打开分频器 */
ADCCON |= (1 << 14);
/* 配置分频系数 100,转换周期为 5/(100Mhz/100) = 5us*/
ADCCON = ADCCON & (~(0xFF << 6)) | (99 << 6);
/* 关闭低功耗模式 */
ADCCON &= (~(1 << 2));
/* 关闭连续转换模式 */
ADCCON &= (~(1 << 1));
/* 选择转换通道 */
ADCMUX = 0x3;
}
/**
* @description: 获取转化的电压
* @param {*}
* @return {*}
*/
unsigned int ADC_do()
{
unsigned int ADCvalue;
/* 打开单次转换模式 */
ADCCON |= 1;
/* 检查转换是否完成 */
while(!(ADCCON & (1 << 15)));
/* 接收数据 */
ADCvalue = ADCDAT & 0xFFF;
/* 转化数据,单位:mv,m*(1.8/2^12)*1000 */
ADCvalue *= 0.44;
return ADCvalue;
}
int main()
{
unsigned int ADCvalue;
ADC_Init();
while(1)
{
ADCvalue = ADC_do();
if(ADCvalue <= 1800 && ADCvalue >= 1501)
{
delay(1000000);
printf("ADCvalue =%dmv\n", ADCvalue);
delay(1000000);
}
else if(ADCvalue <= 1500 && ADCvalue >= 1001)
{
delay(1000000);
printf("ADCvalue =%dmv\n", ADCvalue);
delay(1000000);
}
else if(ADCvalue <= 1000 && ADCvalue >= 501)
{
delay(1000000);
printf("ADCvalue =%dmv\n", ADCvalue);
delay(1000000);
}
else if(ADCvalue <= 500 && ADCvalue >0)
{
delay(1000000);
printf("ADCvalue =%dmv\n", ADCvalue);
delay(1000000);
}
printf("ADCvalue =%dmv\n", ADCvalue);
}
return 0;
}