Arduino Uno keeps looping on setup() everytime i press a specific remote button

I'm trying to decode my Panasonic tv remote using the IR_RECEIVE sketch below.
When i press the remote's buttons it works fine and i get the values, except from when i press the power button - the setup() function executes.

This is the code:

	/* Raw IR decoder sketch!

	This sketch/program uses the Arduno and a PNA4602 to
	decode IR received. This can be used to make a IR receiver
	(by looking for a particular code)
	or transmitter (by pulsing an IR LED at ~38KHz for the
	durations detected

	Code is public domain, check out www.ladyada.net and adafruit.com
	for more tutorials!
	*/

	#define IRpin_PIN      PIND
	#define IRpin          2
	#define MAXPULSE 65000
	#define RESOLUTION 20 

	uint16_t pulses[100][2];  // pair is high and low pulse 
	uint8_t currentpulse = 0; // index for pulses we're storing

	void setup(void) {
		Serial.begin(9600);
		Serial.println("Ready to decode IR!");
	}

	void loop(void) {
		uint16_t highpulse, lowpulse;  // temporary storage timing
		highpulse = lowpulse = 0; // start out with no pulse length

		while (IRpin_PIN & (1 << IRpin)) {
			highpulse++;
			delayMicroseconds(RESOLUTION);

			if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
				printpulses();
				currentpulse = 0;
				return;
			}
		}
		pulses[currentpulse][0] = highpulse;

		while (!(IRpin_PIN & _BV(IRpin))) {
			lowpulse++;
			delayMicroseconds(RESOLUTION);
			if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
				printpulses();
				currentpulse = 0;
				return;
			}
		}
		pulses[currentpulse][1] = lowpulse;

		currentpulse++;
	}

void printpulses(void) {
        Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
	for (uint8_t i = 0; i < currentpulse; i++) {
		Serial.print("delayMicroseconds(");
		Serial.print(pulses[i][0]*RESOLUTION, DEC);
		Serial.println(");");
		Serial.print("pulseIR(");
		Serial.print(pulses[i][1]*RESOLUTION, DEC);
		Serial.println(");");
	}
}

This is the output:

> Ready to decode IR!    
> 
> 
> 
> Received:     
> 
> OFF 	ON    
> delayMicroseconds(34724);        
> pulseIR(3600);    
> delayMicroseconds(1800);    
> ......  
> delayMicroseconds(1340);    
> pulseIR(460);    
> delayMicroseconds(1360);    
> pulseIR(460);    
> Ready to decode IR!    
> Ready to decode IR!

The last 2 rows appeared when i pressed the power button (twice).
The rows above appears when i press any other button.

I played around with the Arduino and the remote, i might have done something to cause this. The first time i tried it - it worked fine.

I tried resetting and re-uploading.

Sorry if the post is too long or not informative enough- i'm new to this and not really sure what kind of information to provide.

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Two things come to mind...

  1. currentpulse is unbounded.

  2. Short-circuit.

You could be writing beyond the bounds of the pulses array and contaminating memory that you do not "own". Unexpected resets like you describe are often caused by writing past the end of an array. Put in some Serial prints to monitor the value of the array index to see what is happening.

Why are you passing “VOID” parameter to each function call?
Probably not the issue, just startled me.

Agree, usually a corrupting variable would lock up a computer, yours might just be in the perfect spot to reboot it as your output seems like it’s actually rebooting not running the loop directly..

Slumpert:
Why are you passing “VOID” parameter to each function call?
Probably not the issue, just startled me.

You must be easily startled.

It is getting close to Halloween.

groundFungus:
You could be writing beyond the bounds of the pulses array and contaminating memory that you do not "own". Unexpected resets like you describe are often caused by writing past the end of an array. Put in some Serial prints to monitor the value of the array index to see what is happening.

It appears so.

But i still don't get- what could've caused this? Previousely it all worked as expected using the same code.
What went wrong?

The only event that occured between the time it still worked and now -
The Arduino was connected to both DC power and the computer withing USB. At some point the OS didn't recognize the USB anymore so i restarted my PC. As the Arduino still wasn't recognized i tried to unplug the power which indeed solved the issue.

Next thing i did was executing this code, just as i did many times before. (but this reset suddenly happened).
Does the above event have anything to do with it?

What sort of Arduino are you using? An Uno?

This would be a good time to post a schematic. Photograph of a pencil / pen + paper drawing is readily accepted.