Speed of Analog reading

I am looking to get analog input samples and do FFT on the input. The signal is audio (music).
For my application, the sampling will short bursts (128 samples) and about 3-4 times a second is good enough, so I will have enough room for the processor to do other things.

I tried both Panda and Panda II, and the results are about 95ms for reading 1000 times. In other words the sample rate is about 10KHz. A good target for me will be 30KHz.

What options do I have to optimize this piece?

The code I used is:

 private static AnalogIn music = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An0);
        private static int[] samples = new int[128];

        public static void TestAnalogSpeed()
            TimeSpan ts = new TimeSpan();
            DateTime t = DateTime.Now;

            for (int j = 0; j < 8; j++)
                for (int i = 0; i < 128; i++)
                    samples[i] = music.Read();
            ts = DateTime.Now.Subtract(t);
            Debug.Print("Total time for 1000 analog reads " + ts.Milliseconds.ToString() + "ms");

This code samples 1024 of course and I adjusted the result accordingly (97mS for 1024 samples is about 95mS for 1000 samples)

Check out RLP.


In the native code, how do I read Analog 0 for example?
I just think it must be through the CLR somehow and not to use micro registers directly.
The prototypes in RLP.h seems like matching digital I/Os.

This is detailed under tutorials.

Thanks Gus, a link could help :wink:


Scroll to the end of the page and lookout for ‘RLP’

Thanks a lot!
Looked at the audio recorder sample, as seems most relevant to me. The code there to do actual read is directly accessing registers. The code there is:

That produces values of 0-255 (mmm… where did the 10bit gone?)
Is it right to fix this by:
#define ADC_DATA_BASE_ADDRESS 0xE0034010

int GHAL_AnalogIn_Read(unsigned char channel)
    return ((*((int*)(ADC_DATA_BASE_ADDRESS) + channel)) >>[b]5[/b]) & 0x3FF;

This is only an example and I think it uses 8bit. feel free ot modify to your needs.

This is the result of working code: http://www.tinyclr.com/codeshare/entry/421/

Excellent work man. Love seeing FFT on Panda :slight_smile:

I am not seeing the FFT RLP code. Is it in the zip file you uploaded?

Yes, it is in the ZIP file

Something to improve on codeshare.It looks like it just opens the first folder inside the zip file and skips the rest.

@ Zakie Mashiah

Good job! Cool demo!

it is a zip in a zip?! :slight_smile: Ia m not sure if this is something we want to support. We will check

No, it is one zip with two top level folders inside. Anyways I’ve just double checked and it shows correctly now.

This was fixed and I modified the database to fix your entry also.

Thanks Josh! Or should I give Gus credit :wink:

Give GHI Electronics credit.