Main Site Documentation

Speed of Analog reading


#1

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)


#2

Check out RLP.

http://wiki.tinyclr.com/index.php?title=RLP_Getting_Started


#3

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.


#4

This is detailed under tutorials.


#5

Thanks Gus, a link could help :wink:


#6

http://www.tinyclr.com/support/

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


#7

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;
}

#8

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


#9

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


#10

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


#11

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


#12

Yes, it is in the ZIP file


#13

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!


#14

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


#15

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


#16

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


#17

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


#18

Give GHI Electronics credit.