lpcware

LPC1769 unexpected value returns from ADC

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Kat on Mon Oct 21 00:35:23 MST 2013
Hi,
I'm using the one analog CH of LPC1769 ADC by ADC CLOCK 1MHz Polling read.
If Read of the ADC is carried out continuously Inaccurate data sometimes like 0xfff is acquired.
If Read may be carried out 50x500 times and there may be no inaccurate data
Inaccurate data may be acquired by 50x10 times of Read(s).
Of course, AD input is not changed.
Would you teach the evasion method, if the direction which experienced such a situation and was avoided comes?
The test code used for reference is attached.

Test code
---------------------------------------------------------------------
    // AD initialize  (AD0.0 1MHz polling read)
    LPC_SC->PCONP |= (1 << 12);
    LPC_PINCON->PINSEL1 &= ~0x0000C000;// P0.23 A0.0 function 01
    LPC_PINCON->PINSEL1 |=  0x00004000;
    LPC_PINCON->PINMODE1 &= ~0x0000C000;// No pull-up no pull-down (function 10)
    LPC_PINCON->PINMODE1 |=  0x00008000;
    pclkdiv = (LPC_SC->PCLKSEL0 >> 24) & 0x03;
    switch ( pclkdiv ) {
    case 0x00:
    default:
        pclk = SystemCoreClock/4;
        break;
    case 0x01:
        pclk = SystemCoreClock;
        break;
    case 0x02:
        pclk = SystemCoreClock/2;
        break;
    case 0x03:
        pclk = SystemCoreClock/8;
        break;
    }
    LPC_ADC->ADCR = ( 0x01 << 0 ) | ( ( pclk  / ADC_Clk - 1 ) << 8 ) | 
( 0 << 16 ) | ( 0 << 17 ) | ( 1 << 21 ) | ( 0 << 24 ) | ( 0 << 27 );

    for(;;){
        for(i=0, j=0; i<50; i++) {
            LPC_ADC->ADCR &= 0xFFFFFF00;
            LPC_ADC->ADCR |= (1 << 24) | (1 << 0);// start adc
            for(;;){
regVal = DR[0];         // read result of A/D conversion
                if ( regVal & ADC_DONE )
    break;
            }
            LPC_ADC->ADCR &= 0xF8FFFFFF;// stop ADC now
            if ( regVal & ADC_OVERRUN ) {
                adspl = 0x1000;
continue;
            }
            adspl = ( regVal >> 4 ) & 0xFFF;
        }
    }


Outcomes