Mem usage on AVR?

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hello All,
I've design my app on a 8515 for ease of debugging and prototyping,
although in terms of code space and pin usage it should fit onto a 2313.
My question though concerns memory usage. In the program I declare an
int array 40 elements, an int array of 79 elements, and 11 other int
variables giving a count of 130bytes of memory used. (I assume I can
simply add it up like this, or am I missing something with regard to my
arrarys, +1byte per array maybe?) Since several of these variables are
being used to store boolean values, I can mesh several of them into one
char and save a couple of bytes of memory. Now my real question is, is
simply counting the bytes like this enough to ensure that my program
will fit into memory? I also have two interrupts and several loops, do
they use up memory (avr-gcc)? Could I do something like assign all the
int varibles to registers and just keep the arrays in memory?

Thanks
Mike

Re: Mem usage on AVR?
Hi Michael,

Your method will give you a rough idea of how much memory your program will
use - assuming whatever compiler you're using doesn't automatically optimize
variables straight into the AVR registers. But keep in mind that calling
routines and/or passing parameters can eat away at memory too, because of
stack usage. Be careful, though, with your data types - different compilers
might allocate a different number of bytes for a particular data type - an
'int' in one might not be the same size as an 'int' in another. Depends
which particular standard - if any - the compiler or language uses. You'll
need to check the compiler documentation, to be certain. One other thing,
the addition won't be accurate if the arrays are transient (i.e. due to
scope).

It might be possible for you to get an idea about what's happening with your
program and memory usage simply by running it in the AVR Studio Simulator
(free download from Atmel / AVRfreaks). Or, you could check out the avr-gcc
documentation and forum (if that's the compiler you're using) - again, on
(or links from) the AVRfreaks site.

Regards,
-Pete.
--
 http://home.comcast.net/~pete.gray /

We've slightly trimmed the long signature. Click to see the full one.
Re: Mem usage on AVR?
Hi, Michael,
Maybe you can look at map file produced by linker?
Aleks.

Quoted text here. Click to load it

Re: Mem usage on AVR?

Quoted text here. Click to load it

Aleks,
What do I want to look for in that file?

Thanks
Mike

Re: Mem usage on AVR?
It may show you the amount of used RAM.

Quoted text here. Click to load it
will
optimize
of
compilers
an
You'll
thing,
your
Simulator
avr-gcc
Quoted text here. Click to load it
on
2313.



Re: Mem usage on AVR?

Quoted text here. Click to load it

Greetings,

40 and 79 sounds like a mag card reader to me.
Track 1 and 2 in fact..

Char arrays not Int I think Pete is gettin at.
If it comes to the crunch, track 2 is 4 bits per number if you drop the
parity or check it on the fly and pack two numbers per byte/char into
an array of 20.

How namy Ext Int sources in a 2313?
Food for thought...

HtHs
Greg the Grog



Re: Mem usage on AVR?

Quoted text here. Click to load it

Exactly. Got the reader for cheap and just did my own serial converter
for fun.

Quoted text here. Click to load it

Ya, I was thinking about doing that.

Quoted text here. Click to load it

2, which, if I can get it to fit, makes it a nice chip for this app.

Thanks
Mike

Re: Mem usage on AVR?

Quoted text here. Click to load it

In addition to the other tips in this thread I also find the 'size'
command to be useful.  It will tell you the size of the code (text)
and of any global variables/data (data+bss).

Yes, you should be able to just add up the sizes as you have done (at
least for avr-gcc).

If you use local variables, function calls and interrupts those will
all use memory from the stack.  'size' will not show this so you will
need to calculate it yourself.  One way to get some help with this is
to use 'gcc -S' (or dissasemble) and look at the generated assembly
code to see how much the stack pointer is adjusted for each function.

-Erik
--
/ddef/md/ad/qd/y 1 d 300{/x 1 d 600{/c x 600 div 4 m 2
sub d/z y 300 div 2 m 1 sub d/r 0 d/i 0 d/t 0 d{t 1 le{/n r r m i i m sub c a
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline