Hello..!!
I am trying to make a project in which I preform an action after taking a input from audio sensor.
the size of my code is 20kb. but when i run the code it is Freezing
so i thought, may b my SRAM is overflowing, so for verification i removed some Serial.println() then code run at some extent, so i come to a conclusion that, SRAM is overflowing, after that i follow the below thread. http://forum.arduino.cc/index.php/topic,91208.0.html
And i got total RAM usage is 1491 bytes (72.8%).
So, is there any reason,because of that i am not able to use 100% of SRAM in my code ???
You can use 100% of SRAM and then it fails. The report can only cover SRAM used at that point in the code that you use it.
As you use functions and interrupts ping off this also uses SRAM for variables and return addresses. This can not be caught exactly in software because it is always changing.
thank you for replying,
I am using Interrupts (0 and 1) and functions. and checking the SRAM usage after Freezing.
so i am think that, at freezing time SRAM usege is 100% (or requesting more SRAM ) after that it is decreases, so that i am getting only 72.8%.
am i right???
BijendraSingh:
then how can I minimize the SRAM usage?
It depends on what you're doing. One thing is to use progmem for data you're using that doesn't change. One example of this is using the F macro with string constants in serial print statements:
Serial.print(F("Some text");
You may have a table of constants that can be moved explicitly out of SRAM using the progmem directive.
Another area to look at is whether you're using appropriately sized variables, especially if you're using arrays: it's a common thing to use int where byte would do. If you're used to programming on a modern PC, concerns about SRAM consumption may be less at the forefront of your thoughts when choosing types.
You may be using inappropriate techniques that consume a lot of stack - recursion is to be avoided on an arduino for example.
Dynamic memory allocation is best avoided, whether explicit use of malloc or use of String objects.
One more thing to consider is the SRAM consumption of any libraries you are using. In some cases, it may be possible to make a tweaked version of a library to reduce its usage.
BijendraSingh:
at freezing time ... after that it is decreases, so that i am getting only 72.8%.
You need to explain in more detail what you mean by 'freezing', because running out of RAM is pretty certain to crash the processor and nothing useful is going to happen 'after that' until you reset it.
change: "File > Preferences > preferences.txt" to say "build.verbose=true".
looked at the IDE message window to find where the build files are stored
during compile. The path is VERRRRY long with many subdirectories,
c:\DOCUM~1\userme\LOCALS~1\Temp\build37068458739447598749.tmp. There I
found the .elf build file.
then I moved both avr-size.exe [found deep in the Arduino IDE directory
and the [renamed] .elf file up to c:, where I ran the command shown from
"Start > Run > cmd", and "cd ".
finally, I got the info shown.
After freezing i go through above steps, and on CMD i got 72.8%
After freezing i go through above steps, and on CMD i got 72.8%
But that will give you exactly the same results before freezing.
It is only telling you what SRAM is used by variables in your sketch, it knows nothing about the dynamic allocation of the return stack and other house keeping things.
After compilation and RUN, i am getting some outputs on Serial Monitor.
But after next few seconds, Serial monitor stop showing any outputs(not showing even garbages) and also not showing any error message.
Hello !!
I debug(commenting each line and checking) the code and found that, code is freezing at
irsend.sendNEC(code_data, length);
code_data is unsigned long int, and its value is 284139615
length = 32;
Library : ArduinoIRremotemaster. also check with IRremote library.
I am not getting why it is freezing at irsend.sendNEC(code_data, length), and how to resolve this.???
please help.
If you have done your best to reduce the amount of space your variables and constant strings take up then the solution is probably to get a processor with more RAM.
You are never going to be able to manage RAM usage down to the last byte.
There must be a slight chance that there is a code error that is causing the crash. That could be checked out by writing a short sketch that uses the piece of code you want to check, but which has very little else so that there is plenty of RAM available.