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.

Thanks [Peter van der Walt] for the tip!

114 thoughts on “Bye-bye ATmega328P, Hello 328PB!

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

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

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

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

          Thanks!

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

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

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

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

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

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

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

            Arduino/Genduino Zero
            https://www.arduino.cc/en/Main/ArduinoBoardZero $49
            https://www.adafruit.com/products/2417

            Sparkfun
            SAM D21 mini $20! https://www.sparkfun.com/products/13664
            SAM D21 breakout $25! https://www.sparkfun.com/products/13672

            Andreas

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

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

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

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

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

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

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

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

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

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

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

  2. 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.
    http://www.atmel.com/tools/ATMELAVRTOOLCHAINFORLINUX.aspx

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.