Question to adc example of LPC824

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Question to adc example of LPC824

828 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ledi007 on Fri Feb 12 04:26:38 MST 2016
Hi guys,

i want to understand how the adc works in that example.
I use the LPC824 board and i use a potentiometer to the pin A0 (ADC1).
If i debug the example, i got a 32bit rawSample value from an 12 bit data register.
Normaly no problem, but what about these funny value 2214658736?
Labels (1)
0 Kudos
Reply
3 Replies

618 Views
lpcware
NXP Employee
NXP Employee
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)
0 Kudos
Reply

618 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ledi007 on Sat Feb 13 07:37:53 MST 2016
Many thanks for your hints! Now, i understand how it works :bigsmile:

But you write:

Quote:
So then it reads 0x02B0 and full scale is 0xFFFF - so the voltage on the pot is 688/65536 or just over 1% of the supply voltage.



This is a 12bit ADC. Therefore the full scale is 0xFFF - so the voltage on the pot is 688/4095 of the supply voltage.
0 Kudos
Reply

618 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by IanB on Fri Feb 12 08:58:48 MST 2016
A lot easier to look at in hexadecimal, where it reads 0x840102B0

The result is in bits 4 to 15, but I find it a lot easier to think of it as a half-word (with the lowest four bits always as zero).

So then it reads 0x02B0 and full scale is 0xFFFF - so the voltage on the pot is 688/65536 or just over 1% of the supply voltage.

The rest of the number, the upper 16 bits, have functions which are shown on page 338 of the manual.
In your case bits 16, 26 and 31 are set, indicating that the result was below the range in the threshold comparison (bit 16), that the result came from ADC1 (bit 26) and that the conversion had finished (bit 31)
0 Kudos
Reply