CC3200-ADC

来源:互联网 发布:声音可爱的网络歌手 编辑:程序博客网 时间:2024/06/02 05:25

在CC3200SDK-1.2.0上测试可用,下面是main函数的代码:

#include <string.h>#include <stdint.h>#include <stdlib.h>#include <stdio.h>#include <stdbool.h>#include "utils.h"#include "hw_memmap.h"#include "hw_common_reg.h"#include "hw_types.h"#include "hw_adc.h"#include "hw_ints.h"#include "hw_gprcm.h"#include "rom.h"#include "rom_map.h"#include "interrupt.h"#include "prcm.h"#include "uart.h"#include "pinmux.h"#include "pin.h"                          //配置ADC引脚#include "adc.h"                          //ADC相关操作#include "adc_userinput.h"#include "uart_if.h"#define USER_INPUT #define UART_PRINT         Report#define FOREVER            1#define APP_NAME           "ADC Reference"#define NO_OF_SAMPLES       128unsigned long pulAdcSamples[4096];        //12位分辨率、满量程电压为1.4V,最小测量电压为0.34mV(1.4/4096)#if defined(ccs)extern void (* const g_pfnVectors[])(void);#endif#if defined(ewarm)extern uVectorEntry __vector_table;#endifstatic void BoardInit(void);static void DisplayBanner(char * AppName);static voidDisplayBanner(char * AppName){    Report("\n\n\n\r");    Report("\t\t *************************************************\n\r");    Report("\t\t       CC3200 %s Application       \n\r", AppName);    Report("\t\t *************************************************\n\r");    Report("\n\n\n\r");}static voidBoardInit(void){/* In case of TI-RTOS vector table is initialize by OS itself */#ifndef USE_TIRTOS    //    // Set vector table base    //#if defined(ccs)    MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);#endif#if defined(ewarm)    MAP_IntVTableBaseSet((unsigned long)&__vector_table);#endif#endif    //    // Enable Processor    //    MAP_IntMasterEnable();    MAP_IntEnable(FAULT_SYSTICK);    PRCMCC3200MCUInit();}void main(){    unsigned long  uiAdcInputPin;      unsigned int  uiChannel;    unsigned int  uiIndex=0;    unsigned long ulSample;          //    // Initialize Board configurations    //    BoardInit();    //    // Configuring UART for Receiving input and displaying output    // 1. PinMux setting    // 2. Initialize UART    // 3. Displaying Banner    //    PinMuxConfig();    InitTerm();    DisplayBanner(APP_NAME);    while(FOREVER)    {        //        // Initialize Array index for multiple execution        //        uiIndex=0;#ifdef CC3200_ES_1_2_1        //        // Enable ADC clocks.###IMPORTANT###Need to be removed for PG 1.32        //        HWREG(GPRCM_BASE + GPRCM_O_ADC_CLK_CONFIG) = 0x00000043;        HWREG(ADC_BASE + ADC_O_ADC_CTRL) = 0x00000004;        HWREG(ADC_BASE + ADC_O_ADC_SPARE0) = 0x00000100;        HWREG(ADC_BASE + ADC_O_ADC_SPARE1) = 0x0355AA00;#endif        MAP_PinTypeADC(uiAdcInputPin,PIN_MODE_255);          //配置引脚、模式        switch(uiAdcInputPin)        {            case PIN_58:                uiChannel = ADC_CH_1;                        //外部模拟输入通道                break;            case PIN_59:                uiChannel = ADC_CH_2;                break;            case PIN_60:                uiChannel = ADC_CH_3;                break;            default:                break;        }        MAP_ADCTimerConfig(ADC_BASE,2^17);                  //配置ADC定时器        MAP_ADCTimerEnable(ADC_BASE);                       //允许ADC定时器        MAP_ADCEnable(ADC_BASE);                            //允许ADC        MAP_ADCChannelEnable(ADC_BASE, uiChannel);          //允许ADC通道        while(uiIndex < NO_OF_SAMPLES + 4)        {            if(MAP_ADCFIFOLvlGet(ADC_BASE, uiChannel))      //获取阈值            {                ulSample = MAP_ADCFIFORead(ADC_BASE, uiChannel);           //获取数据                pulAdcSamples[uiIndex++] = ulSample;            }        }        MAP_ADCChannelDisable(ADC_BASE, uiChannel);                        //禁止ADC通道        uiIndex = 0;        //UART_PRINT("\n\rTotal no of 32 bit ADC data printed :4096 \n\r");        //UART_PRINT("\n\rADC data format:\n\r");        //UART_PRINT("\n\rbits[13:2] : ADC sample\n\r");        //UART_PRINT("\n\rbits[31:14]: Time stamp of ADC sample \n\r");        while(uiIndex < NO_OF_SAMPLES)        {            UART_PRINT("\n\rVoltage is %f\n\r",(((float)((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))*1.4)/4096);            uiIndex++;        }        UART_PRINT("Sensor2: %f \n\r",MAP_ADCTimerValueGet(ADC_BASE));  //打印ADC计数器的值        UART_PRINT("\n\r");        //getchar();                                                    //停止循环    }}