We never have enough peripherals on a microcontroller. Whether it’s hardware-driven PWM channels, ADCs, or serial communication peripherals, we always end up wanting just one more of these but don’t really need so many of those. Atmel’s new version of the popular ATmega328 series, the ATmega328PB, seems to have heard our pleas.
We don’t have a chip in hand, but the datasheet tantalizes. Here’s a quick rundown of the new features:
- Two more 16-bit timer/counters. This is a big deal when you’re writing code that’s not backed up by an operating system and relies on the hardware for jitter-free timing.
- Two of each USART, SPI, and I2C serial instead of one of each. Good when you use I2C devices that have limited address spaces, or when you need to push the bits out really fast over SPI.
- Ten PWM channels instead of six. This (along with the extra 16-bit timers) is good news for anyone who uses PWM — from driving servos to making music.
- Onboard capacitive sensing hardware: Peripheral Touch Controller. This is entirely new to the ATmega328PB chip, and looks like it’ll be interesting for running capacitive sense buttons without additional ICs. It relies on Atmel’s QTouch software library, though, so it looks like it’s not a free-standing peripheral as much as an internal multiplexer with maybe some hardware-level filtering. We’ll have to look into this in detail when we get our hands on one of the chips.
So what does this mean for you? A quick search of the usual suspects shows the chips in stock and shipping right now, and there’s an inexpensive dev kit available as well. If you write your own code in C, taking advantage of the new features should be a snap. Arduino folks will have to wait until the chips (and code support) work their way into the ecosystem.
Thanks [Peter van der Walt] for the tip!
114 thoughts on “Bye-bye ATmega328P, Hello 328PB!”
as much as i like the new hardware i really want to get away from 8 bit micros. slow clock, low memory, still no native usb. i suppose when you build in volume or just want a low pin count its fine. but price wise its not much more expensive to just get an arm.
Really depends on what you need… for me, I find that 8 bit micros can do a lot. Of all my projects to date, all but one are done with 8 bit micros.
As for the native USB thing, look at the Mega32u4. That is my go-to chip these days… a lot of power packed into a very easy to use package.
Yep. 8-bit rocks for most things.
And … correct me if I’m wrong but hasn’t the Leanardo/Pro Micro had all those extra features for ages.
I’ve been using the 32U4 in lieu of the 328 for a long time. The 32K flash space ceiling won’t go away though. I’m targeting my newer projects off the Ultrino. Almost as easy to use and you have a ton more resources.
What’s an Ultrino – I’m not finding it.
I use either ESP8266 or one of the STM32 micros. They work inside the Arduino IDE, 32-bit, and I can get them for less than $4 and that includes shipping. There is a group that works with these STM32 at http://www.stm32duino.com
You can now get an ARM for about $0.50. Little reason to stick with AVR these days: http://www.aliexpress.com/item/10pcs-STM32F030F4P6-32F030F4P6-TSSOP20-100-New-and-Original/32479516689.html?spm=2114.01010208.3.101.XjfD8r&ws_ab_test=searchweb201556_6,searchweb201644_2_10001_10002_10005_10006_10003_10004_62,searchweb201560_8,searchweb1451318400_6150,searchweb1451318411_6451&btsid=8b9f9d39-f0c7-415c-8fe5-bfc6ed4cce35
Could you suggest somewhere to get started using these types of chips in projects? For me the Atmega stuff has been very approachable due to being able to use an arduino as the project platform or the ability to use the arduino to program the chip and then stick it where it needs to be.
What hardware/software is necessary to begin programming these chips to read digital/analog inputs/outputs?
what kind of libraries are available?
I think the simplest path for an Arduino user to get into ARM is to use mbed.com. The web-based IDE is way nicer than the Arduino toolchain. Pick up a something like a ST NUCLEO-F401RE for $10 and you’re all set. It’ll even fit any Arduino shields you might have (probably 3.3V only, not sure about that).
pjrc.com offers Arduino-compatible dev boards with ARM Cortex-M4 and Cortex-M0 processors. These can also be programmed through the command line or even bare metal when you’re ready to step away from Arduino. The hardware quality, support and prices are awesome.
Start at http://www.stm32duino.com I bought at STM32F103C8T6 board on Ebay for less than $4 and installed the libraries in the Arduino IDE and going in no time.
Get one of the ST Discovery board that has the chip you want. It comes with hardware debugger/programmer, You can use it to program/debug external ST ARM chips if you grow beyond playing with eval boards.
Something like MDK is a good starting point for beginners: http://www2.keil.com/mdk5
It is a commercial program. The demo version is limited to 32K code/data. Unlike open source tools, it has support for all the ARM chips from all the vendors. You can do full source code debugging and modify hardware registers (with full annotation of the register bits names) from a GUI.
MDK also set up the open source GCC tool chain and you can switch to that within your projects. The open source tool chain are not as well integrated, but do not have code size limits.
The mbed.com development environment is nowhere near as user-friendly as the Arduino. The library support is far smaller than that for the Arduino as well.
So while the processors are very powerful and offer great bang for the buck, they are only appropriate for more experienced users.
For an easy start I would recommend getting some STM32-discovery board (or STM32NUCLEO) together with Coocox (http://www.coocox.org/). The IDE is easy to setup and is (somewhat) open-source. It also comes with a built-in RTOS (CoOS). Sure, the IDE is severily retarded (not as retarted as Arduino IDE though) being a destroyed Eclipse, but if you are looking for is an easy setup, it’s a recommendation. Btw, make sure to not use version 2.x.x. since it doesn’t work. Also, it only runs on windows, which is a minus.
For a proper setup, I recommend Eclipse combined with GNU-ARMeclipse plugin (http://gnuarmeclipse.github.io/). The setup is a little more complicated (however much easier than when I started with ARM-chips several years ago). Using the STM32-templates it’s easier to get started with at least STM32s (except for the F4-serie, where they have migrated to the ST-HAL lib, which is really severily retarded. I stick with the older std-periph lib).
STM32F103C8T6 boards off of Ebay work with mbed, as mbed supports the chip in NUCLEO-F103RB . Only difference is the FLASH memory – Ebay boards have 64Kb, NUCLEO has 128Kb.
You only need a STLink or regular USB-serial converter, depending on how you want to program the chip.
I think the simplest way for an arduino user to get into ARM, is using a kit from Arduino or their partners with an ARM device on it. The Arduino DUE uses a pretty old Cortex M3, but the best options are the Arduino Zero using a 256kB Flash 32kB SRAM Cortex-M0+ (with on board programmer and debugger) or the similar lower cost boards from
SAM D21 mini $20! https://www.sparkfun.com/products/13664
SAM D21 breakout $25! https://www.sparkfun.com/products/13672
About the eBay boards having 64KB, most actually work up to 128KB. It looks like the 128 en 64kb version are made using the same die most of the time. Of course don’t do this with something critical, but when experimenting, why not…
Generally speaking, the low cost ARMs are pretty bad in terms of low power, so you might want to look elsewhere if you need something battery powered.
My question is, how much do you trust those chips from alixpress….it’s not like they don’t have a history of fake chips.
Most of the time, these prices are close to what you would see here at QTY 1K or 5K. It just means that someone is using these parts for a product and parts get trickled down bypassing the the usual distribution/support chain.
There is counterfeit protection from Aliexpress which act as escrow, so at worse, it is a waste of time and disappointment. Mega is a well known enough seller, so there are little risk at $4.40 US anyways.
@tekkieneet, yes, i know about the protections. but in my experience from purchasing things from there(or ebay or others) is that whenever you buy multiple of something, there are a few with problems in the batch. It may be possible that everything is good, but for some things i am using the local price. sure, that chip will cost me more, but i am sure to not waste time.
I can almost say the same, but depending on your use case. I don’t need fast clocks, usb support, and whatnot all the time on my projects.
Microchip has few 8bit micros with native USB, I guess Atmel also has that feature.
And some of the ATtiny as well from memory, but in any case there are quite a number of the 8 bit AVR’s that have USB
The ATtiny series do not have native USB support. A lot of people favor the t85 or 2313 and use V-USB to accomplish low speed USB via software.
I’ve been looking at the PIC16F1454/1455/1459 for a new design actually, it does have USB, finally
Pic24 for a little over $1 solves many problems. Why fiddle with 8 bit
Because in many cases more bigger/faster != more better.
I personally LOVE 8 bit micros because they dont do a lot. you can make small disposable projects with how cheap they are.
I have one that is just simply a temperature logger. one 1 wire temperature sensor and a micro SD card. I dont need another 1000 IO ports or 50 analog ports. If you are trying to do 50 things with a 8 bit micro then you have the wrong idea as to what the things are for.
perfect definition of “I know what I’m doing”. thanks.
True, thank you.
These days, most people would just use a RasPi for that. I mean, it has filesystem drivers built in, and then you can write the code that reads the sensor and saves it in any language that you want, probably python. That is the standard template for any project these days.
Anyhow, you should link your project … that would be very useful for debugging my crap-from-the-factory Traeger smoker that I have …
When I first got into 8-bit micros for me it was more about ease of prototyping with PDIP and breadboards, no soldering needed.
There’s probably some PDIP ARM out there too, but what I found at the time first was Atmel.
http://www.ebay.com/itm/Digispark-ATTINY85-General-Micro-USB-Development-Board-For-Arduino-New-LO-/161885081074?hash=item25b11a4df2 $1.41 free shipping. You don’t have to buy crystals, caps, and resistors.
http://www.ebay.com/itm/USB-CH340G-Nano-V3-0-16M-5V-ATmega328P-Micro-Controller-Board-For-Arduino-/262123424219?hash=item3d07c609db 328P with USB. $2.13 free shipping.
http://www.ebay.com/itm/STM32F103C8T6-ARM-STM32-Minimum-System-Development-Board-Module-For-Arduino-M2-/221982023431?hash=item33af28df07 $3.43 free shipping.
I’m just showing that for less than $4 you can plug and play most of these. You don’t have to buy crystals, caps, and all and for the price they are disposable.
I like my Pro Mini’s from AliExpress for $1.5/ea
$.09 more then that Tiny85 and you get a whole lot more.
the intel curie (arduino 101) has native usb, 80k of user memory (prog+data), a separate uart on pins 0,1 (separate from native usb) and is not at all an 8bit cpu ;)
Have a look at the ST-Nucleo boards. They all come with a built-in debugger, serial-to-USB and drag and drop programming capabilities. In addition, all STM32 chips also have built-in ROM/factory bootloaders that can be easily accessed over Serial or even USB with a tool like dfu-util in case you decide to roll your own. The STM32 MCU’s come with decent peripherals and reasonably good documentation. Also they are some of the lowest cost MCU’s out there.
The Nucleo-32 boards have a similar size to the arduino nano whereas the Nucleo-64 boards are arduino Uno sized. Both board form factors cost about $15 and have varied target STM32 MCUs; STM32F1,F0,F3 & F4 families are all represented. ST is also releasing, the Nucleo-144 form factor boards that will be arduino Mega sized, still come with debugger, USB-to-Serial, and drag and drop programming, and some will support Ethernet and onboard USB, all for around $20.
ST-Nucleo boards are supported by the mbed environment for higher abstraction arduino like programming. But they can also be programmed using the Free STM32 Workbench IDE and STM32Cube libraries that come from the manufacturer.
In my mind these chips especially the STM32F0 parts are the new ‘AVRs’.
There are 8bit Micros with USB, slow clock and low memory? Maybe using the wrong micro… One thing is certain, don´t be religious over microcontrollers, just use what is the best for your application. And of course it also depends on what you can do. You can squish for memory and performance in a million ways, you´ll be surprised with what is possible…
If you look on a wider scale there are some interesting chips out there:
1) PIC18F4550: 32kB Flash, 2kB SRAM, native USB, 64MHz @ 3.3V (I’m looking at you, STM32L152)
2) ATxmega128A1U: 128kB Flash, 8kB internal SRAM, native USB, 32MHz @ 3.3V, up to 16MB external SRAM or SDRAM
The 168PB came out over a year ago, though it doesn’t have as many of the extras as the 328pb.
Plus, the latest pre-built version of the toolchain doesn’t include support for the pb.
I updated some old build scripts that were posted on avrfreaks, so you could build from source and patch avr-libc with a header for the 328pb (the 48pb and 88pb were just added to SVN, but neither the 168pb or 328pb are in yet).
Here’s the build script I mentioned:
These chips come only in TQFP and QFN packages, so I doubt they will be very popular among the Arduino crowd. Perhaps some Arduino compatible board with them will appear, but otherwise not a whole lot of interest.
And the other question is how long will these actually stay on the market, considering that Microchip has bought Atmel and they have quite a few competing micros in this price range – typically with many more and more advanced peripherals than AVRs ever had.
The new AVR chips are already released, so their development cost is sunk. The only reason Microchip would take them off the market is because they’re trying to move AVR users to PIC. Do you really think that’s going to happen? I’m pretty sure they’d lose more designs to ARM than they’d shift to their other 8-bit line.
QFN is a pain the in you-know-what to hand solder, though it can be (and I have) done. TQFP is no problem, though, for hand soldering. So if you’re designing your own PCBs and then building them by hand, the TQFP version is definitely usable IMHO.
Now, if you’re referring to the lack of a DIP package for breadboard use, sure, but in that case just buy a TQFP to DIP adapter.
Not sure it’s worth bothering with the DIP version of the normal 328 for breadboarding either, it’s more than an Arduino Pro Mini clone with the TQFP chip and supporting components last time I checked.
However, QFN is extremely easy with solder paste and hot air, much more than QFP. If you’re designing a PCB and have the option of either, try QFN and get a stencil and some paste.
Even without paste it is not difficult to solder a QFN, especially without a bottom pad. The drag soldering method that you use for QFP works for QFN as well with the right tip.
I suppose that for hand-soldering QFNs you need to choose larger (longer) out-extending pads layout, so that soldering iron can make greater surface thermal contact with them
“competing micros in this price range – typically with many more and more advanced peripherals than AVRs ever had.”
– can you name any? I really wanted to find a good alternative in PIC, but there is none. They cost 2-times more with same peripherals or have half of them for the same price.
ST’s ARM chips, really cheap and have much more to offer. For example this board – http://goo.gl/S15Ujr, $2.5 + shipping for 72MHz with USB, ISP programming and a lot of peripherals (they even have a freakin’ CAN interface, not sure if the chip on this board has it, but it’s the same family).
Not the same family nor even the same ARM core… STM32F0xx = Cortex M0 (low end part) vs STM32F1xx Cortex M3.
“Two more 16-bit timer/counters. This is a big deal when you’re writing code that’s not backed up by an operating system and relies on the hardware for jitter-free timing”
If you’re talking about timer interrupts, keep in mind you can’t have more than 1 jitter-free timer.
Well, with input capture, that changes a little. But that depends on what you’re doing.
Strictly speaking, on AVR (unlike PIC8) there is no such thing as a truly jitter-free interrupt due to varying instruction times, though of course this jitter is much less than that caused by multiple interrupts.
Pretty sure jitter-free interrupts are no longer a thing on modern PIC8s.
For example the PIC12F1571 datasheet lists the interrupt latency as 3-4 instruction cycles for synchronous interrupts and 3-5 for asynchronous interrupts.
It only takes a few lines of code to read the counter register in the ISR and delay an appropriate amount.
What they need is more things that can do something on a timer event. USI/SPI is pretty good for capturing bit states at specific times, but it’d be really nice to have hardware that provides a time stamp on bit flips.
Not sure I fully understand your use case. Does the input capture feature do what you want?
I’m not sure what you mean by input capture. What I mean is that with USI/SPI you can sample input pins and output waveforms with very specific timing. With USI at least you get up to 15 sample periods before you overrun/underrun. The PWM modes can also generate precise timings but one one bit at a time.
A use case for timestamping transition times would be for instance to time the low period of a waveform without being limited by latency introduced by periods that interrupts are disabled.
Somehow we’re missing each other. If you want to time something, use the timer’s input capture function. Set timer, and it’ll stop timing at first up/down transition and then throw an interrupt or pollable flag. You can read the value out at your leisure thereafter.
This way, the time won’t depend on interrupt latency or anything else.
I think what’s confusing me in your question is that you keep talking about the SPI and serial comms, which is a totally different problem from timing edges. Which makes me unsure that I’m answering you… :) Apologies if not.
My attiny does not have this feature of stopping the timer on an edge, didn’t know the mega timers had it. Neat. Anyway, SPI can be used for solving a different problem, capturing level at specific intervals, and output edges at specific intervals.
Input capture latches the time stamp in a register, but leave the timer running.
The 328’s never made their way into my regular-gotos, actually only used one ever… But 10 PWM channels and five timers is slick.
Still waiting for regular-ol’ AVRs like these that have PLL timers… Still only the Tiny85/861 and AT90PWMs…? Guess it is kinda niche.
maybe look at the XMEGA family? those have PLL up to 128MHz for the peripherals.
Muchas Gracias! I did once look into the XMEGAs, and the funny thing, from the manual I read, was that the Timer could run on the PLL, but that the dead-time generator runs off the normal system clock… Unfortunately didn’t fit my (niche) needs.
Ah, indeed. it runs of the peripheral clock. You can make that equal to the system clock, but only if you limit to 32MHz.
Hey! How’d I miss this one? Looks like it’d do, on Timer 4. Thanks! And USB to boot.
If you use it let me save you some time if you don’t read a datasheet in full everytime you touch a new part. The part ships with programming protection enabled and bootloader code already in place.
I bashed my head against the wall for a good 10 minutes before I realised that the preferred method of programming is via Atmel Flip using the built in bootloader over USB. Or you can erase all the chip.
Awsome tidbit. I hope you don’t mind I copied that to my page: https://sites.google.com/site/geekattempts/home-1/drive-an-old-laptop-display-from-an-avr
You and me both! Those PLLs were AWESOME you could use them for ALL SORTS OF crazy things.
You can sense capacitance already without any additional IC’s on the Arduino. Switch the pin from a low impedance output state to a high impedance input state, and toggle the internal pull-up. The digital state of the input will jump at a fairly fixed voltage, so just time how long it takes to jump and you have an analog of capacitance. You can also use an external resistor connected to a second pin if the internal pull-up resistance doesn’t work well for you.
True. And it’s often good enough.
But if you want to sense multiple pins, or mutual capacitance sensors, or through thick materials, or with noisy background, or… you’re going to need to step up your game. And for that, some dedicated hardware can help.
All that sensivity becomes meaningless if your end users are just going to buy it on a breakout board and stick that in a breadboard and dangle long piece of wires – parasitics and noise.
The extra timers are good for having different PWMs at different frequencies, not just for running interrupts in your code. The two I2C controllers is what I’m interested in, though there’s only one project of mine where I absolutely need it but don’t also need a more powerful chip.
What? No native Ethernet? B^)
“Just a matter of software”
Pretty sure that software can’t do MLT-3 encoding.
Without heavy use of non-blocking code, FIFOs, and interrupts, there’s no good way to actually take advantage of dual SPI or dual I2C buses on the same chip.
Still good to have if you know how to use them right. Maybe you need to interleave two external 16 bit ADCs for extra sample rates
I wish they started to make chips that can run at full frequency but at 3.3V
Love extra timers, kinda want a 32 bit timer though
well did they add DMA?
For that you need an XMEGA. the MEGA series doesn’t have DMA.
@evad: sadly, no DMA on the ATmegas.
@frank: Yup. But you _should_ be writing non-blocking and buffering anyway. :) And the extra I2C is a bonus, even for slow speed, when the I2C devices’ address space is limited.
Try your chips out at 3.3V. It’s not in spec, but I’ve always been lucky. (Not for production use.)
No interrupt priority ordering means being choosy about what I use interrupts for. The SPI on AVRs can run up to 8 MHz in TX mode, if you got an interrupt for every 8 bit of that kind of speed to pop out of a FIFO (and maybe push into another FIFO if you are reading), you can really slow down the rest of your code.
Does it come in a lead-free version? :)
Lead-free should be standard, I wait for the gluten-free version.
Do you mean “No leads” (QFN) or No Pb? For prototypes I don’t like both of this very much. But I can still use 60/40 solder on No Pb components.
Chemistry pun: Pb = Lead.
+1, funny, well caught
I used the dual i2c on the xmega e5 for a design where one was a master talking to a sensor and the other was a slave listening to the main processor.
The PB doesn’t have the full-swing oscillator and the low power oscillator tops out at 16MHz, so 20 MHz crystals won’t work anymore. That’s a pain
WHERE HAVE YOU BEEN ALL MY LIFE?
As a Microchip user I find this rather amusing.
The last time I talked about Atmel with someone, they were complaining about Microchip because they produce two different chips varying only by a single letter (16F874 and 16F874A), which had different features and were therefore not 100% compatible with each other. Apparently that was just too much for him to handle, and he switched to Atmel. Poor fella, he’s totally screwed now. ;)
Admittedly, Microchip does offer a dizzying array of options. A single core may be offered with dozens of different peripheral sets. So for Atmel to offer a single new option, and this being so unusual as to be HaD article-worthy, is an odd concept to me.
All jest aside, this is good news for Atmel users, and I’m happy for them. Though I hope it doesn’t take too long for these chips to become generally available. A few months ago I read about another Atmel MCU with added features, that a year after announcement, still wasn’t obtainable by hobbyists. I don’t know if that’s typical for Atmel. If someone cares to educate me on that, I’m all ears.
Part numbers are always confusing and require attention. All chips come in many packages, speed grades, etc. Par for the course, and a good lesson to learn on the cheap when you’re making stuff in single-unit quantities.
The chips are generally available. Did you read the article?
I read through the new feature list, should have read one paragraph further I guess. ;) Yep, Findchips shows single quantities available through a couple of sources. Excellent.
Yeah, part numbers from each manufacturer use different rules(or not so much) and it is easy to get confused if you look at somebody else. But let’s face it…. the champions are those who encode like 10 kinds of things in a part number and need a special diagram to understand the meaning. They are precise and exact, but little chance to remember everything.
Multiplexed crossbar on I/O would be better. Better simpler layout design and option to switch functions on pin in real-time (example: RX/TX on one pin)
Definitely. I’ve very much wanted a crossbar matrix on peripheral IO for a long time now. It’s sad to see that so many PIC chips have them, but not a single AVR has. Maybe that’s something Microchip could look into giving us please? :)
Aaaaand still no USB.
So just get one of the other AVR chips that does have USB. It’s not like the selection is small.
Damn. Why does the 168PB does not have those features?
I’m using the 168PB in an industrial application because 16k of flash are enough to do the task. I could’ve used the 328PB. But I thought that they are exactly the same… Damn! Now I regret the decision and 5k units are on their way.
The pinout is ready :)
Beautiful, as usual! I really like the breakout with the cap-sense pins — would get too crowded otherwise.
Looks great! How do you generate the pinout or add one to the website?
Thank you for that! I haven’t the time just now to review it, is it pin compatible with the 328P?
Right – had time after all, it is!
Hey there ATMega328PB!, I’m no good at being noble, but it doesn’t take much to see that the problems of a geek and his microcontrollers don’t amount to a hill of beans in this crazy world. Someday you’ll understand that. Now, now. Here’s looking at you, kid.
“Operating system” without at least two stack pointers and system call/pend?
I know it’s possible but you have to implement it yourself and be very careful.
Hi Elliot, hope you’re still reading the comments here… after some experiments and asking around in forums, it appears that the ATmega328PB does not support full swing crystal oscillators, which means you can’t clock it (reliably) with a 16MHz crystal and a couple of caps as you would an ATmega328P. This is an issue people should be aware of. Feel free to contact me for some more details. Thanks!
I read ’em randomly. :) That sounds like a (horrible) caveat. How do they expect folks to clock the thing? Full-on external oscillators?
Yes, apparently – unless you’re happy with much lower clock frequencies. Actually, the full-swing oscillator support was removed from several other AVRs too – including the ATmega328P-AU, which makes you wonder what will happen to some future Arduinos… see here: http://img.digikey.com/Retractions/WC154601%20-%20PCN-12-23-2015.pdf
Yeah right? Thanks very much for the tip and the datasheet! That alone is worth a story.
Credit for finding this document goes to the great folks at avrfreaks.net. This whole affair almost cost me a client’s project; I was careless enough to go for a brand new chip, but still had the good sense to design below its (assumed) performance limits :-)
Please be kind and respectful to help make the comments section excellent. (Comment Policy)