I was interested to see what the ADC max sample rate was with the N+2. So, I did a test. The code is below, and the project is attached.
Quick summary: The ADC max sample rate is roughly between 10,000 and 11,000 samples/second.
The max size array that I could allocate was 40,000 shorts. I'm not sure why. But, that gives ~3 seconds of samples.
To do the test, I ran the code, waited for "OuterLoop Counter: 5" to be displayed, then counted until "OuterLoop Counter: 15" was displayed. Good enough to get a ballpark figure for the max sample rate.
Some notes, unlike with .NET.
1) No difference was found between the release and debug versions.
2) No difference was found with the optimize option checked or unchecked.
3) The Microsoft suggested method (as shown below) to eliminate range checking did not improve performance.
for (int i = 0; i < ADC_samples_int.Length; i++) {
ADC_samples_int[i] = (short)adcPort_A0.Read();
}
My ADC max sample rate test code:
using System.Net;using System.Net.Sockets;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;namespace AnalogTestMaxSampleRate { public class Program { public static void Main() { // Define and initialize variables int inner_loop_counter_int = 0; int outer_loop_counter_int = 0; short[] ADC_samples_int; ADC_samples_int = new short[40000]; SecretLabs.NETMF.Hardware.AnalogInput adcPort_A0 = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0); inner_loop_counter_int = 0; outer_loop_counter_int = 1; // do forever... while (true) { inner_loop_counter_int = 0; while (inner_loop_counter_int < ADC_samples_int.Length) { // read from ADC Port_A0 ADC_samples_int[inner_loop_counter_int++] = (short)adcPort_A0.Read(); } Debug.Print("OuterLoop Counter: " + outer_loop_counter_int++.ToString()); } } }}// NOTES:// 1) No difference was found between the release and debug versions.//// 2) No difference was found with the optimize option checked or unchecked.//// 3) The Microsoft suggested method (as shown below) to eliminate range checking did not improve performance. // for (int i = 0; i < ADC_samples_int.Length; i++) {// ADC_samples_int[i] = (short)adcPort_A0.Read();// }//