ADC,就是模拟量转换成数字量的一种器件,一种将自然界连续的信号转化成离散的电信号发送给设备。
在MSP432中,自带ADC14,一个14位的ADC,好像按照官方的说法这个ADC的速度比MSP430的速度快10倍。
具体ADC的内容数电书上都有,什么并联比较型啊,逐次逼近型啊之类,上网百度一下就有。
关于我们在MSP432中如何使用这个ADC呢,TIDrivers里有非常强大的库我们可以直接使用。
首先我们要了解几个概念:量程分辨率采样速率。调用十分简单
/*
* ======== adcsinglechannel.c ========
*/
#include #include /* POSIX Header files */ #include /* Driver Header files */ #include #include /* Driver configuration */ #include "ti_drivers_config.h" /* ADC sample count */ #define ADC_SAMPLE_COUNT (10) #define THREADSTACKSIZE (768) /* ADC conversion result variables */ uint16_t adcValue0; uint32_t adcValue0MicroVolt; uint16_t adcValue1[ADC_SAMPLE_COUNT]; uint32_t adcValue1MicroVolt[ADC_SAMPLE_COUNT]; static Display_Handle display; /* * ======== threadFxn0 ======== * Open an ADC instance and get a sampling result from a one-shot conversion. */ void *threadFxn0(void *arg0) { ADC_Handle adc; ADC_Params params; int_fast16_t res; ADC_Params_init(¶ms); adc = ADC_open(CONFIG_ADC_0, ¶ms); if (adc == NULL) { Display_printf(display, 0, 0, "Error initializing ADC0n"); while (1); } /* Blocking mode conversion */ res = ADC_convert(adc, &adcValue0); if (res == ADC_STATUS_SUCCESS) { adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0); Display_printf(display, 0, 0, "ADC0 raw result: %dn", adcValue0); Display_printf(display, 0, 0, "ADC0 convert result: %d uVn", adcValue0MicroVolt); } else { Display_printf(display, 0, 0, "ADC0 convert failedn"); } ADC_close(adc); return (NULL); } /* * ======== threadFxn1 ======== * Open a ADC handle and get an array of sampling results after * calling several conversions. */ void *threadFxn1(void *arg0) { uint16_t i; ADC_Handle adc; ADC_Params params; int_fast16_t res; ADC_Params_init(¶ms); adc = ADC_open(CONFIG_ADC_1, ¶ms); if (adc == NULL) { Display_printf(display, 0, 0, "Error initializing ADC1n"); while (1); } for (i = 0; i < ADC_SAMPLE_COUNT; i++) { res = ADC_convert(adc, &adcValue1[i]); if (res == ADC_STATUS_SUCCESS) { adcValue1MicroVolt[i] = ADC_convertRawToMicroVolts(adc, adcValue1[i]); Display_printf(display, 0, 0, "ADC1 raw result (%d): %dn", i, adcValue1[i]); Display_printf(display, 0, 0, "ADC1 convert result (%d): %d uVn", i, adcValue1MicroVolt[i]); } else { Display_printf(display, 0, 0, "ADC1 convert failed (%d)n", i); } } ADC_close(adc); return (NULL); } /* * ======== mainThread ======== */ void *mainThread(void *arg0) { pthread_t thread0, thread1; pthread_attr_t attrs; struct sched_param priParam; int retc; int detachState; /* Call driver init functions */ ADC_init(); Display_init(); /* Open the display for output */ display = Display_open(Display_Type_UART, NULL); if (display == NULL) { /* Failed to open display driver */ while (1); } Display_printf(display, 0, 0, "Starting the acdsinglechannel examplen"); /* Create application threads */ pthread_attr_init(&attrs); detachState = PTHREAD_CREATE_DETACHED; /* Set priority and stack size attributes */ retc = pthread_attr_setdetachstate(&attrs, detachState); if (retc != 0) { /* pthread_attr_setdetachstate() failed */ while (1); } retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE); if (retc != 0) { /* pthread_attr_setstacksize() failed */ while (1); } /* Create threadFxn0 thread */ priParam.sched_priority = 1; pthread_attr_setschedparam(&attrs, &priParam); retc = pthread_create(&thread0, &attrs, threadFxn0, NULL); if (retc != 0) { /* pthread_create() failed */ while (1); } /* Create threadFxn1 thread */ retc = pthread_create(&thread1, &attrs, threadFxn1, (void* )0); if (retc != 0) { /* pthread_create() failed */ while (1); } return (NULL); }
上一篇:NO.20 MSP432的功耗模式介绍
下一篇:NO.16 PWM的概念以及MSP432中如何调用
推荐阅读最新更新时间:2024-11-09 09:52
设计资源 培训 开发板 精华推荐
- DC2094A-A,用于 LTC2348-18 八路、同步、18 位、200 ksps SAR ADC 的演示板
- IS31AP2005 2.95W单声道无滤波器D类音频功率放大器差分输入典型应用
- LT1317CMS8 低噪声 33V 变容二极管偏置电源的典型应用电路
- YS13-3荧光管时钟
- 使用 Analog Devices 的 LTC2376CMS-18 的参考设计
- 模块化多路触摸继电器V1.1
- STM32F10xxx USART 应用实例 STM32F10xxx USART IrDA 接口
- 400W、400V 交流转直流单路输出电源,适用于台式电脑电源
- (测试版)USB转485/232/TTL
- DC2539A-A,基于 LT4295/LT4321 PoE++(51W,12V/3.9A)PD 的演示板,具有反激 DC/DC,理想二极管桥