Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

Few AVR programming tips from ATMEL

Today all C compilers generate very optimal code for microcontrollers. In most cases is not worth trying to optimizing it by writing assembly lines. But there are one factor left that lead to less efficient code – the guy who writes code. If you have programmed for PC writing code same way not always is the best way to do. Microcontroller oriented compilers like AVR GCC is adapted to generate optimal code for AVR devices. If you will go to other micros, then you will see that programming ARM microcontrollers with C in some cases require special code structure to get most of hardware. To be a pro on those things you actually need to know how hardware works in one or in other situation, but simple general tricks may save a day by reducing code size ans so speeding up the execution. Improper coding may generate excess code. So Atmel has prepared an application note where they take through several key coding tips. One part is more dedicated to reducing code size by doing simple decisions on selecting variable… Continue reading

Simple tricks that make AVR code more optimized

AVR like other small microcontrollers have very limited resources including speed, SRAM and Flash. Before you get to the middle of your program writing you may notice that you running out of one of those. You may be struggling with exceeding SRAM, or loosing execution speed where you need it most or simply run out of program space. There are times when there is nothing you can do except to look for bigger and faster MCU, but in some cases smart coding tricks may help. Atmel team have prepared pretty good application note where they take through various aspects of code optimization. Following those advises they managed to reduce code size by 100%, SRAM by 56.5% and execution speed by 33%. Their example was about reading ADC and sending data via USART. Generally speaking they pointed variable sizes – don’t forget that AVR is 8-bit MCU, so using bigger variables always lead to bigger code size and slower processing. Also few tricks allows reduce loop size and speed. Sometimes simple loop enrolling may give a nice kick. Each optimization trick… Continue reading