|
ADC获取某点电压值,范围只有0~1.65v,M4的内部参考电压不是3.3v吗?
我用了 ADCReferenceSet (ADC0_BASE,ADC_REF_INT); 但是结果没有用。
M4可以接入更高的参考电压吗?
#include "stdint.h"
#include "stdbool.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/interrupt.h"
#include "driverlib/adc.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "LCDDriver.h"
void Init_ADC_Detect()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH10 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 3);
ADCIntClear(ADC0_BASE, 3);
}
int main(void)
{
uint32_t Average;
uint32_t pui32ADC0Value[1];
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
LCD_Enable();
LCD_Init();
LCD_ScreenClr();
LCD_Draw_Chinese(1,1,0);
LCD_Draw_Chinese(2,1,16);
LCD_Draw_Char_8x16(':',1,32);
LCD_Draw_Char_8x16('V',1,119);
Init_ADC_Detect();
while(1)
{
SysCtlDelay(SysCtlClockGet()/4);
ADCProcessorTrigger(ADC0_BASE, 3);
while(!ADCIntStatus(ADC0_BASE, 3, false))
{}
ADCIntClear(ADC0_BASE, 3);
ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
Average = (pui32ADC0Value[0] * 1650) / 4096;
unsigned char data1[4] = {0};
data1[0] = pui32ADC0Value[0] / 1000;
data1[1] = (pui32ADC0Value[0] / 100) % 10;
data1[2] = (pui32ADC0Value[0] / 10) % 10;
data1[3] = (pui32ADC0Value[0] / 1) % 10;
int k;
for(k = 0; k < 4; ++k)
{
LCD_Draw_Char_8x16('0' + data1[k], 3, 50 + 8 * k);
}
int i = 0 ;
unsigned char data[4] = {0};
data[0] = (Average / 1000);
data[1] = (Average / 100) % 10;
data[2] = (Average / 10) % 10;
data[3] = (Average / 1) % 10;
for(i = 0; i < 4; ++i)
{
LCD_Draw_Char_8x16('.', 1, 50 + 10 * 1);
if(i < 1)
LCD_Draw_Char_8x16('0' + data[i], 1, 50 + 10 * i);
else
LCD_Draw_Char_8x16('0' + data[i], 1, 50 + 10 * (i + 1));
}
}
}
|
|