ATMEGA328P-PU running excepionally slow on breadboard

I am tearing my hair out, as I cannot figure out what is going on here.
I designed a circuit for a project and decided to test it on a breadboard prior to getting a custom PCB made.
After assembling the components on the breadboard I was unable to upload a sketch, either by using a FTDI USB device or using a Arduino Uno with the ATMEGA328 removed.

To eliminate the possibility that this was due to my circuit, I built a very basic circuit on the breadboard, but the end result was the same.

The basic circuit consists of the following:

  • ATMEGA328P-PU
  • Pins 9 and 10 connected to 16M crystal with 2 x 22nF ceramic capacitors connected to ground
  • Pin 1 connected to 10K resistor then to +5V
  • Pin 1 connected to NO switch and then to ground
  • Pins 7, 20 and 21 connected to +5V (tested with and without VREF connection)
  • Pins 8 and 22 connected to ground
  • 10uF capacitor connected between pins 20 and 22
  • External +5V regulated power supply

After many failed attempts to upload a sketch to the above setup I decided to take another approach...

I loaded the blink example onto a working Arduino Uno, after modified the timing to have the LED turn on and off every 100 microseconds.
That works exactly as you would expect.
I then removed the ATMEGA328P-PU chip and placed onto the breadboard setup described above.

The LED does blink, but it would appear to do so about 500 times slower than it should, that being once every 5 seconds.
(5 seconds on, 5 seconds off)

I have reflashed the bootloader (more than once), but that made no difference.

What I cannot understand is why the blink sketch works perfectly when the chip is in the Arduino Uno, but when located on the breadboard it does not.

Nothing that I have found on the internet suggests that a different fuse configuration is required to build a custom setup.

So, my question...
What the hell is going on here and how do I fix this problem?

I have very limited electronics knowledge, so please respond accordingly.
Thanks.

Show us a good schematic of your circuit.

Show us a good image of your ‘actual’ wiring.

Posting images:


Make sure you have 100nF decoupling capacitors on the breadboard.

5 / 100 microseconds = 50,000 not 500.

One possibility is that your 16MHz crystal isn’t what you think it is and yes, you absolutely need 100nf bypass caps.

Why would you reflash something that works in the original board? The processor isn’t the issue, it’s your breadboard.

Do you have a voltmeter? A scope?

Why would I reflash the chip? Because I was running out of ideas as to why this was happening; no other reason.

I had the same thought about the crystal, so I desoldered one out of a spare, working Arduino I had and tried that as well. No change.

No scope, but I have checked all of the connections with a multimeter. As far as I can tell, it is all as it should be.


22nF caps?

No, that's not right. 22pF is closer to correct (that would be a factor of 1000 less capacitance than 22nF), but even then, there's so much stray capacitance on breadboard that I would aim for less than the nominal amount of capacitance the crystal calls for. Some people report it working on some breadboards without the loading caps at all!

Out of curiosity, what happens if you put it on breadboard without the crystal there at all? It should do nothing - if that's not the case, something very strange is going on....

Hmmmmmmmm...

I cannot remember which website I got my original schematic off, but apparently that sent me down a path which was not ideal.
Tomorrow I will buy some 22pF capacitors and see how I go with those.

Thanks for the pick-up. Hopefully that is the problem.
I will report back...

have the LED turn on and off every 100 microseconds.
That works exactly as you would expect.

Did you check it with a scope? Your eye can't see individual blinks at that rate.

ATmega chips are shipped with the fuses set for the 8MHz internal oscillator and divide by 8, so the clock rate is 1 MHz. The crystal is irrelevant unless you changed the fuses.

I am using an ATMEGA328P-PU, which ships with the Arduino bootloader preinstalled.

Okay...
Replacing the 22nF capacitors with 22pF capacitors seems to have resolved my speed issues, so thanks again for that pickup. :slight_smile:

Just confirms that you cannot believe everything to read on the internet.

Well, color me stunned that the it oscilated at all with 22nF caps!

Well, color me stunned that the it oscilated at all with 22nF caps!

Agreed. I have trouble believing it.

People have made the same mistake, and discussed it on this forum. The symptom was no oscillation at all.

I also use PU units and sometimes find that they are slow. I always use the IDE to load another bootloader and that always cures the problem