10 years, 10 months ago.

Fast Analog In . 11u24 .

Hello guys , I have been trying to write a program that gets input from an analogIn , that is saved in an array to be processed later . The problem is that the signal I am sending to the analogIn is a 20kHz sine wave and I want the data I get from it to be very precise and of very high resolution . I need at least 100 samples for each lump in the wave . I have tried and I can only get about 8-10 samples per time . How can I increase the adc or analog in input ?

title:signalProcessing.cpp

 float data[100];
    float inpt;
    while(i<100) {
        float inpt=Vin.read();
        data[i]=inpt;
        i++;
        //pc.printf("%f \n",inpt);
    }
    i=0;
    while(i<100) {
        pc.printf("%f \n",data[i]);
        i++;

       
   }

2 Answers

10 years ago.

Please allow me to dig out this thread and ask a noobie question.

I basically want to do the same thing as Antreas Antoniou 10 months ago did. I need more samples per time unit and I therefore seek for a method to get there.

I looked at FastAnalogIn, but as mentioned here, it seems to be not compatible with the 11u24 (is that right?). I also looked at the Datasheets and User Manual links provided here. They seem to hold everything I need. The Problem now is the execution.

I tried to put on Burst mode be myself be accessing the Control Register of the ADC (LPC_ADC->CR). The bit was set. But the Analog-Digital-Conversion-Rate didn't seem to get faster. The problem probably has something to do with my standard way of declaring an analog Input ( AnalogIn SoundSensor1(p15) ). i'm not allowed to use this effortless way of creating an analog input, when I try to get the Burst mode working, right?

Furthermore, till now, I just looped trough an array of 200 elements to get a bunch of values from the analog input. But, reading this post, that doesn't seem to be the way it has to be done. I need to call an interrupt. But how do I do that?

FastAnalogIn should work with the LPC11u24. I should look into updating it though :).

Other question is, why do you need more samples? There are valid reasons, but 100 samples per sine wave like requested in the original question here does not provide significant morei nformation than 3 samples (see Nyquist Theorem).

posted by Erik - 04 Nov 2014

Erik Olieman! Hello!

Thanks for your comment. In that case, I will take a second try at your library. Seems like I made one noobie mistake too much, when I tried to implement it some hours ago.

The wave I want to analyse is a sound wave (produced when a ping pong ball hits the table). Because it is not a regular sine wave the Nyquist Theorem won't help me.

posted by Tobias Kuhn 04 Nov 2014
10 years, 10 months ago.

What do you mean with a 'lump'? A period of the sine wave?

The sample rate of the ADC on the LPC11u24 is 400KS/s, so at best you can get 20 samples per period for your sine wave of 20kHz.

If you need really precise and fast sampling you will need an external ADC, although you should then watch out you can still process the data fast enough on your mbed. Also are you sure you need 100 samples per 'lump'? (I assume period). Are there higher harmonics that are relevant? Because the minimum sampling rate you need is a bit more than two times the highest frequency component in your to-be sampled signal. So if it is a perfect sine wave then 50kHz sample rate should be sufficient.

Yes when I say lump , I do mean period . I said lump as the most important bit of the signal that I will be analyzing are the mid to top segments of the wave . I will be analyzing the sine wave and comparing it to the original one from the source to find any inconsistencies and compensate for them . So as you understand the more samples the better in this case . So how do I get it to go to 20 ?

posted by Antreas Antoniou 07 Jan 2014

You will have to directly address the registers. Here is the user manual: http://www.nxp.com/documents/user_manual/UM10462.pdf. Chapter 19 is the ADC. I see there you can actually do it faster, but at the cost of resolution. You will want to have it in burst mode (= automatic continious conversions), and then call an interrupt everytime a conversion is finished -> store that in an array.

As probably useful starting point, I once made an ADC thingie for the LPC1768, which also runs in burst mode, and it does more than what you need, but it does show how to roughly do it (the ADC peripherals are different, so you really cannot copy the code: https://mbed.org/users/Sissors/code/FastAnalogIn/). Finally, here is the mbed code for the AnalogIn of the LPC11u24, which might also be useful: http://mbed.org/users/mbed_official/code/mbed-src/file/c1fbde68b492/targets/hal/TARGET_NXP/TARGET_LPC11UXX/analogin_api.c

posted by Erik - 07 Jan 2014