Content originally posted in LPCWare by IanB on Sat Feb 13 10:14:28 MST 2016
Yes it is a 12-bit ADC, but the 12-bit result is located in bits 4 to 15, so it "looks like" a 16-bit result but with the four least significant bits as zeroes.
So, you need to LSR the result by four bits if you want to read a 12-bit result. So, the result is then 0x2B or 43. The voltage on the pot is therefore 43/4096 or just over 1% of the supply voltage.
I prefer to think of the result as a 16-bit number. There are three reasons do this:
1) a 16-bit number is a half-word, and it's often easier to deal with 16-bit numbers than 12-bit numbers.
2) On other devices with 10-bit ADCs the results are located in bits 6 to 15 instead of 4 to 15, so both 10-bit and 12-bit ADCs can be read as a 16-bit number with identical results, so you can use the same code on an LPC11xx or LPC13xx (with 10-bit ADC) as on LPC8xx or LPC15xx with 12-bit ADC.
3) You don't have to do the LSR #4 instruction - sometimes you really do need to save the time it takes to execute one instruction!
If you want the voltage on the pin in millivolts as an integer, just multiply by 3300 and then shift right 16 places. (assuming a 3.3V supply)