ADC read with 12,8 kHz

I have 256x1 matrix. Every next cell value should be set with ADC read value with frequency 12,8 kHz. I think that the best way to do it is to create a timer which will run a “MATRIXwrite” function every 78,125 micro seconds.

        static void MATRIXwrite(object o)
            if (i == 256) i = 0;
            ADC_matrix[i] = ADC0.Read();

Unfortunately I don’t know how to do it in .NETMF because timer can be set with mili seconds. Could somebody give me a tip how can I do it?
If this information is relevant, I am trying to run this code on STM32F429I-DISCO

Welcome to the forum!

Do you have a link to documentation for the matrix?

@ mrl - What are the conditions to start and stop the MATRIXWrite method, because there is a test for I == zero, this kind of indicates it runs forever.

This sample code will start a Timer to call your MATRIXWrite method, with a period of 78 mS.

static byte i = 0;
// start  the timer
Timer MATRIXWriteTimer = new Timer(MATRIXWrite, false, 0, 78);
// stop the timer

You could optimize the test of i == 0 by using a byte, so the test is not required.
You may have adjust the period, to obtain a rate close to your requirements.

The Micro Framework is not a real-time system. Any deterministic timing requirements will be a problem.

If you read the ADC in managed code, then you will have difficulty reading at a constant rate, making use of the data in something like a FFT less than optimal. You might look into RLP

12.8 kHz is 78 microseconds, not 78 ms

@ Mike
So I guess that it will be better to fall back into C…

@ SouthernStars

Thanks for your contribution

On GHI boards you can use RLP, to use C routines from NETMF.
There you can also set up an exact timer.
I managed to get an ADC sample rate of up to 40kHz by this on a G120.
Here is a link to the forum Post I wrote about that.
To get into RLP, I recommend Simons tutorial:

Completely missed that.

@ mrl - good luck with your project.