home  general  lard  ArdweeNET  MAXX  the QUUB  Gecko  SiiMAN
        embedded systems  PC software

While writing a bit-banged serial routine I noticed how much time was spent by the code just getting into and back out of the interrupt service routine (ISR).

Here's some pseudo code to give you an idea what was written.

ISR() {
   set bit on serial OP line
   calc next bit

main() {
   do some work
   if(serial line is idle) send another byte

Have a look at the following trace from my logic analyser.

Note the green part, that's the main() routine trying to do some work, in this case I'm just pulsing a spare I/O line so I can see what's happening. As we can see we get 5-6 pulses in before it's time for another bit to go out the serial line.

The yellow(ish) part in the middle is the ISR deciding what bits to stuff out the serial line (the top trace is the actual serial output). The ISR takes 81uS.

The two red parts are the processor entering and leaving the interrupt. Of course this code is written in C so there is a lot more overhead for a call than in assembler. This takes 67uS in total, almost as long as the ISR.

So as we can see, using an ATtiny85 processor running at the internal resonator speed transmitting a serial bit stream at 4800bps there's very little time to do any real work which still can be OK in many applications.

You can actually improve this a lot by using the compiler's optimising options so that's my next tip.

Top of Page


  home  general  lard  ArdweeNET  MAXX  the QUUB  Gecko  SiiMAN
        embedded systems  PC software

Copyright © 1973-2013 Rob Gray, All rights reserved.
PO Box 450, Gin Gin, QLD, Australia.