AnalogIn format

05 Oct 2010

I am using read_u16 and it appears that the least significant nibble is always 6.  Are you left justifying the 12 bit ADC result?  Is the actual code for your functions available to see what you are doing?  How would you do an actual LPC register read/write? Do you have defines already that use the data sheet register names?

05 Oct 2010

Here's the code that transforms the value read from ADGDR:

UBFX.W  R0, R0, #4, #0xC
LSRS    R1, R0, #8
ORR.W   R0, R1, R0,LSL#4
This seems to be equivalent to (RESULT << 4) | (RESULT>>8). It doesn't look correct to me, but maybe I'm missing something.

05 Oct 2010

I did a printf of read_u16 and of LPC_ADC->ADGR and it appears that the most significant nibble is mirrored in the least significant nibble??????

05 Oct 2010

LPC_ADC->ADGDR does left justify the 12 bit result with the Least significan't nibble always 0.

05 Oct 2010

Have you looked at the LPC17xx manual?

The ADGDR register returns the result in bits 15:4 the other bits being copies of status etc.

See the following link to see the full definition of LPC_ADC_TypeDef

http://mbed.org/projects/libraries/svn/mbed/trunk/LPC1768/LPC17xx.h#L510

If you are using p20 like the example given for AnalogIn then you should read (LPC_ADC->ADDR5 >> 4) & 0xfff and not LPC_ADC->ADGDR

Look at the LPC17xx manual