Need help in Code optimization.....!!!

Discussion in 'Embedded Systems and Microcontrollers' started by hellototrushal, Nov 19, 2011.

  1. hellototrushal

    Thread Starter New Member

    Nov 7, 2011
    I m using ATmega16 for a Home Automation Project...My code size is 32Kb.My headache is how to port it in a 16Kb Flash...
    I am newbie in AVR programming,i don't know how to optimized code properly...

    I want to know how to use heap memory and dynamic memory allocation in AVR programming and also how to optimize code .....

    Please help me....!!!!

    Thank u very much for ur interest in my topic.
  2. hgmjr


    Jan 28, 2005
    The beauty of micrcontrollers is that you can implement a multiprocessor solution to a complex problem.

    Have you considered using mulitple AVRs to achieve your goal? If your project can be divided up into several major functional blocks. Then you can use a dedicated AVR to perform each of the major tasks. The AVRs can then been connected together over a serial communication link. You would then have a master AVR that would control the distributed microcontrollers each playing their part in the overall task.

  3. kubeek

    AAC Fanatic!

    Sep 20, 2005
    Usually you can trade between RAM and code size, but if you have 32K of code, I guess you use most of the ram available. Why don't you use some bigger chip like ATmega32, 64 or 128?

    If you can post the code, we can try see what your major problems are. Generally you should try bending all the at least a bit similar parts of code to use one piece of code with different parameters - meaning using a bit more of ram for much less code. Or loose some of the less necessary functions.
    But without seeing the code all this is just stabbing in the dark.
  4. MrChips


    Oct 2, 2009
    32KB is a lot of memory space for a micro. They first thing you need to look at is what libraries are you using and what is really essential. In many cases, floating-point arithmetic is not required. Get rid of all your floating-point libraries and you will find your code shrink to a fraction of the current size.

    And there's lots more that you can do to further shrink your code.