First of all, we need to see your schematic. This will make it way easier for us to troubleshoot. I use Altium Designer at work, so I'd like to look at your layout if you mind sharing the project files (a zip file would be great).
Second, Don't expect the external oscillator to work as well on the 328PB as it does on the 328P. 328PB doesn't support a full swing option, and is way more sensitive to poor PCB layout.
I've designed a development board I use for testing MiniCore compatible microcontrollers in TQFP32 and QFN32 packages. I can confirm that MiniCore works if the hardware is right. I'm sure others also have used MiniCore for their 328PB hardware at 16 MHz.
Third, how are you even able to set fuses/burn bootloader with that board? According to the PCB layout picture you posted pin 16 and 17 isn't connected to anything.
If you have an oscilloscope you should try to probe the XTAL1 pin to see if the oscillator is oscillating like it should. You can also try replacing the crystal capacitors to 22pF. Atleast my 328PB devboard is running fine at 16 MHz with 22pF caps, even though the crystal is located about 4cm away from the MCU. However this value heavily depends on the properties of the crystal.
Which crystal are you using? If it is something like a CX5032GB16000H0PESZZ then I think that seems good.
I try to have ground under and around the crystal traces, so there is plenty of improvements that can be made.
Also, the C6 and C7 bypass are too far away and right next to each other so... I guess I need to explain what the bypass capacitor does.
Everywhere the power supply traces run act like an antenna resonate structure, they tend to be resonant at specific frequencies. There are analogies to bridge building. The Tacoma Narrows Bridge collapse was what they use to show in physics classes. To work properly the bypass capacitor needs to be placed at the ends of the power distribution traces, and scattered along the trace (e.g. at each IC is good). To keep a bridge from resonating we might add weights to the tension cable to shift its resonant frequency (though I'm not a bridge designer).
The bridge still falls apart, unfortunately. The disturbances happening at individual bypass elements don't dissipate and can build up. In electronics, the disturbances cause current to flow and that can induce current eddies in ground planes which is dissipative.
Bypass capacitors are useless next to each other. Space them out and make sure there are ground planes so the currents between them can magnetically couple.
@hansibull: that crystal run? what are you thinking, was that to prove a point?
@hansibull: that crystal run? what are you thinking, was that to prove a point?
It was a big design mistake I did before I knew the 328PB lack the following option. However it did infact work on the 48PB, 88PB and 328PB (all bough from Digikey). This design is no problem if the MCU supports full swing, but in this case it's very risky indeed.
Everywhere the power supply traces run act like an antenna, they tend to be resonant at specific frequencies. There are analogies to bridge building. The Tacoma Narrows Bridge collapse was what they use to show in physics classes. To work properly the bypass capacitor needs to be placed at the ends of the power distribution traces, and scattered along the trace (e.g. at each IC is good). To keep a bridge from resonating we might add weights to the tension cable to shift its resonant frequency (though I'm not a bridge designer).
First of all, I'm not trying to defend bad design practices at all. I'm a big fan of doing things "properly". However the AVR microcontroller is very tolerant to really poor designs. I've seen a commercial product where an ATmega328P in a DIP package was soldered on a circuit board without any bypass caps at all! It's just terrible indeed, but it did in fact work.
When designing less advanced PCBs at work I usually stick with the ATmega324P in TQFP44 package. I use a total of four 100nF caps, one located on each side. I make sure the ground return path is short, and that the external oscillator is placed as close to the MCU as possible.
Last winter we tested some of the boards I've designed at a norwegian certification organ (much like UL and Intertek). In the test chamber they radiated radio waves from 30 MHz to 6 GHz with a peak power of about 150W or so. None of the microcontrollers failed during the test, even though some of the boards were two layer design without metal shielding.
What I'm trying to say is that even though one should take the laws of physics into account when designing a PCB this is just a slow 8-bit micro, not a sub gigahertz 1152 pin FPGA with ten different power rails.
The AVR is very forgiving. I was not going for a point about RF or high frequency it was more about the power supply itself. The resonant frequency of the power distribution traces can cause problems in the range we are working with. So I think the bypass needs to be done moderately correctly to keep the power supply clean.
Update: I had not considered the option of placing the crystal a little farther away so there is room for bypassing near the MCU. The more I look at it I think that is an important thing to know is an option.
Thank you all for the advice. According to Ron and Hansibull, 328PB is much more sensitive about its circuit board condition. So, I did several tests to see how sensitive our 328PB can be and here are the results.
There are 3 questions in my head. Is it the problem of the chip? Is it the problem of the oscillator? Is it the problem of the bootloader?
First of all, I finally got 328PB work on a clone Promini chip but I am not really happy about it because I found the chip is much sensitive to the board condition than it should be. I replaced the CSTCE16M0V53-RO 16M 16MHZ 3212 with CX5032GB16000H0PESZZ 22pf/20pf/12pf. And all of them can work only when I soldered them closely to the chip. Once I tried to break them out from the board with wires, they can't work anymore.
Secondly, I tested 328PB with TQFN package and TQFP package. What I found is that the TQFN package 328PB is much more sensitive than TQFP. The chip is working with CX5032GB16000H0PESZZ 20pf but not 22pf or 12pf capacitors.
Last, I tried with different bootloaders Minicore/Watterott. Luckily, they are working properly as they should be.
It's not a problem, it s "feature". The full swing oscillator option (which the 328P has) was removed in favor to a low power mode instead. Everyone thinks this was a stupid choice. However sensitivity may vary between chip batches. As you can see on my board, the chip I got isn't as sensitive as yours. However I designed a similar board for the ATmega324PB, and external oscillator DID NOT work at all.
Is it the problem of the oscillator?
Probably not. However different oscillators have different characteristics. Some are easy to drive, some are not. What you may use instead is an oscillator with a clock output (this usually has four pins). Connect this to the XTAL1 pin only.
Is it the problem of the bootloader?
No. The bootloader is just the program running on the chip, and makes it possible to receive new program data over the UART interface. However the bootloader (or any other timing sensitive program) will not function properly is the clock source isn't reliable.
There should not be any differences between TQFP and QFN packages. It's the same silicon die, just a different package. However it may be because it's from a different batch.
I replaced the CSTCE16M0V53-RO 16M 16MHZ 3212 with CX5032GB16000H0PESZZ 22pf/20pf/12pf. And all of them can work only when I soldered them closely to the chip. Once I tried to break them out from the board with wires, they can't work anymore.
Thanks for sharing your work.
One thing to note is that on Hans board the crystal is surrounded by the ground plane. My guess is that should help to prevent any nearby RF from perturbing the oscillations (a sort of RF shielding). It probably adds to the crystal load capacitor, but I don't know how much. I would also guess the low power oscillations are probably easier to mess up with any nearby RF or coupled signals (e.g. crosstalk and such).
Maybe Microchip thinks the clock output oscillators are the future. I was looking at one a while back but it would need a level shift so I put it to the side.
FWIW, the standard ATmega328p Arduino Fuse settings use the "Low Power" oscillator, and other chips (notably ATmega1284p) are "known" to be unreliable without the full-swing oscillator.
So whether a given crystal or resonator "works" with the LP Oscillator on the 328pb may be dependent on "details" that are not currently well known or documented.
There are several ATmega328pb boards being sold that seem to work at 16MHz (Pololu, Elektor), and there have been reports of some Arduino Nano boards from China that seem to have an ATmega328PB chip (theoretically, the 328pb is cheaper than the 328p), and work fine.