While Creating a 6 Pin DataLogger Using LPC11U24 , I get Incorrect Values by ADC?

While Creating a 6 Pin Data Logger Using LPC11U24 , I obtained a Value of 0.61 in my Data File when i had applied a Constant Voltage of 2V(peak to peak) at The Input Pins. I cannot Understand the relation between Input and Output in this case.

The code used by me is :

Data Logger Code

```#include "mbed.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
LocalFileSystem fs("fs");
int main () {
led2=0;
led1=1;
FILE *fp = fopen("/fs/data.csv","w");
for (int i=0; i < 30; i++) {
fprintf(fp,"\n");
led2 = !led2;
}
fclose(fp);
led1=0;
}
```

I Suppose the output must be digital value but value of 0.61 against 2V is Confusing me.

6 years, 9 months ago.

Analog input values must be between 0V and 3V3. Do not exceed those limits or you will damage mbed. In particular prevent negative voltages on the input.

The AnalogIn class will translate the input voltage in a float between 0.0 and 1.0. So 2V should result in about 0.6 ( = 2V/3.3V).

Thanks a lot for your help...

posted by Pradeep Kumar Mukherjee 16 May 2013
6 years, 9 months ago.

the best way is:

```  ..
..
fprintf(fp,"%f\n",ain1.read() * 3.3);  // Convert to volts ..
..
..
```

But from a more technical note:
you should allow the Analogue multiplexer to settle, before sampling,

This mainly happens when you switch between channels,

after all there is only ONE physical ADC, and a multiplexer.

I would (unless you need silly speed)
and use only the last sample,
or, better still:
read in 2 - 3, samples, dis guard,
then take the MEDIAN of the next 3 to 9 samples,

Although, this does depend on the speed you need to sample, and how much noise is in your source.

Hope his helps,

Ceri

Thanks a lot

posted by Pradeep Kumar Mukherjee 17 May 2013