Yahoo Groups archive

AVR-Chat

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

Message

Re: [AVR-Chat] code speed optimization

2007-12-27 by David Kelly

On Dec 26, 2007, at 9:06 AM, ahmed nabil wrote:

> hi ALL,
> i have a basic knowledge that optimizing my code time or speed is a  
> very
> important matter when writing a professional code.

Not as important as you make it sound.

The most important instance I can think of has to do with sequentially  
toggling I/O bits to control an external device such as a text LCD  
which has a relatively slow Hitachi controller. One needs to be sure  
there is enough setup time before the next bits are written. This can  
be a problem with a 20 MHz AVR as the Hitachi is designed for a 1 MHz  
MC6800 bus.

Also important when one bit-bangs an SPI interface.

Other than that its handy to be able to profile interrupt routines. To  
know how long and how often they are running. As others have already  
stated, use a spare (or borrow temporarily) an I/O bit and toggle it  
going in and out. Many years ago companies made a big deal of software  
tools to profile code, and of hardware ICE with trace buffers to  
profile code usage. Not pushed as hard today because they usually were  
not worth the cost.

Have recommended many times here that one visually inspect generated  
code. Am often impressed at how avr-gcc recognized what it was being  
asked to do and reduced it to minimal code. But sometimes surprised at  
how much code was needed for other tasks. I *shouldn't* be surprised  
when applying a 32 bit mask to clear bits, then oring bits back into  
the original. Must be spoiled.

--
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Attachments

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.