如果最终得到的数据是两路数据的差值, 我们可以采用ADC的 Difference 工作模式
#include <stdbool.h> #include <stdint.h> #include "inc/hw_memmap.h" #include "driverlib/adc.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" #include "user/LCDDriver.h" #define abs(x) (((x)<0)? -(x):(x)) uint32_t pui32ADC0Value[1]={0}; //这是我们的数据缓存, ADC采样数据存储在这里
void adcConfig(){ SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_1); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3 | GPIO_PIN_2); //初始化ADC所使用的GPIO
ADCSequenceConfigure(ADC1_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC1_BASE, 3, 0, ADC_CTL_D | ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); //这里我们选择了两路差工作模式ADC_CTL_D
ADCSequenceEnable(ADC1_BASE, 3); ADCIntClear(ADC1_BASE, 3); }//使能 bool isRisk(){//数据采集程序 GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 255); ADCProcessorTrigger(ADC1_BASE, 3); while(!ADCIntStatus(ADC1_BASE, 3, false)); ADCIntClear(ADC1_BASE, 3); ADCSequenceDataGet(ADC1_BASE, 3, pui32ADC0Value); //AIN0(PE3) - AIN1(PE2) LCD_Draw_Num(pui32ADC0Value[0],0,7,0,false); LCD_Draw_Line_Clear(6,false); if(pui32ADC0Value[0] > 500) return true; else return false; }
关于ADc的引脚, 参考reference
关于ADC的模式:
参考reference
时间: 2024-10-03 13:45:08