测试YL-KL26Z板子上的ADC。
查了一下板子的电路图,可以看出PE20上接了个可调电阻,如图:
701.jpg (68.72 KB, 下载次数: 0)
下载附件
2015-5-24 21:30 上传
直接上主程序:- #include "includes.h"
- void myDelay(INT32U ulTime);
- int main(void)
- {
- INT16U ADC_Value = 0;
- FP32 V_Value = 0;
-
- SystemCoreClockUpdate();
-
- uart0Init(115200,0,0,8,1);
- adcInit();
-
- printf("YL-K26Z开发板ADC测试:\r\n");
- while (1)
- {
- ADC_Value = adcGetUint();
- V_Value = (ADC_Value * 3.3) / 65535;
- printf("ADC_Value = %d\t\tV_Value = %fV\n", ADC_Value, V_Value);
- myDelay(200);
- }
- }
- void myDelay(INT32U ulTime)
- {
- INT32U i;
- i = 0;
- while (ulTime--)
- {
- for (i = 0; i < 5000; i++);
- }
- }
由于KL26Z开发板用的是ADC0,单端模式,REF为3.3V。所义当ADC_IN为3.3V时 ADC为65535, 0V时为0。
因此可以V_Value = (ADC_Value * 3.3) / 65535;即可计算出当前电位器上的电压。
调整电位器旋钮,在串口上就可以看到电压值,非常不精确的电压表。 

|