Bye-bye ATmega328P, Hello 328PB!

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.

Post navigation

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.

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.

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

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?

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.

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.

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).

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

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 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.

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 …

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…

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).

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.

“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).

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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? :)

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.

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.

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!

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 :-)