Electronics
Arduino: the microcontroller
tl;dr;
Arduino's ATmega328P is outdated. An ARM Cortex-M0+ outperforms the '328P several times, has more features, yet is a lot(!) cheaper.
The Arduino platform dates from 2005, and since that time most Arduino models have used the Atmel AVR ATmega328P as the main microcontroller.
Back then this was not a bad choice. It was still the era of 8-bit microcontrollers, and the AVR was quite good. It ran 1 MIPS/MHz and could be clocked at 20 MHz, giving it a good performance rating. (For some odd reason the Arduino team decided to clock it at 16 MHz, however, thus wasting 20% performance for nothing.)
Yet, while it was a good choice for that moment, it wasn't when looking towards the future. In electronics things move fast. Remember Moore's Law, which says that the number of transistors in a dense integrated circuit doubles approximately every two years? It's not really a physical "law", rather an observation, but for a few decades now it has successfully predicted the exponential growth which still goes on. As a result we get more and more powerful microprocessors and microcontrollers every year. 32-bit microcontrollers had been around since the 1980s but now they're becoming more cost-effective. The best example must be the ARM microcontroller. The ARM is designed by ARM Holdings plc in the UK, and the design is licensed to many microcontroller manufacturers. It's an interesting business model, not just for ARM Holdings, who get a huge market penetration, but also for the end user: with many companies fishing in the same pond she's likely to get a better price. And that is what is happening. 32-bit ARMs can be had for a price which is a fraction of that of their 8-bit counterparts. (Mainly due to the choice for 32-bit by ARM the 16-bit field has almost completely been skipped.)
The current generation of ARM cores is called "Cortex", which consists of several series. The M-series, for instance, consists of families like -M4, -M3, -M1 and -M0, and the most recent addition, the Cortex-M0+. This is an improved version of the -M0, with a lower power consumption yet at a higher performance. The Cortex-M0 was the entry level core, and with the improved Cortex-M0+ ARM launches a frontal attack against the current 8-bit microcontrollers.
One of the microcontroller manufacturers which produces ARM microcontrollers is NXP . I like the NXP ARMs; they have a wide and balanced offering, and offer good documentation. Let's see if the -M0+ stands up against the AVR. I'm going to compare one type which has the same basic features (same amount of Flash and I/O) as the AVR.
ATmega328P | LPC824 | ||
---|---|---|---|
Type | ATmega328P-PU | LPC824M201JHI33E | |
Core | AVR | ARM Cortex-M0+ | |
Word length | 8-bit | 32-bit | |
Clock | 16 MHz (note 1) | 30 MHz | |
Flash | 32k | 32k | |
RAM | 2k | 8k | |
EEPROM | 1k | — | |
GPIO | 23 | 29 | |
U(S)ARTs | 1 | 3 | |
I2C | 1 | 4 | |
SPI | 1 | 2 | |
ADC | Resolution | 10 bits | 12 bits |
# channels | 6 | 12 | |
Comparator | Y | Y | |
Price(note 2) | @ 1 | USD 4.11 | USD 1.92 |
@ 100 | USD 3.01 | USD 1.40 | |
@ 2500 | USD 2.06 | USD 0.837 | |
Price advantage |
@ 1 | 0% | 53% |
@ 100 | 0% | 53% | |
@ 2500 | 0% | 59% |
Notes:
- While the AVR can run at 20 MHz, the Arduino team chose to clock it at 16 MHz, or 20% less performant.
- Prices at Digikey, 2015-05
The ARM Cortex-M0+ is the clear winner, and if we throw in 20 cents for an EEPROM the AVR also loses that advantages. So for less than half the price you get more performance and more features. But it doesn't end there. There's another microcontroller on the Arduino Uno, which is only there for its USB interface. It's an ATmega16U2 and costs another USD 3.18 (all prices for 100 pieces, except when otherwise noted). That's USD 6.19 for the two microcontrollers, that is a lot of money. The Arduino Leonardo fixes this by using an ATmega32U4 instead of the ATmega328P; this one has USB support on chip. Cost: still USD 4.67. For 24% less you can get an LPC11U67. Let's compare both:
ATmega32U4 | LPC11U67 | ||
---|---|---|---|
Type | ATmega32U4-AU | LPC11U67JBD48E | |
Core | AVR | ARM Cortex-M0+ | |
Word length | 8-bit | 32-bit | |
Clock | 16 MHz | 50 MHz | |
Flash | 32k | 128k | |
RAM | 2.5k | 20k | |
EEPROM | 1k | 4k | |
GPIO | 26 | 34 | |
U(S)ARTs | 1 | 3 | |
I2C | 1 | 2 | |
SPI | 1 | 2 | |
ADC | Resolution | 10 bits | 12 bits |
# channels | 12 | 8 | |
Comparator | Y | Y | |
Price(note 1) | @ 1 | USD 6.32 | USD 4.83 |
@ 100 | USD 4.67 | USD 3.54 | |
@ 2500 | USD 3.51 | USD 2.30 | |
Price advantage |
@ 1 | 0% | 24% |
@ 100 | 0% | 24% | |
@ 2500 | 0% | 34% |
Notes:
- Prices at Digikey, 2015-05
The Arduino Mega
In the table above I could have easily compared with an LPC11U68 instead of a '67, and then the difference would even be greater, yet it would still be cheaper than the ATmega32U4. The '68 has 256k of Flash, so it's a good candidate for comparison against the ATmega2560, which is used on the Arduino Mega. The ATmega2560 also has 256k of Flash.
ATmega2560 | LPC11U68 | ||
---|---|---|---|
Type | ATmega2560-16AU | LPC11U68JBD64 | |
Core | AVR | ARM Cortex-M0+ | |
Word length | 8-bit | 32-bit | |
Clock | 16 MHz | 50 MHz | |
Flash | 256k | 256k | |
RAM | 8k | 36k | |
EEPROM | 4k | 4k | |
GPIO | 86 | 80 | |
U(S)ARTs | 1 | 3 | |
I2C | 1 | 2 | |
SPI | 1 | 2 | |
ADC | Resolution | 10 bits | 12 bits |
# channels | 12 | 10 | |
Comparator | Y | Y | |
Price(notes 1,2) | @ 1 | USD 20.90 | USD 5.70 |
@ 100 | USD 15.97 | USD 4.17 | |
@ 2500 | USD 12.62 | USD 2.71 | |
Price advantage |
@ 1 | 0% | 73% |
@ 100 | 0% | 74% | |
@ 2500 | 0% | 79% |
Notes:
- Prices at Digikey, 2015-05
- Prices for the ATmega2560 include the ATmega16U2, which is required for the USB connectivity. The LPC11U68 has USB functionality built-in.
Conclusion
Look at the price differences: the ATmega2560/ATmega16U2 combination is 4 to 5 times more expensive than the LPC11U68. An Arduino Mega based on the LPC11U68 could be priced half what it currently costs, which means it would be as cheap as an Uno.
And so it goes for every comparison between AVR and ARM Cortex-M0+. The ARM is a lot cheaper, yet offers better features. I could add a comparison with a USD 20 microcontroller, but it wouldn't be easy to find such an expensive one, and even if I did the comparison would become ridiculous; any USD 20 microcontroller would dwarf the ATmega2560.
You even can buy a SBC from NXP with the even more powerful Cortex-M3 core for the price of the Uno.
There's only one possible conclusion: the AVR is hopelessly outdated, and Arduino LLC should get rid of it.
How did all this happen? How can you make such really bad choices? (It happened for the selection of other parts too.) I don't know, but I've got a hunch. Arduino started as a project by amateurs, students, and I'm afraid it's still run by amateurs. It's as if they didn't make their homework, and failed to investigate several options to come with a solution the customer benefits most of.
Update 2015-05
Arduino has announced the Arduino Zero, though because of legal troubles within the team the release may be some time away. The Zero is indeed based on a Cortex-M0+, as I suggested above. But again the Arduino team chose for Atmel. Again not the best choice. The ATSAMD21G18A costs USD 4.52. If they would have chosen the NXP LPC11U68 the cost would have been USD 3.48. Again that's 23% less.
To the Arduino team: please do your homework before selecting a microcontroller. Atmel is not always the best choice. The Arduino Zero Pro (by an Arduino disruption) is available at Adafruit for USD 55 . While an M0+ can be had for less than an AVR. Need I say more?
Update 2016-01
The Pine64 SBC was announced in 2015 for production in the first half of 2016. Its microprocessor is literally hundreds of time more powerful that Arduino's (75 times clock speed, 4 cores, 8 times word length). The Pine64 comes with everything to make it a PC: 4K HDMI, Ethernet, Bleutooth, USB, up to 2 GB of RAM, etc. Yet it will cost only USD 15, 40% less than Arduino. Again, need I say more?
Other options? Raspberry Pi is a well-known SBC with a 64-bit ARM running at 1 GHz (62× faster than Arduino) at a comparable price. More impressive is Adafruit's Raspberry Pi Zero , a shrunk version of the Raspberry Pi, which sells for 5 dollar! Still featuring:
- micro SD card slot, ideal for your Linux OS
- mini HDMI port
- 2 micro USB ports
- 512 MB of RAM (Arduino Uno has 2 kB, or 0.0004% of that)
- 1 GHz 64-bit ARM
- camera port
All that for the price of a couple of coffees. Again, need I say more?