Jump to content
43oh

Errors compiling in Energia


Recommended Posts

hello i get these errors and not sure how to correct them

 
sinewave.cpp:21:15: error: expected ']' before ',' token
sinewave.cpp:21:16: error: expected unqualified-id before numeric constant
sinewave.cpp:22:1: error: expected unqualified-id before 'for'
sinewave.cpp:22:11: error: 'i' does not name a type
sinewave.cpp:22:18: error: 'i' does not name a type
sinewave.cpp: In function 'void loop()':
sinewave.cpp:44:3: error: 'inp' was not declared in this scope
sinewave.cpp:51:30: error: 'bits' was not declared in this scope
sinewave.cpp:67:30: error: 'bits' was not declared in this scope
 
HERE IS MY CODE
 
 
 
 
void setup()
{   
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, INPUT);          //PIN P1.3 for switch
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
}
 
 
 
 
int button=0;
int i=0;
int sina=0;
int  bits [100,8]=0;
for( i=0; i<100 ;i++)
{
  sina(i)=4+4*sin(100*i/(2*pi));    //This code will be an integer value
  // between 0 and 8
  if(sina(i)>4)
    bits(i,7)=1;      //MSB of the output
  else if((sina(i)/2) > 4)
    bits(i,6)=1;
  else if((sina(i)/4) > 2)
    bits(i,5)=1;
  else if((sina(i)/8) > 1)
    bits(i,4)=1;
  else if((sina(i)/16) > 1/2)
    bits(i,3)=1;
  else if((sina(i)/32) > 1/4)
    bits(i,2)=1;
  else if((sina(i)/64) > 1/8) //LSB
    bits(i,0)=1;
}
 
void loop()
{
  inp=digitalRead(5);
  delay(5);
 
  while(button==0)
  {
    for(i=0;i<100;i++)
    {
      digitalWrite(2,bits(i,7));
      digitalWrite(3,bits(i,6));
      digitalWrite(4,bits(i,5));
      digitalWrite(6,bits(i,4));
      digitalWrite(7,bits(i,3));
      digitalWrite(8,bits(i,2));
      digitalWrite(9,bits(i,1));
      digitalWrite(10,bits(i,0));
    }
    delayMicroseconds(36);      //Gives frequency of 275Hz
  }
  if(button==1)
  {
    //OUTPUT 350Hz 
    for(i=0;i<100;i++)
    {
      digitalWrite(2,bits(i,7));
      digitalWrite(3,bits(i,6));
      digitalWrite(4,bits(i,5));
      digitalWrite(6,bits(i,4));
      digitalWrite(7,bits(i,3));
      digitalWrite(8,bits(i,2));
      digitalWrite(9,bits(i,1));
      digitalWrite(10,bits(i,0));
    }
    delayMicroseconds(28);      //gives Frequency of 350Hz
  }
}
 
 
 
 
  
 

 

Link to post
Share on other sites

Hi @@musclemania05

 

There are a lot of problems with your code unfortunately.  For example...

  • using sina as an array but not declaring it as such
  • using () for arrays instead of []
  • multidimensional arrays incorrect - i.e. bits [100,8] instead of bits[100][8]
  • have code outside of loop() and setup() that isn't in a function

I recommend getting familiar with C/C++ syntax before going any further.  When you code, build it in small chunks and test/compile as you go.

Link to post
Share on other sites
int pi  = 3;

int button=0;

int i=0;

int sina[]={};

int  bits[100][8]={};

void setup()

{   

  pinMode(2, OUTPUT);

  pinMode(3, OUTPUT);

  pinMode(4, OUTPUT);

  pinMode(5, INPUT);          //PIN P1.3 for switch

  pinMode(6, OUTPUT);

  pinMode(7, OUTPUT);

  pinMode(8, OUTPUT);

  pinMode(9, OUTPUT);

  pinMode(10, OUTPUT);

}

void loop()

