文件信息
概要 使用ADC转换出输入端对应数据
适用范围 NUC100 系列
目录
1 简述
使用ADC转换出输入端的电压值, 再经由转换公式获取实际对应的数据.
1.1 环境需求与设定
1.2 芯片设定
2 程序介绍
2.1 Main 函数
初始化ADC, 设置成单端输入模式与单次循环模式
/* 配置 GPIOA.0 脚 功能口为 ADC0 */ DrvGPIO_InitFunction(E_FUNC_ADC0); /* ADC 时钟源 = HIRC (22.1184 MHz), 单端模拟输入模式 */ DrvADC_Open(ADC_SINGLE_END,ADC_SINGLE_CYCLE_OP, 1, INTERNAL_HCLK, 0); ADC->ADSR.ADF = 1; // 保险起见,清除A/D转换结束标志 ADC->ADCR.ADIE = 1;
待ADC转换完成, 读取出ADC转换后的值. 再通过转换公式, 计算出实际的对应值, 然后重复上述动作.
此范例的转换公式为: 计算结果= (ADC转换值 –2200) / 1600
while(ADC->ADSR.ADF==0); ADC->ADSR.ADF=1; // 清除A/D转换结束标志 printf("%d\n\r",ADC->ADDR[0].RSLT); // 计算实际A/D转换值 printf("%f\n\r",(float)(ADC->ADDR[0].RSLT-2200)/(float)1600); Delay(60000); Delay(60000); Delay(60000); ADC->ADCR.ADST=1; // 重新开始A/D转换
3 运行结果
由KEIL 串行 串口所打印出的信息, 分别显示出ADC转换后的数据以及再通过公式转换后的数据.
显示结果如下:
版本历史
Revision Date Description
1.00 Aug. 15, 2013 初始发布.
Important Notice
Nuvoton products arenot designed, intended, authorized or warranted for use as components insystems or equipment intended for surgical implantation, atomic energy controlinstruments, airplane or spaceship instruments, transportation instruments,traffic signal instruments, combustion control instruments, or for otherapplications intended to support or sustain life. Furthermore, Nuvoton productsare not intended for applications wherein failure of Nuvoton products couldresult or lead to a situation wherein personal injury, death or severe propertyor environmental damage could occur.
Nuvoton customersusing or selling these products for use in such applications do so at their ownrisk and agree to fully indemnify Nuvoton for any damages resulting from suchimproper use or sales.
Pleasenote that all data and specifications are subject to change without notice. Allthe trademarks of products and companies mentioned in this datasheet belong totheir respective owners.
|