AVR Microcontrollers

I have been using Atmel AVR microcontrollers since Fall 2001 and I think it's a very good architecture. There are lots of flash microcontrollers around these days, but I was first attracted to AVRs because the free GNU C compiler (gcc) can compile programs into AVR code. And because you can reprogram them without disconnecting them from the circuit; and the newer ones can even reprogram themselves without resetting. Anyway, enough of that.

Development Tools

I spend as much of my computing time as possible in Linux, so of course I have sought out the Linux AVR tools. The most critical tools are a programmer (hardware and software), an assembler, a C compiler, and some libraries. I'm going to refer to other web sites on how to build a programmer circuit, since there are many. My first programmer was a parallel port contraption based on the AVR direct parallel dummy programmer described here (local copy). You can also buy a programmer and get started a little quicker. Here is the software that I use for normal development:

Example Code in C

Here are some short example programs for AVR, written in C. These are known to compile in avr-gcc. I've compiled binaries for 8515, and if there are any requests I'll compile for other chips too.

AVR programming

I've used several types of programmer circuits that work, but eventually decided to stick with the serial port programmer described in Atmel application note 910 (AVR910). The programmer consists of a serial port connection and an AVR (usually AT90S1200) that runs the AVR910 code. Since it's sort of a standard, nearly all programming software supports it. Also, I wanted to use the AVR109 boot loader, which follows the same protocol.

Here are links and patches related to the AVR910 programmer.

AVR Boot Loader

To reprogram a robot across an infrared link, I have been using the self-programming feature of the ATmega163. I couldn't find any solutions to this problem on the web, so I went back to the basics. Atmel application note #109 talks about boot loaders and includes code for an AVR boot loader, so this was a good starting point. It was written for a commercial C compiler called IAR, which I don't have, so I ported it to avr-gcc and fixed some bugs. Then it wasn't as fast as I would like, so I made some optimizations to improve programming speed.

This schematic shows one way to set up an ATmega to use a boot loader. The top of the diagram is a standard AVR serial programmer, which you need in order to program the fuse bits and the boot loader itself. At the bottom is an example application circuit with an ATmega. Once the boot loader is working, you don't need the AVR programmer anymore. You can reprogram the device with just the serial connection.

Now that it works for me, I've cleaned up the code and created patches so that other people can try it too. Here are links to the originals, and my latest patches:

Since an IR link is not reliable, I wrapped up the programmer commands with a very simple packet structure with a sequence number and checksum. I'll post this eventually. Let me know if it would be useful.

Performance of uisp with multiword writes

To see how much multiword writes were helping, I tested with a sample 8K program. The table shows how long it took to download 8K using uisp with various baud rates and download styles.
Baud rate AVR910 programmer AVR109 boot loader AVR109 boot loader
with multiword patch
2400 ? 258.7 sec 46.8 sec 5.5x
4800 ? 171.6 sec 24.4 sec 7.0x
9600 ? 86.3 sec 12.6 sec 6.8x
19200 88.3 sec 86.3 sec 8.0 sec 10.8x

For a while, I tried to hack multiword writes into AVR910 to see if it would help there too. But then I realized that because the AVR910 code does both the UART code and SPI transactions in software, it cannot keep up with a long stream of writes. You could try to buffer all the writes until the end, and then do all the SPI accesses at once. But I'm doing this for fun, right?

AVR Links

Please let me know if you have any suggestions for these pages. I'm not a robotics expert, but I want to share what I have learned.