
Sega vs. Nintendo, Mac vs. PC, Android vs. iOSโฆ the tech industry has spawned its fair share of โholy warsโย in our time. But thereโs one thatโs had Makers and embedded engineers up in arms since the nineties โ the war of the 8-bit microcontrollers: Microchipโs PIC vs. Atmelโs AVR.
With Wednesdayโs announcement that Microchip will purchase Atmel for $3.56 billion, is the war finally over? What does this mean for the future of embedded development?
Probably not much in the short term. Microchip and Atmel will continue to produce and provide support for their existing devices well into the future, since, well, theyโre in everything. In your home, in your car, in your pocket โ Microchip has shipped over 12 billion PICs to date, and the Atmel megaAVR is the chip that powered the first Arduino, which introduced scores of Makers to the world of physical computing.
Thereโs a lot of promise here though. Microchip/Atmel have the the opportunity to combine the best of the AVR and PIC worlds into an awesome microcontroller platform. Despite the growing popularity and decreasing cost of powerful 32-bit ARM chips, there are still plenty of applications where 8 bits are all you need.
So what are the differences between PIC and AVR, and do they even matter? If youโre just starting out in the world of embedded software, youโre probably good to go with an Arduino board and its easy-to-use tools. But when you want to take the next step โ turning your prototype into a production-ready device, or building timing-critical applications โ youโll have to make a choice.
AVR: Open Source, Maker Friendly
If youโve used an Arduino before, youโve already programmed the AVR โ itโs in the Uno, Pro, Mega, Gemma, LilyPad, Leonardo, Diecimilia, Duemilanove, and more. It’s popular with Makers because it’s been embraced by the open-source community. If you want to get started with standalone AVR programming, all the tools you need are available for free, for all operating systems. AVR-GCC is a full-featured and well-supported C compiler (if you use a Mac, setup is as easy as installing CrossPack), and the AVRDUDE utilityย lets you upload your code to an AVR microcontroller using one of many programming devices like Atmelโs official AVRISP mkIIย or Sparkfunโs Pocket AVR Programmer.
The โRโ in AVR stands for RISC: reduced instruction set computing. What that means is that if you ever want to get your hands dirty with some assembly language, youโre gonna have a blast. The instruction set is both well-suited for C compilers and straightforward enough to allow hand-coding of time-constrained routines. Thereโs a sizable number of awesome AVR projects out there that do amazing stuff with assembly language: Linus “lft” ร kessonโsย Craft, Phasor, and Bitbangerย demo boards, the Uzeboxย game console, and my own Terminalscopeย project that can let you browse the web on your oscilloscope.
Unfortunately, where the AVR falls short is in bang for your buck. The ATmega328P, heart of the Arduino Uno, costs $3.70 for a breadboardable DIP package. This gets you 32K of ROM for your code, 2K of RAM, and 23 I/O pins: six of which can be used to read analog voltages, and six of which can output PWM signals for driving motors or fading LEDs. If you want more pins or more memory โ say, 16K of RAM and 32 I/O pins, in a 40 pin DIP package โ youโll have to upgrade to the ATmega1284, which will run you a whopping $7.67! If youโre OK with surface-mount soldering, there are cheaper options with more exotic peripherals like onboard USB, but youโll find similar parts from other manufacturers at a tiny sliver of that price.
โThereโs a PIC for thatโ
Before Arduino, the Microchip PIC was the chip of choice for hobbyists and professionals alike. Their product lineup is huge, theyโre packed with peripherals, and theyโre dirt cheap. Want 28 analog input channels in a DIP package? The PIC16F1717ย is $2. Want to make something cool that talks to your computer over USB? PIC16F1454, $1.40, no extra components needed!
Microchip has put some pretty interesting peripherals in their PICs that can reduce or eliminate the need for external components, potentially reducing costs further. Many have onboard digital-to-analog converters (DACs) for generating true analog output voltages. The Complementary Waveform Generator can simplify driving of DC motors. And the Configurable Logic Cell is kind of like a tiny FPGA: it can perform simple operations (AND, OR, XOR, and more) on input signals and route them to outputs without any intervention from the main processor โ even in sleep mode.
So PICs are dirt cheap, widely available, and have plenty of cool stuff on board โ whatโs the downside? Why was it the AVR that rose to megastardom in the Maker microcontroller revolution of the mid-2000s and not the PIC? Many would say that itโs the tools. While there are numerous free and open-source tools out there for AVR development, if you want to program PICs, youโre gonna need to use Microchipโs software and hardware.
Until a few years ago, this restricted PIC development to Windows users only. Microchipโs current integrated development environment (IDE), MPLAB X, is built on the NetBeans platform, and runs on Windows, OS X, and Linux. The download is a hefty 500+ MB. The user interface can be daunting, with its array of toolbars, sidebars, and configuration dialogs. If youโre more of the command-line type, itโs possible to use a script buried deep inside the MPLAB X app bundleย to upload code to your chip.
Unlike the AVRโs clean RISC architecture, the PICโs memory is segmented into banks of 128 bytes, only one of which can be active at a time. This arrangement has hindered the development of open-source compilers. The Small Device C Compilerย is the only one that Iโm aware of. Iโve used it to produce working results, but it may not support all features of the latest chips, and has some bugs. If you want to program a PIC in C, your only other option is Microchipโs XC8ย compiler. The free version doesnโt perform any optimization on your code: if you want to build the fastest code possible, youโll need to buy a Pro license, which will set you back a thousand bucks. A justifiable expense for a professional engineer thatโs shipping a million devices, but sadly out of range for most hobbyists.
As far as device programmers go, the PICkit 3ย ($50) is the only device guaranteed to support the latest PIC models. They can be tricky to set up (mine wouldnโt work with my Mac out of the box, and I had to use a Windows PC to upgrade its firmware) but do the job just fine.
The Future
Iโm dreaming of Microchip/Atmel releasing aย new generation ofย microcontroller with the AVR architecture, open-source toolchain,ย and the PICโsย wide selection of peripherals and low price โ but is it too late? 32-bit ARM Cortex-M devices, such as those in the Teensyย and Arduino Due, are poised to take over the low-end market, and full-featured Linux systems like the Raspberry Pi Zeroย and CHIPย can be bought for a handful of dollars. But thereโs something to be said for the sheer simplicity of the 8-bit micro. You can learn everything there is to know about one in a few weeks. Squeezing every last drop of performance out of a chip โ counting clock cycles, writing hand-tuned assembly language, slicing off instructions to get your code to fit on a cheaper part โ these are what keep me and countless other hackers excited about embedded development.
ADVERTISEMENT