Problem description
I've got occasional startup issues on some boards with an ATmega2561. On about 10% (seems to fluctuate a lot) the processor does not seem to start on first power on. Only a power cycle lets the MCU start.
I've researched online and tried different things. I made several hypothesis and tested them but I have been able to disprove all of them.
I've checked the datasheet several times but could not find any clue as to what I could be doing wrong.
Reproducing
The Problem shows itself in the following way:
- Switch on power
- Sosftware won't start (no communication on UART no LED-blink, both of which should happen when the software runs.)
- Switch power off and wait 10s
- Switch on again
- Microcontoller starts
If I switch off the power for >3 minutes the problem appears again. If a board has the problem it's perfectly reproducible. Replacing the microcontroller solves the problem.
I've also checked the power. The microcontroller runs at 5V. The 5V switches on within a few microseconds and is rock solid stable (checked with an oscilloscope and multimeter in Min/Max-Setting.)
Also: I can program the microcontroller via ISP if it is in that hung state.
Hypothesis
Hypothesis 1
External ceramic resonator does not start because of wrong fuse settings
I could disprove that by measuring the frequency with an oscilloscope and by setting the microcontroller to use the internal R/C oscillator (which should start.)
Hypothesis 2
Something with the external reset circuit
Reset/ is high and stable 200ms after power on (that's the time the external reset is pulled low).
Hypothesis 3
The MCU is in some undefined state for some unknown reason after startup
Pulling reset low for any amount of time did not get the microcontroller started.
It seems I'm out of ideas. What's more: This board has a bootloader which I use to load an application. If there is a valid application the bootloader immediately starts the app in its first line of code. The problem exists independently of state. It does not start into bootloader or application. If it's not a hardware issue it must be software, but the only thing common between application and bootloader is basically one line of C-code (that calls a few functions to read from EEPROM and FLASH to check if a valid application is installed.)
Does anyone have an idea on how to tackle this problem? Could it be a software issue? Why does it not happen on all the microcontrollers?
Update:
As suggested in the comments I've measured AVcc in relation to Vcc during power on.
Channel 1 (yellow) is Vcc, Cannel 2 (cyan) is Aref
That seems to be the problem. Aref (and also AVcc) is rising much faster than Vcc.
SOLVED! (at least it seems)
Adding a resistor in front of the LM7805 that creates the Aref and AVcc to limit the current (and therefore charge the capacitors slower) brought the AVcc on after Vcc and now a board that had the problem boots normally.
AVcc (yellow) and Aref (cyan)