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();
i++;
}
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
@ 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.
Main()
{
...
static byte i = 0;
...
// start the timer
Timer MATRIXWriteTimer = new Timer(MATRIXWrite, false, 0, 78);
...
// stop the timer
MATRIXWriteTimer.Dispose();
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 https://www.ghielectronics.com/docs/50/rlp