0

I'm trying to decode my Panasonic television remote using the IR_RECEIVE sketch below.

When I press the remote's buttons it works fine and Iget 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.

Michel Keijzers
13k7 gold badges41 silver badges58 bronze badges
asked Oct 20, 2018 at 19:19
2
  • 2
    the chip resets on some error Commented Oct 20, 2018 at 20:41
  • 2
    try larger array uint16_t pulses[150][2]; Commented Oct 21, 2018 at 5:45

1 Answer 1

1

How high can currentpulse get before it is reset to zero? It is used an array index and if it gets larger than the (number of array elements-1), your code will write outside of the array.

Can the array be so far over-written that it grows into the stack area? That could definitely cause a reset, or reset-like behavior.

answered Oct 21, 2018 at 12:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.