[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] AVR assembly for fast bit bang

From: David Kelly
Subject: Re: [avr-gcc-list] AVR assembly for fast bit bang
Date: Wed, 9 Nov 2005 20:38:08 -0600

On Wed, Nov 09, 2005 at 09:00:58AM -0500, Dave Hansen wrote:
From: David Kelly <address@hidden>
People keep saying "C isn't fast enough." I don't belive it. First


It might be tough to do better on AVR.  My standard SPI routine uses a
do-while loop, which might save an instruction or two, but made about a 30%
difference on the PIC compiler I used.  Something like

  void output_spi_byte(uint8_t byte)
     uint8_t bit_ctr = 8;

        output_low(SPI_DATA);   // Set data bit low...
        if (byte & 0x80)
           output_high(SPI_DATA);   // ...or high, as required

        byte <<= 1;         // Shift acts as clock dwell delay

     } while (--bit_ctr);

I don't have avr-gcc handy to see if it's any better than your code. I was more concerned with size than speed, as you may be able to tell. If speed
is the ultimate object, unrolling the loop will help.

The above compiles to 14 bytes with slight changes
(output_low/output_high macros). But I would suggest putting
output_low(SPI_DATA) as an else to if (byte & 0x80) as needless
transitions consume power, generate noise, and sometimes confuse the
connected device. Moving it into an else results in 16 byte code.

Forgot how big mine was. A little big bigger IIRC.

David Kelly N4HHE, address@hidden
Whom computers would destroy, they must first drive mad.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]