So I got bored on the weekend...
Posted by: Brent York
on Feb 11, 2010
... and I decided since I was stuck in the house (sick) that I might as well do something fun and useful, like perhaps make something :).
Much like my blogging duties, my bench has been sorely neglected as of late. So I decided to make a DASA programmer for the AVR AtTiny16 microcontroller. After a few minutes of struggling looking at waveforms that looked kind of like this:

And finally digging until I found the ground signal on the cable, I was able to finally make this:

Behold, a DASA programmer for the AtTiny26... It hooks to a USB to serial dongle through a NULL modem cable :). It's slow, but it works.
As many of you know I'm a Linux junkie, so I immediately setup my Linux laptop with gcc-avr, avrdude, uisp, and avr-libc. This enabled me to use C to write my AVR program to test the programmer (which you can see videos of, and a source listing for at the end of this blog post). I also installed an AVR assembler. More interesting though is that I also installed a program called "KontrollerLab", and the requisite emulators for various AVR devices as well.
KontrollerLab for those who are familiar with AVRs is almost an AVR Studio like IDE, but for Linux. Unfortunately it looks to be a long unsupported package who's last build was an alpha. I've had luck with it thus far, and I'm keeping my fingers crossed that I continue to.
It should be noted that the alpha will not build straight out of the box, you'll have to install an awful lot of libraries (some of them by hand), and modify the configure script a slight bit. Namely the package is so old that it expects to still use the KDE ARTS libraries which are long since gone (have been since KDE2).
Other than that, it works great. So I built the programmer, and the software, test-burned a chip (several attempts and small changes to the programmer to get to this point), and built the circuit below ( Yes, I know I could have bread-boarded this a lot cleaner. This is a proof of concept build ;) ).

And after hooking up the battery:
Looks crispy in the dark, doesn't it? :)
And now for a little background about the AVR AtTiny26. The AtTiny26 is an 8-bit microcontroller with a whole whopping 2 kilobytes of flash memory for storing programs. It is low power, and is a RISC based processor achieving 1 MIPS per MHz (and we were running it at 4 in the video). It has 32 general purpose registers which are all directly connected to it's Arithmetic Logic Unit (ALU). It's got an ADC with 11 single and 8 differential ended channels. It's got an 8 bit PWM module, a TWI or two-wire serial interface, and supports SM-bus. It has 128 bytes of EEPROM besides, and 128 bytes of SRAM. It's also got up to 16 GPIOs, also known as general purpose I/O lines of which we use 8 for this light chaser. As with all things engineering, there's trade-offs. The faster you run it the more power it consumes. But all in all it's a very well behaved little micro.
Now... for those of you who haven't worked with micro controllers before, all that verbiage above probably sounded greek... :). The basic gist of this is: It's a small programmable computer on a 20 pin chip. When I say small, I mean small. Look at this thing:

Better yet, the surface mount version of this chip (called SOIC or Small Outline IC) is smaller than a Canadian dime.
The possibilities here are endless, from robot control to analog to digital systems monitoring, pulse width modulation for light control, clock functions, you name it, if you can fit it in 2K of code space, you can probably achieve it with this device.
Cool, isn't it?... Atmel makes a ton of these chips actually. Several different device models, not all AtTiny either, they now have 16 bit and 32 bit micro controllers too. One that Scott and I are particularly interested in (and now that I've got the electrical portion of programming it in-circuit down, beware the evil radio-robots that may ensue) is an AVR with a built in Zigbee module!
Some serious fun is on the horizon here. I can just smell it, and it smells like solder smoke ;).
So, I ask my readers, are any of you interested in this sort of stuff? :) Should I keep posting these things? Let me know in the comments. In the meantime, here's my code:
#include <avr/io.h>
#include <util/delay.h>
/*
* Assumptions:
* - LEDS connected to PORTB
* - F_CPU is defined to be your cpu speed (preprocessor define)
*/
#define DELAY_TIME_MSEC 20
int main (void)
{
int i;
/* set PORTA for output*/
DDRA = 0xFF;
PORTA = 0x00;
while (1) {
/* This algorithm does the light chaser */
for (i = 0; i < 8; i++) {
PORTA |= (1 << i);
if (i >= 3) {
PORTA &= ~(1 << (i - 3));
}
_delay_ms(DELAY_TIME_MSEC);
}
for (i = 5; i < 8; i++) {
PORTA &= ~(1 << i);
_delay_ms(DELAY_TIME_MSEC);
}
for (i = 7; i >= 0; i--) {
PORTA |= (1 << i);
if (i < 5) {
PORTA &= ~(1 << (i + 3));
}
_delay_ms(DELAY_TIME_MSEC);
}
for (i = 2; i >= 0; i--) {
PORTA &= ~(1 << i);
_delay_ms(DELAY_TIME_MSEC);
}
}
return 0;
}
And if you'd like to see updates from me on a more regular basis, you can follow me on twitter. I promise, I'll try to get the next post in the series out soon :). It just needs some proof-reading, I swear.




