big array occures freeze

Hey there,

when i initialize this array here

boolean sequenzen[16][4][10][32];

and fill it with 0s in the setup() function the arduino is frozen....

When I change the index 16 with 4 it works ...

What can i do to use a bigger array?
I dont think its the memory because its datatype is boolean which means that the whole array takes
16410*32= 20480 Bits or 2,56kByte

Does anyone know what the problem is?

I dont think its the memory because its datatype is boolean which means that the whole array takes
16410*32= 20480 Bits or 2,56kByte

I think know it is a memory problem - you don't have that much RAM.

Each boolean takes up a whole byte.
Time for a rethink.
Maybe bits?

and fill it with 0s in the setup() function

I assume it is a global, in which case, it is filled with zeroes before "setup".

why does a boolean take a byte?
if a boolean takes a byte which datatype takes just a bit per value?
can i use and save such a big array or isnt it possible with the mega1280?

why does a boolean take a byte

Because you need to be able to take the address of one, and the smallest addressable entity on an AVR is a byte.

void setup(void)
{
Serial.begin (115200);
}

void loop(void)
{
Serial.println (sizeof (boolean) * 16 *4 *10 *32);
delay (1000);
}

Output:

20480

Looks like AWOL is 100% correct.

why does a boolean take a byte?

From that page:

In modern computer architectures, a byte is the smallest addressable unit of memory.

If you want to squeeze more in (and this is nothing to do with the Atmega1280) you need to do a bit of work to access individual bits.

okay, so I have to write functions on my own where I kinda go through all adresses with a for loop beginning from the pointer of the array and get the values like this?


so i have to initialize an array with 2560 bytes so the memory is reserved.
then i intialize the pointer on this array.

mh...

yeah i try this now, it will also be a good exercise on pointers.

yeah i try this now, it will also be a good exercise on pointers

I don't know about pointers, but the "/" and "%" operators will be useful.
(though you could just use "&")

Hi Flub

Why do you need a multi dimentional array with 20480 boolean elements?

-Fletcher

Hi ,

I built a 10 channel Trigger sequenzer with 4 Bars with 32 Notes each bar and I want to save 16 Sequenzes.

Hi Flub,

I'm not sure what a

10 channel Trigger sequenzer with 4 Bars with 32 Notes each bar and I want to save 16 Sequenzes

is.

Music or demolition controle?

Do you intend to manipulate 10 channels each with 4 bars each with 32 notes (10432) = 1280 indepently outputs?

-Fletcher

perhaps this is a help... otherwise i can make a little video sooner or later


does anyone know if there is something like the calloc function in c++ for the arduino compiler ?

this is for the arduiono:

boolean ReadValue(int seq, int takt, int channel, int p) {
takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p;  
pointer = pointer+count;
return *pointer;
pointer=sequenzen;
Serial.println();
}

void WriteValue(int seq, int takt, int channel, int p, boolean value) {
takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p;  
pointer = pointer+count;
*pointer = value;
pointer=sequenzen;
}

It doesnt work, i dont know why...

i tried this in my c++ compiler :

#include <iostream>
using namespace std;

int main () {
bool sequenzen[1280];

bool *Zeiger = NULL;
Zeiger = sequenzen;
cout << "size:" << sizeof(sequenzen) << "--" << Zeiger << " " << &sequenzen<<"\n";

Zeiger=Zeiger+2;
cout << Zeiger;
return 0;
}

and the second output is the first bit adress + 2 in hexa decimal... so this is right.

return *pointer;
pointer=sequenzen;
Serial.println();

You don't really expect the pointer assignment and Serial.println() call to be performed, do you?
Where/how is pointer defined? Since pointer is not defined in the function, it hardly makes sense to return it.

While bytes and booleans are the same size, they are intended for completely different purposes. What you are returning from ReadValue() is NOT a boolean value.

sequenzen and pointer is globally defined like this:

boolean sequenzen[1280];
boolean *pointer;

Now i tried to work with BitWrite and BitRead, but therfore i need an value with the size of 1280 bytes...

i just need 1280 byte memory reserved and a possbiliy to access every of the 1280*8 bits...

how can i do this?

You could look at the bitRead and bitWrite functions.
http://arduino.cc/en/Reference/BitRead
http://arduino.cc/en/Reference/BitWrite

Then, sequenzen [ 0 ] contains bits 0..7, sequenzen [ 1 ] contains bits 8..15, and so on.

Thank you all guys! i got it...
I didnt knew that a byte is something like : B00000000...

byte sequenzen[2560];
...
void setup() {
for (int i = 0; i < 2560; i++) {
   sequenzen[i]=B00000000;
}
...
}
...
boolean ReadValue(int seq, int takt, int channel, int p) {
takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p;
count--;
int x = count % 8;
int x2 = (count-x)/8;
return bitRead(sequenzen[x2],x);
}

void WriteValue(int seq, int takt, int channel, int p, boolean value) {
takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p;  
count--;
int x = count % 8;
int x2 = (count-x)/8;
bitRead(sequenzen[x2],x); ;
bitWrite(sequenzen[x2],x,value); 
}

this works fine. Now its a pitty that this doesnt fit on the eprom, so i cannot save the sequenzes while the device is off...

Doing a bitRead in WriteValue is just a waste of time.
This:

takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p;
count--;
int x = count % 8;
int x2 = (count-x)/8;

is common code - why not factor it into a single function?

Now its a pitty that this doesnt fit on the eprom, so i cannot save the sequenzes while the device is off...

A microSD shield would give you access to up to 2GB of storage.

oh i forgot to clear the function out of mistakes... i need two for several purposes for example copy and pasting sequences.

boolean ReadValue(int seq, int takt, int channel, int p, int Switch) {
takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p;
int x = count % 8;
int x2 = (count-x)/8;
count=-1;
boolean BIT = bitRead(sequenzen[x2],x);
if (Switch) {
  bitWrite(sequenzen[x2],x,inv(BIT)); 
} else {
  return BIT;
}
}

void WriteValue(int seq, int takt, int channel, int p, boolean value) {
takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p;  
int x = count % 8;
int x2 = (count-x)/8;
count=-1;
bitWrite(sequenzen[x2],x,value); 
}

if I see this the right way.... i dont even need the micro sd thing because ive got 4kB eprom : http://arduino.cc/en/Main/ArduinoBoardMega2560

with the Mega1280 ...

I ll see how to save it on the eprom.

Hi Flub,

It may not be an issue with your code but this line:

int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p;

has a potential risk of roll-over (at 32,767).

-Fletcher