#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2019
    Posts
    1
    Rep Power
    0

    Insufficient memory on microcontroller project


    I'm working on a project and I got an error saying that "microcontroller final.out" was not built and that "The program will not fit into available memory"
    I tested it in a different compiler without the parts controlling the microcontroller. I'm confused as to what the problem is with it. I'm using a TI MSP430

    #include <msp430g2553.h>
    #include <stdio.h>

    unsigned int i;
    int morseCode[26][4]={{0,1,2,2},{1,0,0,0},{1,0,1,0},{1,0,0,2},{0,2,2,2},{0,0,1,0},{1,1,0,2},{0,0,0,0},{0,0,2,2},{0,1,1,1 },{1,0,1,2},{0,1,0,0},{1,1,2,2},{1,0,2,2},{1,1,1,2},{0,1,1,0},{1,1,0,1},{0,1,0,2},{0,0,0,2},{1,2,2,2 },{0,0,1,2},{0,0,0,1},{0,1,1,2},{1,0,0,1},{1,0,1,1},{1,1,0,0}};
    char string[1000]="SOS";
    void dot(void);
    void dash(void);
    void endWord(void);
    void endLetter(void);
    void endString(void);
    void runMorse(int i);

    int main(void){
    WDTCTL = WDTPW + WDTHOLD;
    P1DIR |= 0x41;
    P1OUT &= 0xBE;
    unsigned int i=0;
    while(1){
    if((string[i]>='a' && string[i]<='z') || (string[i]>='A' && string[i]<='Z')){
    runMorse(i);
    i++;
    }
    if(string[i]==' '){
    endLetter();
    i++;
    }
    if(string[i]=='\0'){
    endString();
    i=0;
    }
    else{
    i++;
    }
    }
    return 0;
    }
    void runMorse(int i){
    int row, j;
    if(string[i]>='A' && string[i]<='Z'){
    string[i] += 32;
    }
    switch(string[i]){
    case 'a': row=0;
    case 'b': row=1;
    case 'c': row=2;
    case 'd': row=3;
    case 'e': row=4;
    case 'f': row=5;
    case 'g': row=6;
    case 'h': row=7;
    case 'i': row=8;
    case 'j': row=9;
    case 'k': row=10;
    case 'l': row=11;
    case 'm': row=12;
    case 'n': row=13;
    case 'o': row=14;
    case 'p': row=15;
    case 'q': row=16;
    case 'r': row=17;
    case 's': row=18;
    case 't': row=19;
    case 'u': row=20;
    case 'v': row=21;
    case 'w': row=22;
    case 'x': row=23;
    case 'y': row=24;
    case 'z': row=25;
    }
    for(j=0; j<4; j++){
    if(morseCode[row][j]==0){
    dot();
    }
    if(morseCode[row][j]==1){
    dash();
    }
    }
    return;
    }

    void dot(void){
    int i;
    P1OUT ^= 0x40;
    for(i=0; i<20000; i++)
    ;
    P1OUT ^= 0x40;
    for(i=0; i<20000; i++)
    ;
    return;
    }

    void dash(void){
    int i;
    P1OUT ^= 0x40;
    for(i=0; i<60000; i++)
    ;
    P1OUT ^= 0x40;
    for(i=0; i<20000; i++)
    ;
    return;
    }

    void endLetter(void){
    int i;
    for(i=0; i<40000; i++)
    ;
    return;
    }
    void endWord(void){
    int i;
    for(i=0; i<120000; i++)
    ;
    return;
    }

    void endString(void){
    int i;
    P1OUT ^= 0x01;
    for(i=0; i<60000; i++)
    ;
    P1OUT ^= 0x01;
    for(i=0; i<140000; i++)
    ;
    return;
    }
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,986
    Rep Power
    510
    Before we shrink the code we should make it correct. Assuming this is a c program--sure looks like it, you need to understand about the fall-through nature of cases in the switch statement.

    Run the program on a big computer to correct it with actual tests. Print the dashes and dots and spaces to check them.

    I don't know how much space is available to you, nor do I know how compact is the code your compiler produces. morseCode could be byte rather than int, or a bit struct. Since 2 bits can store 0 1 2, and there are at most four signals in a letter, one 8 bit byte could store the code for a character.
    Two bits in place of at least sixteen bits reduces that array size to one eighth what you've got.

    There may be a little extra code for shifting and masking. Let's reduce the code size next. The big switch statement can instead be (assuming of course that you'd first fixed it with break statements)
    Code:
    row = string[i] - 'a';
    There are some empty loops, for timing I suppose. (Morse is a base four code. There are two "on" lengths as well as two "off" durations.) Make sure your compiler doesn't optimize these away.

    Learn about the "else" part of an "if" statement.

    The code in the while loop in the main function looks completely screwed up (incorrect), but I haven't tried to build this mess.

    string and the input come from the msp430g2553 header file?

    Good luck. You might need to rewrite in assembler. Or search the internet for other ideas such as https://www.muppetlabs.com/~breadbox...ny/teensy.html

    I've written morse code programs, at least one of them lurks on the internet with a 2010-Dec-09 timestamp.
    Last edited by b49P23TIvg; April 24th, 2019 at 07:42 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,286
    Rep Power
    4194
    Assuming the msp430g2553 file indicates the part number, then you only have 16kB of memory to store your program according to the specs. You'll need to make sure you can compile your code down to a binary file smaller than that. Check your compiler for optimization options aimed toward smaller size. If that isn't enough then you'll have to start looking at the code to see if you can save space.
    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,490
    Rep Power
    1876
    Remember to use code tags when posting code.
    Code:
    #include <msp430g2553.h>
    #include <stdio.h>
    
    unsigned int i;
    int morseCode[26][4] = {
        {0, 1, 2, 2},
        {1, 0, 0, 0},
        {1, 0, 1, 0},
        {1, 0, 0, 2},
        {0, 2, 2, 2},
        {0, 0, 1, 0},
        {1, 1, 0, 2},
        {0, 0, 0, 0},
        {0, 0, 2, 2},
        {0, 1, 1, 1},
        {1, 0, 1, 2},
        {0, 1, 0, 0},
        {1, 1, 2, 2},
        {1, 0, 2, 2},
        {1, 1, 1, 2},
        {0, 1, 1, 0},
        {1, 1, 0, 1},
        {0, 1, 0, 2},
        {0, 0, 0, 2},
        {1, 2, 2, 2},
        {0, 0, 1, 2},
        {0, 0, 0, 1},
        {0, 1, 1, 2},
        {1, 0, 0, 1},
        {1, 0, 1, 1},
        {1, 1, 0, 0}
    };
    
    char string[1000] = "SOS";
    
    void dot(void);
    void dash(void);
    void endWord(void);
    void endLetter(void);
    void endString(void);
    void runMorse(int i);
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;
      P1DIR |= 0x41;
      P1OUT &= 0xBE;
      unsigned int i = 0;
      while (1) {
        if ((string[i] >= 'a' && string[i] <= 'z') || (string[i] >= 'A' && string[i] <= 'Z')) {
          runMorse(i);
          i++;
        }
        if (string[i] == ' ') {
          endLetter();
          i++;
        }
        if (string[i] == '\0') {
          endString();
          i = 0;
        } else {
          i++;
        }
      }
      return 0;
    }
    
    void runMorse(int i)
    {
      int row, j;
      if (string[i] >= 'A' && string[i] <= 'Z') {
        string[i] += 32;
      }
      switch (string[i]) {
      case 'a':
        row = 0;
      case 'b':
        row = 1;
      case 'c':
        row = 2;
      case 'd':
        row = 3;
      case 'e':
        row = 4;
      case 'f':
        row = 5;
      case 'g':
        row = 6;
      case 'h':
        row = 7;
      case 'i':
        row = 8;
      case 'j':
        row = 9;
      case 'k':
        row = 10;
      case 'l':
        row = 11;
      case 'm':
        row = 12;
      case 'n':
        row = 13;
      case 'o':
        row = 14;
      case 'p':
        row = 15;
      case 'q':
        row = 16;
      case 'r':
        row = 17;
      case 's':
        row = 18;
      case 't':
        row = 19;
      case 'u':
        row = 20;
      case 'v':
        row = 21;
      case 'w':
        row = 22;
      case 'x':
        row = 23;
      case 'y':
        row = 24;
      case 'z':
        row = 25;
      }
      for (j = 0; j < 4; j++) {
        if (morseCode[row][j] == 0) {
          dot();
        }
        if (morseCode[row][j] == 1) {
          dash();
        }
      }
      return;
    }
    
    void dot(void)
    {
      int i;
      P1OUT ^= 0x40;
      for (i = 0; i < 20000; i++);
      P1OUT ^= 0x40;
      for (i = 0; i < 20000; i++);
      return;
    }
    
    void dash(void)
    {
      int i;
      P1OUT ^= 0x40;
      for (i = 0; i < 60000; i++);
      P1OUT ^= 0x40;
      for (i = 0; i < 20000; i++);
      return;
    }
    
    void endLetter(void)
    {
      int i;
      for (i = 0; i < 40000; i++);
      return;
    }
    
    void endWord(void)
    {
      int i;
      for (i = 0; i < 120000; i++);
      return;
    }
    
    void endString(void)
    {
      int i;
      P1OUT ^= 0x01;
      for (i = 0; i < 60000; i++);
      P1OUT ^= 0x01;
      for (i = 0; i < 140000; i++);
      return;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. No Profile Picture

    Join Date
    May 2019
    Location
    Pakistan
    Posts
    1
    Rep Power
    0
    https://www.resellerplanet.co.uk

    Checkout our All in one Reseller Package!

    Our Pro Reseller Plan comes with WHMCS, cPanel/WHM and a FREE .com or .co.uk domain!

    The Package Specifications

    Bronze Reseller
    25GB SSD Storage
    25 cPanel Accounts
    Unlimited Email Accounts
    Unlimited Bandwidth
    Unlimited Databases
    WHMCS Optional Extra
    FREE .COM or .CO.UK
    9.99 per month

    Order now:
    https://www.resellerplanet.co.uk/cart.php?a=add&pid=5

    Silver Plan
    50GB SSD Storage
    50 cPanel Accounts
    Unlimited Email Accounts
    Unlimited Bandwidth
    Unlimited Databases
    WHMCS Optional Extra
    FREE .COM or .CO.UK
    https://www.resellerplanet.co.uk/cart.php?a=add&pid=6

    Our Ultimate Plan - Including free WHMCS + either .com or .co.uk!

    Our best plan yet!

    100GB SSD Storage
    Unlimited cPanel Accounts
    Unlimited Email Accounts
    Unlimited Bandwidth
    Unlimited Databases
    FREE WHMCS STARTER
    FREE .COM or .CO.UK
    https://www.resellerplanet.co.uk/cart.php?a=add&pid=7

    Thank you,

    ResellerPlanet

IMN logo majestic logo threadwatch logo seochat tools logo