PSA: if you're a fan of ATmega, try AVR Dx
A little-known offshoot of the ATmega series of 8-bit microcontrollers is better, faster, and cheaper than its progenitor.
The first AVR ATmega microcontroller debuted in 1998 and took the world by storm. In contrast to other embedded 8-bit processors of the era, it required no external components, could run off a wide range of supply voltages, and worked with the GNU C Compiler when others required you to learn assembly or pay for proprietary tools.
Since then, ATmega MCUs remained a staple of hobby engineering. In recent years, their market position has been challenged by single-board computers and the wi-fi-capable ESP32; still, the AVR architecture remains the go-to option for those who want to get things done without wrangling schedulers or understanding the messy clock and memory architectures of Cortex-M chips.
Yet, relatively few ATmega fans realize that Microchip recently released a revamped series of 8-bit AVR MCUs: AVR DA and DB, along with the more specialized AVR DD and DU. The products are not being marketed to hobbyists. Instead, they’re advertised for automotive and industrial applications. Still, they’re cheaper and better in almost all respects — and just as easy to use.
The price difference can be stark; for example, if you want a microcontroller with 128 kB of program memory, you can get AVR128DA28 for under $2 a piece; the cheapest older-generation chip with the same amount of flash — ATMEGA1284P — is $6.
When it comes to architectural improvements, the most universally useful change is that AVR Dx can internally generate clocks up to 24 MHz; the ATmega can only do 8 MHz, and you need external timing to reach 20 MHz (attainable only at some supply voltages). Another nice touch is a single-wire UPDI programming and debugging interface, simplifying PCB layout and saving space. The new chips also feature reduced power consumption, better ADCs and DACs, on-board op-amps, and programmable LUT-based logic units that can implement real-time automation without involving the CPU.
From the software side, the differences are small; you use the same avr-gcc, avr-libc, and avrdude toolchain, and most of the on-die peripherals are configured and operated roughly the same way. AVR Dx is not a drop-in replacement, but porting is a breeze.
To the extent that the semantics differ, the changes are for the better. For example, on the ATmega, you had no C-level idiom for the exceedingly common task of clearing or setting single output pins. Instead, you had to spell it out as read-modify-write operation. You then crossed your fingers and hoped the compiler outputs a single SBI or CBI opcode instead of what your program asked it to do:
void oled_send_cmd(uint8_t cmd) { PORTA &= ~_BV(OLED_A_DC); /* Clear the DC bit */ PORTA &= ~_BV(OLED_A_WR); /* Clear the WR- bit */ PORTB = cmd; /* Prepare command */ PORTA |= _BV(OLED_A_WR); /* Set the WR- bit */ }
In contrast, on an AVR Dx chip, you have separate “set” and “clear” registers, removing the need for wishful thinking and error-prone Boolean logic. The same function can be rewritten as:
void oled_send_cmd(uint8_t cmd) { PORTA.OUTCLR = _BV(OLED_A_DC); /* Clear the DC bit */ PORTA.OUTCLR = _BV(OLED_A_WR); /* Clear the WR- bit */ PORTB.OUT = cmd; /* Prepare command */ PORTA.OUTSET = _BV(OLED_A_WR); /* Set the WR- bit */ }
Microchip has a short migration doc explaining the differences between the platforms. If you prefer to learn from examples, I also published the source code for two of my earlier AVR Dx projects: an audio toy and an OLED game.
If you liked this article, please subscribe! Unlike most other social media, Substack is not a walled garden and not an addictive doomscrolling experience. It’s just a way to stay in touch with the writers you like.
If you’re wondering about the differences between 32-bit and 8-bit MCUs, check out this followup article. For more articles about MCU programming and electronics, click here.
As for the differences between models:
AVR DA is the all-around baseline. It's available in packages between 28 and 64 pins and goes up to 128 kB of flash. It has a good mix of digital and analog peripherals.
AVR DB is essentially identical, except for small changes to accommodate some additional signal processing use cases. The chips are interchangeable in most uses and cost about the same. On the DB series, you lose one I/O pin (PD0), gain an op-amp, and have a separate voltage domain for one port. You also have support for a high-frequency crystal, whereas DA only supports a 32.768 kHz timekeeping one.
AVR DD is a stripped-down version of DB, available in smaller packages (14-32 pins) and with less program memory (64 kB). It's a reasonable choice when you want something small and cheap - the series starts around 90 cents, and can do a lot more than ATtiny.
AVR DU is a flavor of AVR DD that has an on-die USB 2.0 subsystem that requires no external components; this includes no need for an external crystal. It's great for HID accessories and such - and likewise, it's pretty darn cheap.
megaAVR/tinyAVR 0-series are similar too.