Electronic – AVR (attiny24) resets itself driving more than 5 outputs under no load

avr

I have the blink code below running on an attiny24 with the default fuses, via Atmel Studio 6. If I set DDRA to any combination of 5 pins (or set DDRA to 0xFF and then blink by setting PORTA to any combination of 5 pins) then it works but as soon as I use 6 pins it resets itself. The PORTB.0 toggle at start up demonstrates the reset.

The usual cause for this sort of behaviour is sourcing or sinking too much current on the outputs, however this is happening when the outputs are left open, nothing attached, so I can't see what's causing it. Any suggestions?

int main(void)
{
  // DEBUG: Toggle PORTB.0 to demonstrate AVR reset.
  DDRB = 0x01; PORTB ^= 0x01; _delay_ms(10); PORTB ^= 0x01;

  // Output 6 pins at once (change to 5 pins and AVR does not reset).
  DDRA = 0b00111111;
  for (;;)
  {
    PORTA = 0xff;
    _delay_ms(1000);
    PORTA = 0x00;
    _delay_ms(1000);
  }
}

I've tried the usual suspects, power supply, running with AVRISP disconnected and ensuring there is a cap between +VE and GND. Also tried setting pins individually and as soon as it hits 6 it resets.

Schematic - note LED is just for debugging

Best Answer

The problem is that there is a spike when turning on all the pins, even though they are not loaded, and this sapped enough power to cause a brown out.

The Atmel design notes specify the cap should be as close to the pins as possible and it worked when I put a 100nF cap directly on the chip's VCC and GND on the breadboard. There wasn't a huge gap between the chip and my power rails, just over an inch, so this shows how important it is place the cap correctly.

I've used a lot of AVRs and this one seems particularly unforgiving in this aspect, especially as the outputs were not drawing any current externally.