I have an AVR circuit for which I have connected its clock-out pin some other circuits external clock and the other pins operate various other things. By using an oscilloscope, I have found that the AVR chip (both attiny4313 or atmega8535) will run at a slower speed after its power source has been disconnected and reconnected.
The chips in the circuit in question are connected to a 20mhz resonator to xtal 1 and xtal 2. Here is how I recreate the issue:
1) Connect power and ground.
2) burn fuses for external oscilator with clock out
3) press reset button
4) clockout shows 20 MHz on scope, other circuits run at proper speed.
5) Disconnect battery (from the L7805 regulator)
6) Connect battery back to the circuit
7) main chip is now running at around 8 mhz, no nother circuits are running properly.
8) Reburn fuses
9) Works properly at 20 MHz now.
The issue happens with a attiny4313 and an atmega8535.
EDIT: The image is a test circuit that I am using to try and figure this out. It allows me to reproduce the problem.
why is this happening? How do I prevent it from happening?
Additional notes:
Brown out detection at 4.3 V does not fix the issue.
Programmed with an arduino uno as ISP with avr-gcc (latest ubuntu version)