Memory Question

Started by stonysmith, December 05, 2014, 03:32:18 PM

Previous topic - Next topic

stonysmith

*
Newbie
Posts: 1
Logged
I'm trying to find out more about how memory is allocated on the Tinyduino.

I need an array of longs to store some data in. I'd like to be able to store up to 1000 points of accelerometer x,y,z data.

I setup this as a test:
       long Points[300];
       for (i=0;i<300;i+=3) {
         accel.read();
         Points[i+0]=accel.X;
         Points[i+1]=accel.Y;
         Points[i+2]=accel.Z;
         }
and it works just fine, allowing me to store one hundred x,y,z values.

But if I increase the number to even 500, the sketch stops working.

I assume (know) that the 2k of ram memory is too small to hold all 1000 points that I'd like to have, but it seems odd to me that the sketch fails at even 500.

A long should be 16 bits, right? 500 longs should be 1000 bytes, using only half of the RAM available.

I'd like to be a bit more logical about this.. I should be able to calculate how much RAM a set of longs is going to require, rather than trial-and-erroring just waiting for the sketch to fail.

=======
The second half of my question is.. I could move all of this data out to an SD card, but what's the write cycle speed on an SD?  Isn't writing to an SD going to significantly slow me down compared to using RAM?   Any chance of a RAM shield some day?  I'm not greedy, even 32k should be exceedingly helpful here. <hint> <grin>

dude

*
Newbie
Posts: 3
Logged
Quote from: stonysmith on December 05, 2014, 03:32:18 PM
A long should be 16 bits, right? 500 longs should be 1000 bytes, using only half of the RAM available.

It depends on the compiler, but I think longs are 32 bits on this architecture. 

TinyCircuits

Administrator
*****
Hero Member
Posts: 108
Logged
longs are indeed 32-bit on the AVR architecture, if you only need 16-bit, just change them to int, which would be fine for the accelerometer. 

The microSD card writes are indeed fairly slow, and the SD card library will consume about 1/2K of RAM as well for buffering.  We are working on a SRAM TinyShield which will hopefully be out in early to mid January.

Thanks!

Ken
TinyCircuits

mike_ekim1024

***
Full Member
Posts: 17
Logged
Quote from: TinyCircuits on December 14, 2014, 03:52:06 PM
We are working on a SRAM TinyShield which will hopefully be out in early to mid January.

This would be awesome!  2K is so tight when you use WiFi, I2C and other libraries combined!  With C++, it would be possible to create wrappers/proxies to interface seamlessly with it.

SMF spam blocked by CleanTalk