LPC21xx ADC Problem

I have just started writing a simple application for the LPC2129. I have a problem with polling the DONE bit of the ADC.

The ADC clock is 3.68 MHz. I set the ADC to be 10 bits, single shot. I start the ADC and then poll the done bit like this:-
while( !(ADDR & 0x80000000) );
The code is compiled using the Keil ARM tools (demo version). When I run the code on the simulator it works correctly, when I run it on the target it returns incorrect values.

The returned value does track the input voltage but is quantised to 0x0000, 0x6000, 0x8000 or 0xE000 (Only 4 discrete values).

If I single step or place a delay function before polling the DONE bit then the code runs correctly.

Am I doing something wrong or is there a problem with polling this bit?

Parents
  • The UM is ambiguous about the state of the
    sample value when DONE=0. Since I prefer not
    to depend on anything that isn't explicitly
    stated in the manual, I use the alternative
    coding

    do { r = ADDR; } while (!(r & DONEMASK));

    [This message brought to you by your
    Department of Magic and Superstition.]

Reply
  • The UM is ambiguous about the state of the
    sample value when DONE=0. Since I prefer not
    to depend on anything that isn't explicitly
    stated in the manual, I use the alternative
    coding

    do { r = ADDR; } while (!(r & DONEMASK));

    [This message brought to you by your
    Department of Magic and Superstition.]

Children
More questions in this forum