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

LPC2148 ADC working but incorrectly

hey

i am using LPC 2148. and configured the hardware for taking the analog signal at P0.28 which is ADC0 channel 1.

i am using following code but the output stays 0 or 1023 only.

my hardware connections are verified with several ready made boards and kits for the same controller..

kindly check and help for my problem..

thanks


#include<lpc214x.h>
#include<stdio.h>


//VPB clock 30Mhz
void delay(int);

extern long val,stat,s;
extern long adc_val;


int main()
{
        serial_init();
        clear_arrays();
        adc_init();
        //printf("MISSAR SYSTEMS\n\n");

        while(1)
        {

                adc_read();
                printf("%i\n",adc_val);
                delay(1000);
        }
}

void adc_init(void)
{
        PINSEL1 = 0x01000000;   // P0.28 - AD0.1
        PCONP |= 0x00001000;
        AD0CR &= 0x00000000;
        AD0CR |= 0x00201302; // with clock = PCLK/(7+1) = 30Mhz/8 = 3.75Mhz
        AD0INTEN &= 0x00000000;

}

void adc_read(void)
{
        AD0CR |= 0x01000000;    // Start AD conversion NOW on AD0.1 (P0.28)
        delay(100);
        do
        {
                val = AD0DR1;    // Get value
        } while ((val & 0x80000000) == 0);  // until bit 31 is high (DONE)

        val = (val>>6);
        adc_val = val & 0x3FF;       // Extract AD result
}

void delay(int delay_value)
{
        int out_delay=0,in_delay=0;

        for(out_delay=0 ; out_delay < delay_value ; out_delay++)
        {
                for(in_delay=0 ; in_delay <= 1000 ; in_delay++);
        }
}

Parents
  • yes sir.

    firstly the problem is solved..

    i have measured the voltage on the pin itself.. and it was 2.5v only on pin.
    but the problem was the pin next to the Vref pin was having some king of short ckt with the vref.

    actually the short ckt was not visible. but when u teld me that it seems like 0v ref so i just tried to re solder and removed any short ckt by blade.

    and it worked..

    thanks a lot for your support..

    also for many people facing the same problem..
    Do always verify the hardware..

    thanks

Reply
  • yes sir.

    firstly the problem is solved..

    i have measured the voltage on the pin itself.. and it was 2.5v only on pin.
    but the problem was the pin next to the Vref pin was having some king of short ckt with the vref.

    actually the short ckt was not visible. but when u teld me that it seems like 0v ref so i just tried to re solder and removed any short ckt by blade.

    and it worked..

    thanks a lot for your support..

    also for many people facing the same problem..
    Do always verify the hardware..

    thanks

Children