LPC11U24 and IR

12 Nov 2012

Just got my first mbed lpc11U24 a couple of days ago.

I am trying to get some IR to USB functionality working. Using mbed's RemoteIP class, this was easily put together. I connected a TSOP2238 to 5v,GND and pin 21 and the a key press on my NEC remote spits out the keycode via USB (pc.printf).

Sadly, once in a while the keycode is not recognized properly. So I build the test code. (see below). Every time an edge is detected, it sets pin23 respectively.

Hooking up a logic analyzer to pin 21 (B0) and pin 23 {B1), I was surprised to see that indeed my code is missing an edge once in a while.

I assume a LPC11U24 is fast enough for detecting edges ~ 1ms. So what is going wrong?

I limited the code in the ISR as much as possible. But no change.

Your input is appreciated.

Mat

---------

 #include "mbed.h"

DigitalOut myledA(LED1);
DigitalOut myledB(LED2);
DigitalOut myledC(LED3);
DigitalOut myledD(LED4);

DigitalOut bitbang(p23);
InterruptIn evt(p21);

void isr_ledc()
{
   myledC = !myledC;
   bitbang = 1;
}
void isr_down()
{
   bitbang = 0;
}

int main() {

   evt.rise(isr_ledc);
   evt.fall(isr_down);

   while(1) {
        myledA = 1;
        wait(0.2);
        myledA = 0;
        wait(0.2);
    }
}
12 Nov 2012

/media/uploads/mattes/_scaled_2012-11-12_15-54-56.jpg

13 Nov 2012

As far as i know, the mbed library classes for DigitalIn and InterruptIn by default use the input mode "PullDown". You can set the input mode to evt.mode(PullUp) or evt.mode(PullNone) at start of your main(). Since the TSOP2238 already has a Pullup-resistor at the output, PullNone should be appropriate, but PullUp will work too. Only PullDown (default) will probably interfere with the output of the TSOP and might explain the intermittent erratic behaviour you are seeing.

Best regards
Neni

13 Nov 2012

Thanks for the input Nenad. I tried both pullup and pullnone, but it did not make difference. ;-(

I changed the code of the main, reading the state of pin21 inside the while loop as a control. The result is surprising. the while loop actually detects the IR edge properly.

  • B0 is input pin21 ir signal
  • B1 is output pin23 set by InteruptIn rise and fall
  • B2 is output pin24 while loop

/media/uploads/mattes/_scaled_img095crop.jpg

As you can see B1 stays zero, while B0 rises.

Is there something wrong with InteruptIn?

#include "mbed.h"

DigitalOut bitbang(p23);
DigitalOut bitbang2(p24);
InterruptIn evt(p21);
DigitalIn necir(p21);

void isr_ledc()
{
   bitbang = 1;
}

void isr_down()
{
   bitbang = 0;
}

int main() {
   evt.mode(PullNone);
   evt.rise(isr_ledc);
   evt.fall(isr_down);

   while(1) {
      if ( necir.read() )
         bitbang2 = 1;
      else
         bitbang2 = 0;
   }
}