{

  button=digitalRead(5);

  delay(5);

 

  for( i=0; i<100; i++)

{

  sina=4+4*sin(100*i/(2*pi));    //This code will be an integer value

  // between 0 and 8

  if(sina>4)

    bits[7]=1;      //MSB of the output

  else if(sina/2 > 4)

    bits[6]=1;

  else if((sina/4) > 2)

    bits[5]=1;

  else if((sina/8) > 1)

    bits[4]=1;

  else if((sina/16) > 1/2)

    bits[3]=1;

  else if((sina/32) > 1/4)

    bits[2]=1;

  else if((sina/64) > 1/8) //LSB

    bits[0]=1;

}

 

  while(button==0)

  {

    for( i=0;i<100;i++)

    {

       digitalWrite(2,bits[7]);

      digitalWrite(3,bits[6]);

      digitalWrite(4,bits[5]);

      digitalWrite(6,bits[4]);

      digitalWrite(7,bits[3]);

      digitalWrite(8,bits[2]);

      digitalWrite(9,bits[1]);

      digitalWrite(10,bits[0]);

    }

    delayMicroseconds(36);      //Gives frequency of 275Hz

  }

  if(button==1)

  {

    //OUTPUT 350Hz 

    for(i=0;i<100;i++)

    {

      digitalWrite(2,bits[7]);

      digitalWrite(3,bits[6]);

      digitalWrite(4,bits[5]);

      digitalWrite(6,bits[4]);

      digitalWrite(7,bits[3]);

      digitalWrite(8,bits[2]);

      digitalWrite(9,bits[1]);

      digitalWrite(10,bits[0]);

    }

    delayMicroseconds(28);      //gives Frequency of 350Hz

  }

}

Link to post
Share on other sites

i correct the code but now it says this following error:

 

 

c:/users/alex narvais/downloads/energia-0101e0017-windows/energia-0101e0017/hardware/tools/msp430/bin/../lib/gcc/msp430/4.6.3/../../../../msp430/bin/ld.exe: sinewave.cpp.elf section `.bss' will not fit in region `ram'
c:/users/alex narvais/downloads/energia-0101e0017-windows/energia-0101e0017/hardware/tools/msp430/bin/../lib/gcc/msp430/4.6.3/../../../../msp430/bin/ld.exe: region `ram' overflowed by 1114 bytes
collect2: ld returned 1 exit status
Link to post
Share on other sites

The errors are pretty much what they say they are - 

  sinewave.cpp.elf section `.bss' will not fit in region `ram' - something is too big to fit in RAM.

  region `ram' overflowed by 1114 bytes - and that is how much it is too big.

 

This is your bits array:

int  bits[100][8]={};

How much space does that take up?  One 'int' is maybe 32-bits (yes?), so that's 4 bytes for one entry. Multiply by 800, to get 3200 bytes total. Find out what processor you are using and look-up how much RAM it actually has.  Maybe only 2K?

 

EDIT: I forgot to tell you how to fix this! SImply change the type from 'int' to 'char' or 'byte'. Instead of storing a single bit in a 32-bit value, we'll store it in a 8-bit value. This is still quite wasteful, but that should reduce the memory usage by a factor of 4. 

 

Also, there might be a problem in the three tests like this one:

 else if((sina[i]/16) > 1/2)

That "1/2" is converted to "0" by the compiler. It is not a floating-point computation.

 

Also, aren't all of your "sina[]" tests basically the same thing? I haven't thought deeply about this, but it seems to me that if "X/2 > 4", then "X/4 > 2" will also hold, and the same with "X/8 >1", and so on down the line.

 

Finally, you say that 'sina' is a number from 0 to 8.  OK, then dividing by anything bigger than 8 will give you zero. This is integer arithmetic, not floating-point.

 

PS: the code that creates "sina" and builds "bits" can be moved out of "loop" and into "setup". You don't even need the "sin" array, actually.

 

Good luck!

Edited by mgh
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...