lpcware

LPC1225 ADC

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Redbull68 on Wed May 28 05:31:42 MST 2014
Hi,

I try to use the on chip ADC but I have a problem with the result.
I use the software control to start and stop acquisiton on AD0 pin where a generator is connected to have a stable voltage.


void HalAdcInit(void)
{
    // Configure pin as ADC peripheral
    IOCON_PIO0_30 |= 3;         // channel AD0
    IOCON_PIO0_30 &= 0xFF7F;    // Pin as analog
   
    PDRUNCFG_bit.ADC_PD = 0;    // Enable Power on ADC
    SYSAHBCLKCTRL_bit.ADC = 1;  // Enable ADC clock
   
    AD0CR_bit.CLKDIV = 3;       // Divider (value + 1) for APB clock to have an ADC clock
                                // less than 9 MHz
                                // ADC clock = System clock / (CLKDIV + 1)
                                //             33177600 / 4
                                //             8294400 Hz
   
    AD0CR_bit.SEL = 1;
   
    AD0CR_bit.BURST = 0;        // Conversion are software controlled
    AD0CR_bit.START = 0;        // A/D conversion stop
   
}/*END HalAdcInit*/



void HalAdcTest2(void)
{
    UVAR_16     i;
    UVAR_16     tab[400];
   
    memset(tab, 0, sizeof(tab));
    while (1)
    {
        for (i = 0; i < 400; i++)
        {
            AD0CR_bit.START = 1;
            while (AD0DR0_bit.DONE != 1);
            AD0CR_bit.START = 0;
            tab = AD0DR0_bit.RESULT;
        }
    }
}


I do the initialisation and after only HalAdcTest2 function running.
When i run the loop only 1 time, data in tab is good but if I launch continually the function and i stop in the fly, data in tab is not good( sequence of 0x003F and 0x03C1)

Outcomes