I'm busy ( have done V0.xx) making a library to use a Maxim 78M6613 energy monitor IC ( with current and voltage sensor)
to be used with an uno (atmega 328) and the mega ( 2560).
my protoype is working on an Uno
the interface is very easy to implement but this results in a lot of memory usage ( 7k ),
edit** I m unsure as to where the strings are stored and would like to minimise the SRAM and flash footprint of this
I access memory adresses from 0x20 up to 0xF2, so I only use a small amount of unique characters sent over serial as ASCII
is there a way that I can store these 26 characters ie. 16 hex,),=,?,+,-,Z,W,L,P,O,K
in an array in flash and refer to them in my Serial commands
commands are sent as ASCII strings like a serial print... but i used streaming library to get things nicely inline
commands are as follows :
Serial << ")20?" << crl; // get channel 1 temperature
where the command breaks down to
) : controller memory access
20 : hex address the value is stored in ( in this case , an on-board temperature reading in degrees C)
? : reply should be a decimal format
: end of message
a sample method is here :
I think it stores both these strings as separate entities ( the one i send, and the one i pass to my response handler),
double PowerMonitor::vrms(int channel) // returns rms Voltage +VVV.vvv (26) (66)
{
switch(channel)
{
case 1:
Serial << ")26?" << crl;// get channel 1
return processResponse(")26");
break;
case 2:
Serial << ")66?" << crl;// get channel 2
return processResponse(")66");
break;
}
}
currently using an Uno ( Atmega 328)
but this shield will be used along with GSM/GPRS or Ethernet/Wifi and Xbee
So I'd like to keep the RAM usage as low as possible
it adds around 7k when included in a sketch, obviously not all of this is SRAM,
I'm looking for ways so try and minimise SRAM usage in this library,
it bothers me that I don't know where the quoted strings are stored that I use in my library.
would it be wise to use something like controllerprojects.com determine the SRAM usage ?
Ive had the 328 "lock up" before when I was working with a SM5100B-D GSM/GPRS module due to all the AT command strings and the POST and PUT strings I used in the sketch.
Trying to avoid this library using unnecessary amounts of SRAM in sketches and to minimise its flash footprint as well, to account for people using it not knowing all the implications of memory usage,
LocalgHost:
it adds around 7k when included in a sketch, obviously not all of this is SRAM,
I'm looking for ways so try and minimise SRAM usage in this library,
it bothers me that I don't know where the quoted strings are stored that I use in my library.
the 7k reported by the IDE does not include the SRAM at all -- it is only determined as it runs (especially if you have recursive functions and such).
All of your quoted strings are stored in SRAM unless you've specifically told them to be stored in flash (with the PROGMEM keyword or by using the F macro)
LocalgHost:
would it be wise to use something like controllerprojects.com determine the SRAM usage ?
That would be helpful however...
freeRam returns (total memory) - (static data) - (stack space) - (heap). For the first optimization pass you should focus just on static data (like string constants). That's the part that you have the most control over. The simplest way to determine static data size is with a command-line program named avr-size. There have been several posts on this forum about how to use it. After searching, if you cannot find anything helpful, report back.