Hi folks,
I'm trying to develop (and understand) my own interrupt based IR decoder (please excuse my worse english ).
What I've done so far:
- connected a TSOP4838 to digital pin 11 on my arduino UNO.
- enabled pin change interrupt for PCINT7..0
- set pin change interrupt mask to enable for digital pin 11 (PCINT3)
What is working:
- when I press a key on my RC I get the recorded counter values
I don't know how to write code to measure the exact low an high value durations in the ISR :~
So here is my code:
volatile uint8_t irPin = 11;
volatile uint8_t irqFlag = 0;
volatile unsigned long lowDuration;
volatile unsigned long highDuration;
volatile unsigned long totalDuration;
void setup() {
 pinMode(irPin, INPUT);   // Set Arduino pin 11 (PCINT3/PORTB3) as input
 digitalWrite(irPin, HIGH); // Set pull-up resistor
Â
 PCICR |= _BV(PCIE0);  // Enable Pin Chane Interrupt 0 for PCINT7..0
 PCMSK0 |= _BV(PCINT3);  // Enable Pin Change Interrupt for digital pin 11 (PCINT3)
Â
 Serial.begin(115200);
 Serial.println ("Waiting for interrupts..");
 interrupts();
}
void loop() {
 if (irqFlag == 1) {
  Serial.println("Interrupt detected!");
  //Serial.println(PINB & _BV(PINB3), BIN);
  Serial.print(highDuration); Serial.print("-"); Serial.println(lowDuration);
  Serial.println(totalDuration);
  irqFlag = 0;
 }
}
ISR(PCINT0_vect) {
 noInterrupts();  // Disable all interrupts
 uint16_t lowCounter;
 uint16_t highCounter;
Â
 while ((PINB & _BV(PINB3)) == 0) {
  lowCounter++;
 }
Â
 while ((PINB & _BV(PINB3)) == 1) {
  highCounter++;
 }
Â
 while ((PINB & _BV(PINB3)) == 0) {
  lowCounter++;
 }
Â
 lowDuration=lowCounter;
 highDuration=highCounter;
 totalDuration=lowCounter + highCounter;
Â
 irqFlag = 1;   // Set interrupt flag to notify loop()
 interrupts();   // Enable all interrupts
}