Software Short Circuit

No danger - no smoke, just a few lines of crazy code.
Well, the ATmega328-INT0 can be programmed to get activated on both rising AND falling levels.
And any output pin can get toggled by writing a "1" to the corresponding input register. What if you feed the output directly to the ISR input? Very simple: it will oscillate. You can watch the pin-13-LED getting only half-bright. The frequency generated by this software short-circuit will be 242.4 kHz on the UNO equivalent to 66 CPU cycles. If you add NOP instructions before the toggle command you get two cycles more for each NOP.
As INT0 has highest priority other interrupts (loop=Timer0) do not affect this frequency.
Is it useful at all? Most probably not - except for studying some internals. And having fun!

[code]
void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  // send output from pin-13 to pin-2 via a short wire
  EICRA = 1; // Any logical change on INT0 generates an interrupt request.
  EIMSK = 1; // Bit 0 – INT0: External Interrupt Request 0 Enable
}

void loop() {}

ISR (INT0_vect) {   // read pin-2:
  PINB = B00100000; // toggle PIN-13:
}
[/code]

It's just positive feedback, not a short-circuit

Hi AWOL,
of course you are right. Only seen from the UNO layout geometry it is a very short wire of just 1.2 inches.
If 66 cycles are not short enough, go to the ISR_NAKED option:

ISR (INT0_vect, ISR_NAKED) {   // read pin-2:
  asm("sbi 3,5 \n\t" // PINB = B00100000; // toggle PIN-13:
      "reti");
}

It will reduce the number of cycles from 66 down to 28. That really is extremely short.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.