AVR Specifics
Types Efficiency
First of all, you should know that AVR ALU, which performs arithmetic operations, is optimized for working with bytes. Although mikroC PRO for AVR is capable of handling very complex data types, AVR may choke on them, especially if you are working on some of the older models. This can dramatically increase the time needed for performing even simple operations. Universal advice is to use the smallest possible type in every situation. It applies to all programming in general, and doubly so with microcontrollers. Types efficiency is determined by the part of RAM memory that is used to store a variable/constant.
Nested Calls Limitations
There are no Nested Calls Limitations, except by RAM size. A Nested call represents a function call to another function within the function body. With each function call, the stack increases for the size of the returned address. Number of nested calls is equel to the capacity of RAM which is left out after allocation of all variables.
Important notes :
- There are many different types of derivates, so it is necessary to be familiar with characteristics and special features of the microcontroller in you are using.
- Some of the AVR MCUs have hardware multiplier. Due to this, be sure to pay attention when porting code from one MCU to another, because compiled code can vary by its size.
- Not all microcontrollers share the same instruction set. It is advisable to carefully read the instruction set of the desired MCU, before you start writing your code. Compiler automatically takes care of appropiate instruction set, and if unapropriate asm instruction is used in in-line assembly, compiler will report an error.
- Program counter size is MCU dependent. Thus, there are two sets of libraries :
- - MCUs with program counter size larger than 16 bits (Flash memory size larger than 128kb)
- - MCUs with program counter size less or equal 16 bits (Flash memory size smaller than 128kb)
- Assembly SPM instruction and its derivates must reside in Boot Loader section of program memory.
- Part of Flash memory can be dedicated to Boot Loader code. For details, refer to AVR memory organization.
What do you think about this topic ? Send us feedback!