Shop OBEX P1 Docs P2 Docs Learn Events
Program size, bs2 — Parallax Forums

Program size, bs2

FurciferFurcifer Posts: 3
edited 2008-10-14 12:15 in Learn with BlocklyProp
Chapter 10 of What's a microcontroller, project 2 tasks us with adding a 5th menu option to a sensor array.· I intend to go a bit further and include a lengthy RTTL file for a song.· My question is- what happens if I exceed the EEPROM or RAM capacity of the bs2?· Will it crash, or can damage to the bs2 result?· Thank you

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-10-11 15:13
    No crash, no damage.

    The Compiler (IDE Run button) will let you know that you've exceeded capacity (Error) and that'll be that.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-12 04:23
    Press Ctrl+M to see a graphic of how much memory you have used so far.
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2008-10-13 18:39
    One situation in which you can cause yourself problems is with writing to EEPROM during run-time, which is different than downloading the program and EEPROM data together at compile-time where the Editor can detect a size problem.

    In the BASIC Stamp, EEPROM stores both the program and also values sent to EEPROM with the WRITE command. If you don't plan ahead, it is possible to keeping writing so much data to your EEPROM that you start to overwrite your program which will cause a crash. You can use the Memory Map to see how much EEPROM space you have for writing during run-time, or you can use a DATA directive for all BS2 models to set aside that space ahead of time and the Editor will catch any potential conflict.

    You can read more about WRITE and DATA in the BASIC Stamp Editor Help.

    -Stephanie Lindsay
    Editor, Parallax Inc.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-13 22:19
    Is is possible to self modify the program during runtime? A simple examle would be to change the value of a constant (not normally possible during run time) by writting over that spot in memory.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-14 00:01
    Actually, constants are compiler directives. When you use them in your program, the value of the constant is plugged into the memory location.

    So while in theory you could change a value in eeprom, finding which value to change would be difficult.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-14 01:25
    But possible, I take it? So along that line, you could have some sort of SERIN/WRITE loop that self modifies the code based on what another stamp (or other serial device) sends? You'd just have to figure out how the compiler organizes things into the memory block.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-14 01:30
    It's possible, but not easy. It's very easy to store initialized data in an otherwise unused part of the EEPROM and change it as needed. Keep in mind that any given location in EEPROM can only be written maybe 100,000 times. This seems large, but can easily occur in a few hours if there's an error in a program that runs continuously.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-14 03:08
    So what happens when the write count reaches it's max? Does it become unreadable, or is the last piece of data permanent? Or something else entirely?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-14 04:28
    Well, it's not like there's a counter hidden in the EEPROM, but charge gets trapped in the insulating layer (silicon dioxide) used to store a bit and can't be completely removed (during the internal erase operation). At some point (like around 100,000 cycles), one or more bits at a location become "stuck" at zero since the erased state is all ones and not enough of the stored charge can be swept out of the insulating layer to be read as a one in those bits.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-14 12:15
    Yes, in theory, it could be done.

    In practice, "self modifying code" is frowned upon. It gets VERY difficult (virtually impossible) to debug, for one thing. And there are alternatives -- that's what subroutines are for, and decision code.

    Also, to create a 100 byte program that was "self-modifying" could require a thousand bytes of decision code to decide how to modify the critical 100 byte part.

    And yes, what Mike said is correct -- you wind up with certain locations that can't be fully erased.· The symptom you then see is a "compare failure" when you try to program the BS2.
Sign In or Register to comment.