10 years, 11 months ago.

To create a 6 input datalogger using LPC11U24 What should be the Connections ?

To create a 6 input datalogger using LPC11U24 What should be the Connections ? I used Pins 15 to 20 for Taking Inputs. The code used was-

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 () {
led2=0;
led1=1;
FILE *fp = fopen("/fs/data.csv","w");
for (int i=0; i < 30; i++) {
 fprintf(fp,"%\n","1 ",ain1.read());
 fprintf(fp,"%\n","2 ",ain2.read()); 
 fprintf(fp,"%\n","3 ",ain3.read()); 
 fprintf(fp,"%\n","4 ",ain4.read()); 
 fprintf(fp,"%\n","5 ",ain5.read()); 
 fprintf(fp,"%\n","6 ",ain6.read());  

 led2 = !led2;
 }
fclose(fp);
 led1=0;
}

However I get no values in the file created by code. What must be the Problem??

2 Answers

10 years, 11 months ago.

Your fprintf is not formatted correctly. Currently it has no value to print because nothing follows the % formatter. Assuming you want to print a float, the first parameter should be ain rather than a string "1".

Try

fprintf("ain1 = %f\n", ain1.read());

Accepted Answer
10 years, 11 months ago.

Thanks a lot for your help...I have a followup question...The values obtained in the saved file were ambiguous ....When i applied a voltage of 2V(Peak to Peak) at the Input Pins then I Obtained a value nearly 0.61 in the output file...What is the relation between Input and Output?

Secondly Even when same sinusoidal signal was applied at all six terminals, the values stored in the file are different for each set of Observation...How can we decrease the Time interval of observations at different pins in each set of Observation?

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

Depending on your samplerate you could get different values in the file. The sinewave frequency may be much higher than the sampletime + the time it takes to write the value to the file. Solution may be to first sample all 6 inputs and save the values in a variable, then write these 6 variables to the file and then do this for the next set of 6 values. Note that analog conversion always takes time and is done sequentially for all 6 inputs so there will be differences for high frequency input waveforms.

posted by Wim Huiskamp 16 May 2013

How can we alter the Sampling rate? Can you please give me a snippet of code or instructions on how to alter the Sampling Frequency? I am Indebted to you for wasting your precious time for a newbie. :)

posted by Pradeep Kumar Mukherjee 16 May 2013

The lpc1768 manual says its max conversion rate is 200 kHz. Dont know about the lpc11u24. Note that it seems that the mbed lib is significantly slower than 200 KHz. You can find more on the wiki: https://mbed.org/handbook/AnalogIn or search the site for ''analog sample rate"

You can sample at slower rates by using a Timer that calls a conversion routine at regular intervals.

posted by Wim Huiskamp 16 May 2013