AtMega328PB Blink Sketch

Hi all,

I uploaded the blink example to a project that uses an AtMega328PB with a 16MHz external crystal and two 22pF capacitors. The blink example, as we know, is supposed to blink an LED every second. When I upload the blink sketch to the AtMega, it blinks on and off ebout every 16-17 seconds. Is the chip not keeping time because of my crystal or is it another problem?

Here is a link to the datasheet for the crystal I am using: http://www.txccorp.com/download/products/quartz_crystals/2015TXC_7A_28.pdf

to a project that uses an AtMega328PB with a 16MHz external crystal and two 22pF capacitors

What has the rest of the project got in the way of decoupling capacitors and power supply?
Lack of adequate decoupling can cause oscillations on the supply which can basically screw up the clock.

That sounds like it is running at 1MHz due to fuse settings.
Which core are you using and how did you burn the bootloader . ?

6v6gt:
That sounds like it is running at 1MHz due to fuse settings.
Which core are you using and how did you burn the bootloader . ?

I am not using a bootloader at all, just burning sketches directly to the Atmel chip. I am also using MiniCore.

Josephm3502:
I am not using a bootloader at all, just burning sketches directly to the Atmel chip. I am also using MiniCore.

Did you use the Tools>Burn Bootloader option to set the fuses correctly?

Grumpy_Mike:
What has the rest of the project got in the way of decoupling capacitors and power supply?
Lack of adequate decoupling can cause oscillations on the supply which can basically screw up the clock.

I am wondering if it is because I am using a 3.7v lipoly (little over 4.2 when fully charged) battery to power it.

Ok. So you are using the chip with the factory fuse settings (clock divider, internal oscillator etc.).
You need to either use a avrdude to change these to match the core or do the following in the IDE:

  1. Burn a bootloader. The burning process sets the fuses for Arduino environment as a side effect.
  2. Reload your blink sketch as you did before.

As an exercise, look in the data sheet for the MCU to see what the factory fuse settings are.

You will have to reduce the speed to no more than 13 MHz to be able to run in spec at 3.2V - the minimum for that type of battery. A 12 MHz crystal would do fine for this. 16 MHz may or may not work when the battery reaches end of life, minimum specification for 16 MHz is 3.78V.