Mem usage on AVR?

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

Reply to
Michael Dombrowski
Loading thread data ...

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/

"Michael Dombrowski"  wrote in message
 Click to see the full signature
Reply to
Pete Gray

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

Reply to
Grog

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

Ya, I was thinking about doing that.

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

Thanks Mike

Reply to
Michael Dombrowski

Hi, Michael, Maybe you can look at map file produced by linker? Aleks.

Reply to
Alexander Baranov

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

Thanks Mike

Reply to
Michael Dombrowski

will

optimize

of

compilers

an

You'll

thing,

your

Simulator

avr-gcc

on

2313.
Reply to
Aleksandr Baranov

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

--
/d{def}def/m{mul}d/a{add}d/q{repeat}d/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
 Click to see the full signature
Reply to
erij

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.