I have some several custom PCB's based on Atmega 2560. I am using AVRISP MarkII for flashing. No bootloader.

Flashing is flawless, it just works. I have one assembled PCB works as it should be, no issues.

But, the other one has a quite time lag in its functions. It has also been flashed OK but, it is not running quite OK.

Here are my observations;

By asserting Reset, I expect four leds on the pcb running (on and then off) by 100ms intervals one after each others. This is happening in the very beginning in Setup() section of the program.

Note that: Leds are connected to MCU via mosfets. If MCU output is LOW, they are ON and vice versa.

So, with this problematic PCB, all leds come ON all together after 10 seconds after pressing reset button and they stay almost 60 seconds before they start the sequence (on and then off) as coded.

And then that sequence is also slowly occurring. It is not 100ms as I coded but almost 4 seconds or so.

I am suspecting from the external clock (16Mhz) circuitry but I can't proof it accurately as I don't have oscilloscope at hand.

You may see the simple code I use to test that behavior;

void TestLeds() {
    unsigned long interval = 100;

    digitalWrite(LED1_PIN, LOW);
    digitalWrite(LED1_PIN, HIGH);

    digitalWrite(LED2_PIN, LOW);
    digitalWrite(LED2_PIN, HIGH);

    digitalWrite(LED3_PIN, LOW);
    digitalWrite(LED3_PIN, HIGH);

    digitalWrite(LED4_PIN, LOW);
    digitalWrite(LED4_PIN, HIGH);

How/where should I check the bottle-neck on that?

Thank you.


To be more specific, I add this output regarding programming; here

  • Measure voltage and current. Mar 28 '17 at 15:47
  • 4
    Did you change the fuses? By default most AVR run at 1MHz from the factory. So that would mean your code runs 16 times as slow.
    – Gerben
    Mar 28 '17 at 19:00
  • @Gerben <pedantic> You mean a sixteenth of the speed, not sixteen times as slow. Sixteen times as slow as what? </pedantic>
    – Majenko
    Mar 28 '17 at 21:20
  • I am just using same setup (fuses) as I used for the other PCB. But, how about this: if the external oscillator (16Mhz) doesn't work for some reason although the flashing has just worked fine, could there be something happened about the fuses e.g. automatically adjusted itself or so and started to work at 1Mhz instead?
    – Sener
    Mar 28 '17 at 21:28
  • 1
    Fuses don't reset themselves. There also no failover in case the crystal isn't working. You could try reading the fuses to verify that they are set correctly.
    – Gerben
    Mar 29 '17 at 7:44

I am closing the case. It is not 100% satisfaction though. Because, using Visual Studio with Visual Micro didn't help me on that issue in a natural way but something else.

For the future reference for somebody might get benefit out of this, I like to explain here what I did to get over this issue briefly. As @Gerben (big credits go to him) has pointed the right direction, I did check fuses by installing Atmel Studio 7 and use its programmer.

Yes, the fuses were completely wrong. I have therefore read the fuses from my healthy PCB and noted aside and then applied these very same fuse settings to the slow working PCB. I have just programmed the fuses, Firmware was the one I programmed earlier in the uC. So, voilà, the slowness has gone.

I think I am going to use Atmel Studio 7 now on next to Visual Studio as it has everything built-in including Arduino support.

Thanks everybody involved.


Just burn the bootloader via arduino ide before you burn your firmware. During bootloader burning, ide also configures the fuse bits you needed.

  • 1
    That's what I do. Then Upload Using Programmer to load without having the bootloader called.
    – CrossRoads
    Oct 29 '19 at 17:39
  • 1
    I must agree with you guys. I do it at home with my hobby projects. The way I choose as stated in my solution has been already liked by the field engineers of ours. I can't ask them to use Arduino IDE to deploy new firmware versions. They used to use Atmel Studio flasher. Thanks anyway.
    – Sener
    Oct 30 '19 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.