ADC:模拟信号转化为数字信号
1、S3C2440对于ADC的编程,最要做好两个寄存器的配置
(1)、ADCCON控制寄存器的设置
/*AD转换频率设置,最大频率为2.5MHz*/
rADCCON = (1<<14)|(preScaler<<6)|(channel<<3);//setup channel
(2)、ADCDAT0寄存器数据的读取
int ReadAdc(int channel)
{
/*开启AD转换*/
rADCCON |= 0x01; //start ADC
while(rADCCON & 0x1);//check if Enable_start is low
while(!(rADCCON & 0x8000));//check if EC(End of Conversion) flag is high
return ( (int)rADCDAT0 & 0x3ff );
2、对于初始化程序的理解}
void adc_init(void)
{
int channel=0; //AIN0,对应开发板上W1可调电阻
preScaler = ADC_FREQ; // #define ADC_FREQ 2500000
Uart_Printf("ADC conv,freq. = %dHz\n",preScaler);
preScaler = 50000000/ADC_FREQ - 1; //PCLK=50M //这样的设置到底有什么意思呢???
Uart_Printf("PRSCVL=PCLK/ADC_FREQ - 1=%d\n",preScaler);
/*AD转换频率设置,最大频率为2.5MHz*/
rADCCON = (1<<14)|(preScaler<<6)|(channel<<3);//setup channel
delay(1000);
}