What’s the difference between AVR microcontrollers?


When you delve into the world of microcontrollers there will be inevitable confusion about the different versions of what appear to be the same family of microcontroller.

In the Arduino world, the initial choice was the Atmel ATmega8 running at 16MHz. Subsequent versions of the Arduino used the ATmega168 as well as the commonly-known ATmega328, both running at 16MHz as well. (the Arduino “Mega” series are an offshoot, but the principles presented here remain valid…)

So what’s the difference between an ATmega8 and an ATmega328? Truth be told, for most hobby/maker applications, almost zero!

The most significant difference amongst the ATmega8/168/328 is the amount of “flash” storage space in the chip, which is roughly analogous to a hard drive in a PC (room for programs). The amounts are 8kb, 16kb and 32kb. Here’s the rub, if you don’t exceed the flash size limitation, the difference is utterly useless! There will be no difference in execution speed, or anything else, if you code fits into a smaller size. (Note, to muddy the waters a bit more, there’s also an 8kb ATmega88, which is in exactly the same family as the ’168 and ’328)

Putting aside the Arduino Ethernet shield code examples and SPI devices in general, which are notoriously complicated, most of the examples included with the Arduino 1.01 IDE will fit into 8k of codespace. For example, Arduino code that drives a two-line LCD display, and tracks and calculates RPM based on a hall-effect (magnetic) rotation sensor, barely exceeds 3k!

Amongst the various family members, there are other fairly transparent or minor differences, like pin-change interrupts (which Arduino does not directly support outside of the dedicated INT0/1), the amount of RAM, and with the ATmega8, the number of PWM channels available.

RAM and a microcontroller is kind of an odd situation, since it’s not like a PC which might just get sluggish if you “use up” all your RAM. With a microcontroller, it will probably just freeze if you run out of RAM!

That being said, unless you have very complex code, (or poorly written code), RAM will probably never be an issue, and as long as your program works, having more is no benefit whatsoever!

In closing, the best professional programmers are almost always striving for what is known as “tight” code, which means code that executes a task with the absolute minimum number of CPU instructions. Given the relatively tiny memory sizes available on the Arduino ATmega microcontrollers, it makes sense to always strive for tight/efficient code. Overall, it’s just a good practice to get into, no matter how much memory or processing power you have!

Comments are closed.