Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

How to monitor Atmega128 SRAM usage at runtime?

How to monitor Atmega128 SRAM usage at runtime?

2004-08-20 by Yang Wang

Hello there,

Does anyone have some experience in monitoring the SRAM usage at 
runtime? Since the Atmega128 has only 4k SRAM, I am always worrying 
that at run time, storage of the program variables will eat up the 
SRAM, but I don't know how to check at run time, how much of the 4k 
SRAM has been used and how much is left there.

Please let me know if you have any suggestions. thanks a million!

--Yang

Re: How to monitor Atmega128 SRAM usage at runtime?

2004-08-20 by Yang Wang

I am using C. I am not using any dynamic memory allocation for the 
time being, so all the internal SRAM consumption should be for the 
stack. By the way, what kind of buffers are you refering to?

Thanks a lot!

--- In AVR-Chat@yahoogroups.com, Dave VanHorn <dvanhorn@d...> wrote:
> At 05:16 PM 8/20/2004, Yang Wang wrote:
> 
> 
> >Hello there,
> >
> >Does anyone have some experience in monitoring the SRAM usage at 
> >runtime? Since the Atmega128 has only 4k SRAM, I am always 
worrying 
> >that at run time, storage of the program variables will eat up the 
> >SRAM, but I don't know how to check at run time, how much of the 
4k 
> >SRAM has been used and how much is left there.
> 
> Are you working in assembler or C?
> 
> The most difficult thing, is to predict the depth of the stack, 
especially in C.
> The other memory usage should be controlled by how you allocate the 
memory when you write the code. 
> Buffers are given a finite size, and of course you need to work out 
what to do when they become full.

Re: [AVR-Chat] How to monitor Atmega128 SRAM usage at runtime?

2004-08-20 by Dave VanHorn

At 05:16 PM 8/20/2004, Yang Wang wrote:


>Hello there,
>
>Does anyone have some experience in monitoring the SRAM usage at 
>runtime? Since the Atmega128 has only 4k SRAM, I am always worrying 
>that at run time, storage of the program variables will eat up the 
>SRAM, but I don't know how to check at run time, how much of the 4k 
>SRAM has been used and how much is left there.

Are you working in assembler or C?

The most difficult thing, is to predict the depth of the stack, especially in C.
The other memory usage should be controlled by how you allocate the memory when you write the code. 
Buffers are given a finite size, and of course you need to work out what to do when they become full.

Re: [AVR-Chat] Re: How to monitor Atmega128 SRAM usage at runtime?

2004-08-20 by Dave VanHorn

At 06:06 PM 8/20/2004, Yang Wang wrote:

>I am using C. I am not using any dynamic memory allocation for the 
>time being, so all the internal SRAM consumption should be for the 
>stack.

The only way I know of, to check in that condition, is to clear the memory to zeroes at the start (in simulation) run the program for a while, and re-check the memory. 

> By the way, what kind of buffers are you refering to?

Any buffers that you create for serial I/O or whatever.

Re: [AVR-Chat] Re: How to monitor Atmega128 SRAM usage at runtime?

2004-08-21 by Bernd Felsche

On Saturday 21 August 2004 07:11, Dave VanHorn wrote:
> At 06:06 PM 8/20/2004, Yang Wang wrote:
> >I am using C. I am not using any dynamic memory allocation for the
> >time being, so all the internal SRAM consumption should be for the
> >stack.

> The only way I know of, to check in that condition, is to clear the
> memory to zeroes at the start (in simulation) run the program for a
> while, and re-check the memory.

"dead beef" is a better initial value to use, IMHO

If C functions are being used, then a macro declaration of "RETURN"
to trace the current stack pointer (perhaps simply by saving it to a
known location in memory if it's less than the previously-saved
value), prior to an actual return may be of use. I've not tried
that; but it may be useful.

-- 
/"\ Bernd Felsche - Innovative Reckoning, Perth, Western Australia
\ /  ASCII ribbon campaign | I'm a .signature virus!
 X   against HTML mail     | Copy me into your ~/.signature
/ \  and postings          | to help me spread!

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.