This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem in ADC initialization

Hello everyone,
I am using lpc2378, I had initialized ADC0 for channel 1 at pin P0.24 in polling. But it is not working. I have given 1V to the pin but it reads only 0. Please check this initialization code

void init_ADC0(void)
{ PCONP |= (1<<12); PINSEL1 |= (1<<16);

AD0CR = ((1<<1) | (1<<21) | (5 << 8));
}

uint16_t read_ADC()
{ uint32_t ADC_data;

AD0CR |= (1<<24); while(!(AD0DR1&0x80000000)); AD0CR &= ~(1<<24); ADC_data = AD0DR1; ADC_data = (ADC_data>>6)&0x3FF; return (uint16_t)ADC_data;
} Is there anything wrong in my code ?

Iqbal

Parents
  • Ok, I am giving you the sample of the above code again.

    void init_ADC(void)
    {
    uint32_t clk_div;
    
            PCONP |= (1<<12);
            PINSEL1 |= (1<<16);
            clk_div = SET_ADC0_CLK_AT_kHz(3000);
    
            AD0CR = (ADC0_CH_1 | PDN | (clk_div << 8));
    }
    
    uint16_t read_ADC_data()
    {
    uint32_t ADC_data;
    
            AD0CR |= START_ADC0_CONV;
            while(!(AD0DR1 & DONE));
            AD0CR &= STOP_ADC0_CONV;
            ADC_data = (AD0DR1 >> 6)&0x3FF;
             return (uint16_t)ADC_data;
    }
    
    

    Please give me any solution.

Reply
  • Ok, I am giving you the sample of the above code again.

    void init_ADC(void)
    {
    uint32_t clk_div;
    
            PCONP |= (1<<12);
            PINSEL1 |= (1<<16);
            clk_div = SET_ADC0_CLK_AT_kHz(3000);
    
            AD0CR = (ADC0_CH_1 | PDN | (clk_div << 8));
    }
    
    uint16_t read_ADC_data()
    {
    uint32_t ADC_data;
    
            AD0CR |= START_ADC0_CONV;
            while(!(AD0DR1 & DONE));
            AD0CR &= STOP_ADC0_CONV;
            ADC_data = (AD0DR1 >> 6)&0x3FF;
             return (uint16_t)ADC_data;
    }
    
    

    Please give me any solution.

Children
No data