Jump to content


  • Content Count

  • Joined

  • Last visited

Reputation Activity

  1. Like
    waynewec reacted to Rei Vilo in Basic Serial Program Printing Inconsistent Data   
    To know the RAM used,
    find the location of the size utility /Applications/Energia.app/Contents/Resources/Java/hardware/tools/msp430/bin/msp430-size compile a sketch and find the location of the elf file /var/folders/kd/70m4ltxn14l086ddy860ff3c0000gn/T/build7439050874009286986.tmp/Blink.cpp.elf open a terminal window and type the command $/Applications/Energia.app/Contents/Resources/Java/hardware/tools/msp430/bin/msp430-size /var/folders/kd/70m4ltxn14l086ddy860ff3c0000gn/T/build7439050874009286986.tmp/Blink.cpp.elf text data bss dec hex filename 590 0 6 596 254 /var/folders/kd/70m4ltxn14l086ddy860ff3c0000gn/T/build7439050874009286986.tmp/Blink.cpp.elf do the maths: text + data = FLASH bss + data = SRAM
  2. Like
    waynewec reacted to roadrunner84 in Basic Serial Program Printing Inconsistent Data   
    Ah! You're an assembly guy! Then you might go for a more C-like approach than the C++ like approach you're currently taking. I'm not sure that it will actually make your code smaller, but I figure that since you don't need dynamic memory your RAM usage will decrease.
    That's tough, it's virtually impossible to measure individual clock cycles, unless you dedictate a timer to count them. Then still you're bound to be off in some way, since the read action alone takes 3 cycles. I think the easiest way is to ensure that you use both the rising edge of the output and the active edge on the input should be parsed by the same routing in which you avoid any conditional logic (like if statements). This way both the start and the stop of your interval will have the same latency and thus your interval will be equal in the physical realm as in your software.
    Implementing a single shot can be done in several ways. First, you could output a string of bits over SPI ending in a zero bit, then since you don't reload the SPI register with another value it will stay idle and thus zero.
    A second option would be to set a pin to timer output and set the timer OUT bit to high, then set up that CCR register to use the Reset mode. The pin will stay high until the CCR matches the timer value, then the pin will go low and stay low until you set it high again.
    So you're making a sonar? Nice. Since you're using the single shot to drive your 555, the width of the shot isn't that important I figure. You could also do other things after setting the single shot high and after you're done set it low again. You're basically interleaving code this way, something I often have to do in time critical stuff.
    I click the < > symbol above the edit window, then a popup occures that lets me paste code. Either let it use auto-detect as language, or Javascript, since that's quite similar to C in coding style.
    Oh, yes, the C version of compiling a string for sending over serial
    void loop() { if (run) { for (int i = 0; i < 180; ++i) //Print 10 meter ping times for each scan angle { unsigned long A, B, C; char outString[40]; sprintf(outString, "%u$%lu#%lu#%lu#", i, A, B, C); Serial.println(outString); } } } sprintf uises the printf formatting to write a to a character array (the C version of a string; much dumber). The %u means to insert a unsgined integer here, %lu (that's a lower case L) means to insert a unsigned long integer here. After the formatting string the variables to replace the formatting codes are named in the same order.
    Take into account that the size of a char[] must always be at least one character longer than the longest text you will store in it! A char[] will never resize and will contain a single '\0' to denote the end of the string, you barely ever actively use this trait, but you must constantly be aware that you are required to allocate that extra character in the declaration of your string to store it.
    In this case the length of your string should be the largest size of a long (10 characters) times 3, plus the size of your iterator (3 characters when <180, 5 characters worst case) plus the size of the $, the three # and the '\0' summing up to 3*10+3+5 is 38, let's round up to 40.
  3. Like
    waynewec reacted to roadrunner84 in Basic Serial Program Printing Inconsistent Data   
    I'd suggest setting the size to at least 25, as that's the amount of data you try to store in it! That it is working while you don't have that much space available means your String object we create a copy of twice the size (40 characters) and then deallocate the old one. This is very inefficient, try to (if you stick to String usage) reserve at least the maximum string size + 1 when calling upon reserve().
    Also, leave the = ""; part out in the declaration of the string objects.
    Instead of appending the angle to your string (which then should be empty) and emptying the string at the end of the iteration, just assign the angle to the string.
    void loop() { if (run) { for (int i = 0; i < 180; ++i) //Print 10 meter ping times for each scan angle { unsigned long A, B, C; outString = to_string(i) + "$" + to_string(A) + "#" + to_string( + "#" + to_string(C) + "#"; Serial.println(outString); } } } Something like this.
    Or if you wish to stop the measurement in between every angle
    void loop() { static int i = 0; if (run) { ++i; if (i == 180) i = 0; unsigned long A, B, C; outString = to_string(i) + "$" + to_string(A) + "#" + to_string( + "#" + to_string(C) + "#"; Serial.println(outString); } }
  4. Like
    waynewec reacted to roadrunner84 in Basic Serial Program Printing Inconsistent Data   
    That would only be true for compile time and stack memory. The String class on the other hand uses free space (a.k.a. heap) memory, which isn't allocated until run time. Your RAM usage thus does not show up in these kind of compile reports.
    Additionally, you call Serial.println(outString); which requires the String class to either return a raw pointer to the internal character data (unsafe) or return a copy of the string as a character sequence. This is due to the limitations of println, which (probably) only accepts char*, not String. As a result there are currently four buffers, your incoming and outgoing String buffers and the Serial's incoming and outgoing serial buffers! Plus maybe a temporary copy of the data in the println() call!
    I found that println() will buffer the data internally as well. If you want to make sure you don't run out of memory in the Serial object, after calling Serial.println() call Serial.flush().
  5. Like
    waynewec reacted to veryalive in Basic Serial Program Printing Inconsistent Data   
    Hi - as a newbie myself, I tried your code.
    As RR84 suggested buffer sizes, I experimented, as total 400 bytes (in+out each 200) seemed a lot for the 512 byte RAM on the 2553. And I don't know what Energia needs for its own buffers in addition to that 400.  I noticed that the original code crashed after 10 lines in, and at about 21 characters per line, that gets over the 200 byte limit of the output buffer - and where is THAT in memory?
    So, I changed the INPUT buffer length to 20, down from 200. And it works.
    I don't think the code is busting the buffer due to concatenation, though. It could be just too little RAM in the chip for the compilation and Enegia doesn't let us know about it.  Just my own guess.
    >> So, here is your code, it delivers all 180 samples to the serial port. And it stops cycling after each 180 if your type STOP.
    I put in some debug lines to check out things.   I found out that \n checking is actuially checking foir LINEFEED (ctrl-J), not CR as I guessed.  I like the serial event command but have no idea where you found out about it !
    **  Simple program designed to simulate pushing 180 degrees of 10 meter scan times
    **  for testing of VB.NET GUI
    String inputString = "";
    boolean run = false;
    String outString = "";
    int i = 0;
    void setup() {
      inputString.reserve(20);  //DEBUG       <<<<<<<<<<<<<<<<<<<<<<<<<<<<<  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    void loop() {
      if (run) {
        for (i = 0; i < 179; i++) //Print 10 meter ping times for each scan angle
          outString += i;
          outString += String("$932944#932944#932944#"); //Test data to simulate 10 meter distance
          outString = "";
          delay (50);                                                            // debug, slow it down ********************************
    void serialEvent() {
      while (Serial.available()) {
        char inChar = (char)Serial.read();
        Serial.print(inChar);    // echo DEBUG   **************************************************
        if (inChar == '\n' && inputString == "START")
          run = true;
          Serial.println("run flag true");     //   ***************************************
          inputString = "";
        else if (inChar == '\n' && inputString == "STOP")
          run = false;
          Serial.println("run flag flase");     //   *************************************
          inputString = "";
        else if (inChar == '\n')
          Serial.println("Please use valid command: START | STOP");
          inputString = "";
        inputString += inChar;
        Serial.print("\t");            //DEBUG ************************
        Serial.println(inputString);   // echo up till now DEBUG  ************************
  6. Like
    waynewec reacted to roadrunner84 in Basic Serial Program Printing Inconsistent Data   
    You're running out of memory. Since you concatenate the test string and the iterator number to the string each iteration through the for loop, your string is bound to overflow your RAM capacity at some point.
  • Create New...