Now a cerberus favor

I was wondering if anyone with a cereberus could run this code and tell me how long it takes…

I suspect it will run out of memory though… :’(


var myInt = new int[100000];
var ain = new AnalogIn(AnalogIn.Pin.Ain0);
var startTime = DateTime.Now.Ticks;
 
for (var i = 0; i < myInt.Length; i++)
	myInt[i] = ain.Read();
 
var elapsedTime = (DateTime.Now.Ticks - startTime)/(double)TimeSpan.TicksPerSecond;
Debug.Print(elapsedTime.ToString("F2") + " s");

well i tried it on a Panda and sure enough i get an out of memory exception…

but changing this:



var myInt = new int[100000];
to 

byte[] myInt = new byte[100000];

and this :
for (var i = 0; i < myInt.Length; i++)
	myInt[i] = ain.Read();

to

 for (var i = 0; i < myInt.Length; i++)
                myInt[i] =(byte) ain.Read();

gives a whole lot more to read and store.

Jay

the ADC is ten bits long, converting to a byte means you lose two bits. ???

Hi Mike,
in that case the use of int16 will get you more then int…

Or shift right two bits and get less granularity/resolution in the measurement.

but, but… :slight_smile:


Debug.Print(elapsedTime.ToString("F2") + " s");

I am curious what that will be.

In any event does anyone know the max array size for an int array. Speed is not really a concern if it is nearly as fast as a Hydra…

Gosh if this just had 512k I would order 30 of them.

I cannot read and save data fast enough to an SD card at 100 kHz…

If I could do an array with 100,000 elements I would be good to go!