Multi dimentional Array

I have two Arrays

  1. byte D[64] and
  2. byte TB[27][256]

I'm trying to run this code but not getting any output. I wonder why?

for(f=0; f<70; f++)
     {
       for(l=0; l<27; l++)
       {
         for(m=0; m<64; m++)
         {
          P = D[m];
          L= l;
          PORTB = TB[L][P];
          PORTD = 4;
          PORTD = 0;
         }
    }
}

:~

Is there a size limit for Two dimensional array?

I have two Arrays

  1. byte D[64] and
  2. byte TB[27][256]

27 * 256 = 6912 bytes of the 2K that you have available, unless you have a Mega, in which case you have 8K. Even if you do, you are probably still running out of memory.

I have Duemilanove with ATMEGA 328P
from Arduino IDE it reads;
"Binary sketch size: 6048 bytes (of a 30720 byte maximum)"

Am I still out of memory? So why there is no Warning or Error message?

Binary sketch size: 6048 bytes (of a 30720 byte maximum)"

That's telling you how much code (ROM) memory your sketch occupies, not how much RAM.

This:PORTB = TB[L][P]; suggests to me you may be using your array as ROM anyway, so maybe you could move it into PROGMEM

Am I still out of memory? So why there is no Warning or Error message?

Yes. The amount of SRAM needed at run time is a function of the number/type/size of the global variables you define, the number/length of literal strings, the number/type/size of local variables you define, the number/type/size of arguments you pass to functions, and the order and depth that those functions are called in.

Only some of that information can be obtained at compile time.

It would be nice if the compiler popped up a message when the amount of SRAM that it knows is used exceeds the amount available, but, alas, that is not the case.

It is up to you to be aware of the limits and write code appropriately.

I'm using PROGMEM ROM and not RAM.
the code is just reading the value. Still it doesn't work. Wonder why?

Still it doesn't work. Wonder why?

Wonder what the code looks like, now.

OK, a little progress.
The code works if the array is between;
TB[0][256] to TB[14][256]. But when I increase the value of array TB[15][256] or above it doesn't work.

Arduino IDE reads;
Binary sketch size: 4240 bytes (of a 30720 byte maximum) // for TB[14][256]
It uses only 14 * 256 = 3586 bytes.

I'm more confused now.

I'm more confused now.

And I still wonder what the code looks like.

Here's the code.
Plz don't ask me the purpose of it!

You can try with the Array TB[14][256] and TB[15][256] and let me know your finding!

 int APin  =  8;
 int BPin  =  9; 
 int CPin  =  3; 
 int l,m,f,P,L;
 
  
 byte TB[14][256] = {
   
                    {0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,         //1
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
                    
                    {0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,         //2
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
                    
                    ....please repeat ( I can't post full code: it exceeds the size allowed in forum!)
                    
                    {0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,         //13
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
                    
                    {0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,         //14
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}
                   
                   /* 
                   ,{0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,         //15
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}
                    */
                 };
   
 byte D[8] = { 9,  9,  9,  9, 0,  0,  0,  0 };

  
 void setup() 
 {   
   DDRB = DDRB | B00111111; // sets Arduino pins 8 to 13 as outputs, pins GND & AREF are unchanged
   DDRD = DDRD | B11111100; // sets Arduino pins 2 to 7 as outputs, pins 0 & 1 are unchanged
 } 
 
  void loop()
  {
     PORTB = 0;
       for(l=0; l<14; l++)
       {
         for(m=0; m<8; m++)
         {
          P     = D[m];
          L= l;
          PORTB = TB[L][P];
          PORTB = 0;
         }
       }  
   
  }

I'm using PROGMEM ROM and not RAM.

Or you could use PROGMEM.

let me know your finding!

I'm not finding any PROGMEM there.

You mean byte TB[14][256] PROGMEM = {... ???
But that's not right syntax

But that's not right syntax

Correct.
However, a simple search for "PROGMEM" over at the "Main Site" (up there on the left) would reveal all sorts of useful hints.

Why did you say you were using PROGMEM before?

I thought you mean PROGMEM = Program Memory and not RAM. I wasn't aware of Keyword PROGMEM!
Also I had misconception that Sketch and all the declared Constants are saved in Flash.

Also I had misconception that Sketch and all the declared Constants are saved in Flash

They are - where else is there to store them?
However, all tables like yours are copied to RAM before "main" runs (before "setup" in Arduino-speak).

Problem!!
The data I'm getting from Array is not correct!
:expressionless:

The data I'm getting from Array is not correct!

Time to give the data a lecture about moral rectitude.

Or post your code.

Ha ha ..lol

Here is the code;

 #include <avr/pgmspace.h>
 int APin  =  8;
 int BPin  =  9; 
 int CPin  =  3; 
 int l,m,f,P,L;
  
 //byte TB[14][256]  = {
PROGMEM  prog_uint16_t TB[15][256]  = {
                    {0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,         //1
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
                    
upto 15 times.....

                   ,{0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,         //15
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
                    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}
                   
                 };             
   
 byte D[8] = { 9,  9,  9,  9, 0,  0,  0,  0 };

 void setup() 
 {   
   DDRB = DDRB | B00111111; // sets Arduino pins 8 to 13 as outputs, pins GND & AREF are unchanged
   DDRD = DDRD | B11111100; // sets Arduino pins 2 to 1 as outputs, pins 0 &  are unchanged
 } 
 
  void loop()
  {
     PORTB = 0;
       for(l=0; l<15; l++)
       {
         for(m=0; m<8; m++)
         {
          P     = D[m];
          L     = l;
          PORTB = TB[l][P];
          PORTB = 0;
         }
       }  
  }

When l=0 I get the right data; pin 8 and 9 are HIGH for 4 times out of 8. But when l>0 pin 8 and 9 are HIGH for 8 times out of 8 Why?

Ok,
I've just used
PORTB = pgm_read_word(&TB[L][P]); instead of
PORTB = TB[l][P];

and it seems working!!!
:blush: