|
最近忙写论文,有一段时间没有更新了,东西忘得真够快的啊。好在有坚持做笔记的习惯,回顾下之前写的学习经验,随便改了下几个错别字,大概都记得了。今天我们学习下ADC部分,先看看LPC的ADC的特点:
z 10 位逐次逼近式模数转换器;
z 测量范围:0~3.3V;
z 10 位转换时间≥2.44us;
z 一路或多路输入的 Burst转换模式;
z 转换触发信号可选择:输入引脚的跳变或定时器的匹配;
z 具有掉电模式。
代码如下:
//主函数
void main(void)
{
double ADCresmV;
unsigned int ADCresult;
char buf[100];
//初始化IO口
/* Configure the Analog to Digital converter */
AD0CR_bit.SEL = 2; //enable AD0.1 only
AD0CR_bit.CLKDIV = PCLKFREQ / 4500000;
AD0CR_bit.BURST = 1; // put A/D into continuous convert mode
AD0CR_bit.CLKS = 0; //11 clocks/10 bit accuracy
AD0CR_bit.PDN = 1; //power up the unit
PINSEL1_bit.P0_28 = 1; // This is probably the potentiometer output
//开始转换
AD0CR_bit.START = 0x0001; //start 1st cnvrsn immediately
//初始化UART1
InitUart1();
while(1)
{
/* Fetch the last A/D conversion and start up the A/D for the next one */
while(AD0DR_bit.DONE == 0); //wait until conversion done
AD0DR_bit.CHN = 0; // Data in channel 0
ADCresult = AD0DR_bit.VVDDA ; // save the converted data
ADCresmV = (ADCresult>>2)*3.3/256.00; // 10 bit resolution, 3V max
//将转换后的结果通过串口发送出去
sprintf(buf,"potentiometer now reads %4.2fV\n\r",ADCresmV);
sendStr(buf);
Delayn(1000000);
AD0CR_bit.START = 0x0001; // start the next conversion
}
}