ADC在11个时钟,10位精度下工作,负载为电机,待测值为:70mv,VREF为:3.22mvAD0DR0应该为20到23,可实际上AD0DR0从10到30之间不断变化,每次AD转换的值都不同,这是为什么,难道LPC11C14的AD对mv的转换不行
|
程序如下:
void ADCInit( uint32_t ADC_Clk )
{
uint32_t i;
LPC_IOCON->R_PIO1_0 = 0x02; // ADC IN1 //
LPC_IOCON->PIO1_11 = 0x01; // ADC IN7 //
LPC_SYSCON->PDRUNCFG &= ~(0x1<<4);
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<13);
for ( i = 0; i < 8; i++ ) //
{
ADCValue = 0x0;
}
//------------------------------硬件扫描模式------------------------------------------
LPC_ADC->CR = ( 0x82 << 0 ) | // SEL=1,select channel 0~7 on ADC0 ADC7
( ( SystemAHBFrequency / ADC_Clk - 1 ) << 8 ) | // CLKDIV = Fpclk / 1000000 - 1
( 1 << 16 ) | // BURST = 0, no BURST, software controlled
( 1 << 17 ) | // CLKS = 0, 11 clocks/10 bits 9/8 bit
( 0 << 24 ) | // START = 0 A/D conversion stops
( 0 << 27 ); // EDGE = 0 (CAP/MAT singal falling,trigger A/D conversion)
//-------------------------------------------------------------------------------------
return;
}
uint32_t ADCRead( uint8_t channelNum )
{
uint32_t regVal=0, ADC_Data=0;
if ( channelNum >= ADC_NUM )
{
channelNum = 0;
}
//------------------------------硬件扫描模式------------------
while((LPC_ADC->DR[channelNum] & 0x80000000) == 0);
regVal = LPC_ADC->DR[channelNum];
if ( regVal & ADC_OVERRUN )
{
return ( 0 );
}
ADC_Data = ( regVal >> 6 ) & 0x3FF;
//---------------------------------------------------------
return ( ADC_Data );
}
ad1=0,ad7=0; adv=0;
for(k=0;k<10;k++)
{
ad1 = ADCRead(7);
ad7 = ad7 + ad1;
}
adv=ad7/10;
AD引脚上有3个分支,一是接到采样电阻上,以测量电流;二是接到74HC04反相器上;三是接了个5.6V的稳压管
在采样电阻之前是H桥电机电路 |