6 years, 9 months ago.

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);
AnalogIn ain1(p15);
AnalogIn ain2(p16);
AnalogIn ain3(p17);
AnalogIn ain4(p18);
AnalogIn ain5(p19);
AnalogIn ain6(p20);
LocalFileSystem fs("fs");
int main () {
FILE *fp = fopen("/fs/data.csv","w");
for (int i=0; i < 30; i++) {
 led2 = !led2;

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

2 Answers

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).

Accepted Answer

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,
or in the case of MBED, discard the 'noisy' ADC reading(s),

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)
read ADC 2 - 5 times,
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,


Thanks a lot

posted by Pradeep Kumar Mukherjee 17 May 2013