Ensuring full discharge of IC before next boot sequence

I’ve prototyped and tested the attached circuit and it’s code. Really straight forward: play notes and power LEDs in a sequence to emulate a song when the circuit closes, then wait for the accelerometer to output a large enough variance indicating that it’s being shaken which then starts the song again.

The problem is that if you switch the circuit on-off-on within a second or so in-between the off-on sequence, a few notes are incorrect and play as if something in memory is now corrupted. Turning it off and waiting more than 5 seconds and the toy returns to nominal operation. I understand that there is still enough charge in the capacitors to not allow memory to fully be released, but what is the proper way to avoid this kind of issue?

I’ve played with the idea of using transistors to solve this problem, but just can figure it out. How would one design a circuit that prevents the main circuit from closing again until the IC is fully discharged?

Is BOD enabled? Try enabling it (via fuses) if not - that's what it's there for (preventing erratic behavior in undervoltage situations)

I'm thinking that if internal software initialisation of values doesn't work, then perhaps a monostable timer circuit that controls a power route to the arduino could be used. If some logic circuit senses that the power switch has been flicked to 'off', then turning the switch 'on' again will require 'X' seconds to pass before re-enabling the power route.

But, naturally, it's best if the system is able to start working as soon as possible after flicking the power switch to on. The less delay the better. So maybe better to see if something can be done in software to re-initialise values, in order to prevent the glitch.

You draw it as a stand alone AVR so indeed have a look at the fuses. Indeed BOD should fix it.

And btw, How do you drive the speaker? Half sine wave? I would add a capacitor in series with the speaker to remove DC off set.

Sounds like a peefect app for a ATtiny85.

BOD ?

BROWN OUT DETECTOR ?

Can you add a cap to increase the discharge delay ?

FYI, It's not a good idea to leave the RESET pin floating like that. It should have a 10k pullup and a 1uF cap to GND. That's standard. Usually there's a push button to short it to GND but that's OPTIONAL. You can put a large electrolytic on the Vcc pin to GND and that will add some delay.