8 years, 6 months ago.

ADC uint16_t in LPC1768

Hey guys!.

I've made the code that measure ADC value and voltage using addValue.

And I'd like to know that whether [ I can use uint16_t code at LPC1768 ] and [ how to get 12bit value ]. (I know if I AnalogIn function, that data come out as the 0 ~ 1 values and it is much easier way than what I'm doing now)

The problem is.. if I used the uint16_t function and .read_u16() function, I've got the right value(maximum adcValue is 65535 and minimum is 0). However, when I changed the code from {.read_u16()} to {.read_u16()&0xFFF}, I got the wrong answer.

I was so confused because LPC1768 has the 12-bit ADC. How is this possible?. If you know about [ .read_u16() function ], please let me know.

my code is like this.

1. 16-bit adcValue(I've got right one)

  1. include "mbed.h"

AnalogIn adc(p20);

Serial pc(USBTX,USBRX);tx,rx

int main() {

uint16_t adcValue;

float voltage;

while(1) {

adcValue = adc.read_u16(); //

voltage = adcValue * 3.3 /65535; 2^16 = 65536

pc.printf("ADC Value : %i, %.3f volt \r\n", adcValue,voltage);

wait(0.1);

} }

2. 12-bit adcValue(I've got wrong answer)

  1. include "mbed.h"

AnalogIn adc(p20);

Serial pc(USBTX,USBRX);tx,rx

int main() {

uint16_t adcValue;

float voltage;

while(1) {

adcValue = adc.read_u16()&0xFFF;

voltage = adcValue * 3.3 /4095; 2^12 = 4096

pc.printf("ADC Value : %i, %.3f volt \r\n", adcValue,voltage);

wait(0.1);

} }

Thanks!

Be the first to answer this question.