Electronic – When power is lost on an AVR chip (4313 and 8535) why does the mcu run slower


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.

Test circuit that reproduces the problem

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)

Best Answer

That thing you call a reset button isn't.

Switch bounce will likely be issuing multiple resets to your MCU milliseconds apart and possibly of microsecond duration, and possibly spending time in indeterminate logic states. You should check the datasheet for needed reset timings. My hunch is this spurious multiple out-of-spec reset pulses is putting the MCU into an undefined state - and apparently not operating per its fuse configuration, and instead running off its internal 8MHz oscillator*.

Standard practise is to at least have a cap to ground, at least 100n, but more likely 1uF..10uF depending on the reset timing specs and, more importantly, the bounce characteristics of the switch, which normally have to be estimated empirically (i.e. watch what RESET is doing with on an oscilloscope). Putting the switch/pull-up/cap through a schmigger can help a lot too. But normally a proper reset controller chip is used to deal with the reality of switch bounce in imperfect mechanical switches.

  • This is in the same realm of the fuzzing of power rails and other critical signals - like RESET - used by hardware hackers to put the MCU into certain states, for example to read out code, when that read-out functionality should not be possible due to fuse config.