hi,i use the LPC1768 ,
when i use the ADC , i found a problem , i use all the 8 ch,
i use the same signal to test all the ch,
the ch0 ch1 ch2 ch3 ch5 ch6 is OK,but the ch4 have problem
it show
not a line ,and i use oscillscope test the waveform ,it's ok ,not any problem.
this is my prj ,only the ch4 have problem !!!
void ADCInit( uint32_t ADC_Clk )
{
uint32_t i;
LPC_SC->PCONP |= (0x1<<12); /* ʹÄÜADCʱÖÓ . */
for ( i = 0; i < ADC_NUM; i++ )
{
ADCValue[i] = 0x0;
}
/*
* ÅäÖÃADC¹Ü½Å
*/
#if ADCCH0_EN
LPC_PINCON->PINSEL1 &= ~(0X03<<14); //P0.23AD0.0
LPC_PINCON->PINSEL1 |= 0X01<<14;
LPC_GPIO0->FIODIR &=~(0x01<<23);//ADC0.0
#endif
#if ADCCH1_EN
LPC_PINCON->PINSEL1 &= ~(0X03<<16); //P0.24ADC0.1
LPC_PINCON->PINSEL1 |= 0X01<<16;
LPC_GPIO0->FIODIR &=~(0x01<<24);//ADC0.1
#endif
#if ADCCH2_EN
LPC_PINCON->PINSEL1 &= ~(0X03<<18); //P0.25ADC0.2
LPC_PINCON->PINSEL1 |= 0X01<<18;
LPC_GPIO0->FIODIR &=~(0x01<<25);//ADC0.2
#endif
#if ADCCH3_EN
LPC_PINCON->PINSEL1 &= ~(0X03<<20); //P0.26ADC0.3
LPC_PINCON->PINSEL1 |= 0X01<<20;
LPC_GPIO0->FIODIR &=~(0x01<<26);//ADC0.3
#endif
#if ADCCH4_EN
LPC_PINCON->PINSEL3 &=~(0x03<<28); //P1.30AD0.4
LPC_PINCON->PINSEL3 |=0x03<<28;
LPC_GPIO1->FIODIR &=~(0x01<<30);//ADC0.4
#endif
#if ADCCH5_EN
LPC_PINCON->PINSEL3 &=~0xC0000000; //P1.31AD0.5
LPC_PINCON->PINSEL3 |=0xC0000000;
LPC_GPIO1->FIODIR &=~0x80000000;//ADC0.5
#endif
#if ADCCH6_EN
LPC_PINCON->PINSEL0 &=~(0X03<<6); //P0.3--ADC0.6
LPC_PINCON->PINSEL0 |=0X01<<7;
LPC_GPIO0->FIODIR &=~(0X01<<3);//ADC0.6
#endif
#if ADCCH7_EN
LPC_PINCON->PINSEL0 &=~(0X03<<4); //P0.2--ADC0.7
LPC_PINCON->PINSEL0 |=0X01<<5;
LPC_GPIO0->FIODIR &=~(0X01<<2);//ADC0.7
#endif
LPC_ADC->ADCR = ( 0x01 << 0 ) | /* SEL=1,select channel 0~7 on ADC0 */
((SystemFrequency/ADC_Clk-1)<<8) | /* CLKDIV = Fpclk / ADC_Clk - 1 */
( 0 << 16 ) | /* BURST = 0, Èí¼þ¿ØÖÆת»» */
( 1 << 21 ) | /* PDN = 1, ´¦ÓëÕý³£Ä£Ê½ */
( 0 << 24 ) | /* START = 0 ²»Æô¶¯ADת»» */
( 0 << 27 ); /* EDGE = 0 ÉÏÉýÑØÆô¶¯ */
#if ADC_INTERRUPT_FLAG
NVIC_EnableIRQ(ADC_IRQn);
LPC_ADC->ADINTEN = 0xFF; /* ͨµÀ0ת»»½áÊø²úÉúÖÐ¶Ï */
#endif
return;
}
uint32_t ADCRead( uint8_t channelNum )
{
#if !ADC_INTERRUPT_FLAG
uint32_t regVal, ADC_Data;
#endif
if ( channelNum >= ADC_NUM )
{
channelNum = 0; /* ÊäÈëchannelNum´óÓÚ8£¬ÔòÉèÖøòÎÊýΪ0 */
}
LPC_ADC->ADCR &= 0xFFFFFF00;
LPC_ADC->ADCR &=~(0x03<<25);
LPC_ADC->ADCR |= (1 << 24) | (1 << channelNum);
/* Ñ¡Ôñ¶ÔӦͨµÀÁ¢¼´Æô¶¯×ª»» */
#if !ADC_INTERRUPT_FLAG
while ( 1 ) /* µÈ´ýADCת»»Íê³É */
{
regVal = LPC_ADC->DR[channelNum];
if ( regVal & ADC_DONE )
{
break;
}
}
LPC_ADC->CR &= 0xF8FFFFFF; /* ֹͣADC */
/*
* Èç¹ûûÓз¢Éúoverrun´íÎó£¬Ôò±£´æÊý¾Ý
*/
if ( regVal & ADC_OVERRUN )
{
return ( 0 );
}
#if ADC_12BITS
ADC_Data = ( regVal >> 4 ) & 0xFFF;
#else
ADC_Data = ( regVal >> 6 ) & 0x3FF;
#endif
return ( ADC_Data ); /* ·µ»ØADC²ÉÑùÊý¾Ý */
#else
return ( channelNum );
#endif
}
void ADC_WOrk(void)
{
unsigned int Ins_read=0,Ins_re=0;
ADCRead(0);
while(!ADCIntDone);
ADCIntDone = 0;
Ins_read = ADCValue[0];
ADCDataInput[0] = Ins_read*1320/4095;
ADCDataInput[0] =1200-ADCDataInput[0];
ADCRead(1);
while(!ADCIntDone);
ADCIntDone = 0;
Ins_read = ADCValue[1];
ADCDataInput[1] = Ins_read*1320/4095;
ADCDataInput[1] =1200-ADCDataInput[1];
ADCRead(2);
while(!ADCIntDone);
ADCIntDone = 0;
Ins_read = ADCValue[2];
ADCDataInput[2] = Ins_read*1320/4095;
ADCDataInput[2] =1200-ADCDataInput[2];
ADCRead(3);
while(!ADCIntDone);
ADCIntDone = 0;
Ins_read = ADCValue[3];
ADCDataInput[3] = Ins_read*1320/4095;
ADCDataInput[3] =1200-ADCDataInput[3];
ADCRead(4);
while(!ADCIntDone);
ADCIntDone = 0;
Ins_read = ADCValue[4];
Ins_read =Ins_read*1320/4095;
//ADCDataInput[4] =1200-Ins_read;
Ins_re =1200-Ins_read;
ADCDataInput[4] =(Ins_re+ADCDataInput[4]*7)/8;
ADCRead(5);
while(!ADCIntDone);
ADCIntDone = 0;
Ins_read = ADCValue[5];
ADCDataInput[5] = Ins_read*1320/4095;
ADCDataInput[5] =1200-ADCDataInput[5];
ADCRead(6);
while(!ADCIntDone);
ADCIntDone = 0;
Ins_read = ADCValue[6];
ADCDataInput[6] = Ins_read*1320/4095;
ADCDataInput[6] =1200-ADCDataInput[6];
}
Hi ,
Thank you for your interest in NXP Semiconductor products and
the opportunity to serve you.
To provide the fastest possible support, I've attached an ADC demo project, please refer to it for details.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------