Problem with TSOP 31238

Discussion in 'General Electronics Chat' started by buzaiandras, Jul 19, 2011.

  1. buzaiandras

    Thread Starter Member

    Jul 18, 2011

    I have a problem with my TSOP31238 38Mhz IR receiver and I can't figure out what is causing it.
    When I press a button on the remote control the TSOP31238 sets the OUT pin to low (this is ok), and this properly generates an interrupt on the PIC16F688 micro-controller (port RA2). The problem is that at random times the TSOP31238 generates random pulses (without me pressing any button on the remote control).
    I tried to isolate the IR receiver (I put it inside a cardboard box) but this only increased a little the time between the random pulses, the pulses did not disappeared.
    I do limit the current to the TSOP by using a 220R resistor in series with the Vs of the TSOP, and I have placed a 4.7uF filtering capacitor between the GND and Vs of the IR receiver (I have also tried with bigger capacitors but the result was the same).

    Also I have tried the circuit also by using the power from the PicKit2 programmer (connected through USB to my PC) and also by using a separate +5V regulated power source. The result was the same. The random pulses were generated by the TSOP without me pressing any button on the remote.

    I have attached my schematics to this post.

    Is there something wrong with my circuit? Or this random pulses are just a result of noise from the environment picked up by the TSOP IR receiver?
    If this is caused by the noise of the environment (my office is in a basement, no wireless connection near by ...etc ... only my PC ) is this normal?

    If so how can I eliminate this noise?

    Thank you,

    • MC.png
      File size:
      19.6 KB
  2. praondevou

    AAC Fanatic!

    Jul 9, 2011
    How long is a random pulse?

    Could it be radiation from a nearby smps?

    Did you detach the receiver from the PIC (deactivate the PIC), put the receiver in the box and measured the output? Are there still random pulses?

    If all fails try to connect it to 3 AAA batteries, turn everything else off, without PIC, in the box and see if it still gives you the random pulses.
  3. buzaiandras

    Thread Starter Member

    Jul 18, 2011
    The "pulses" are very short and they occur at a random time interval.
    I don't have an oscilloscope to measure this more exactly. By pulses I mean that at random time intervals the Vout from the TSOP31238 has a small drop (ex: from 4.5V it drops to 4.0V).
    I measure this using an analog volt-meter connected to GND and Vo of TSOP31238.
    I just stare at the volt-meter and notice the fluctuation.
    When the PIC is connected this fluctuation causes an interrupt.

    The only SMPS nearby is the one from my PC power supply. But I tried the circuit in another room and the same thing happened.

    When the PIC is disabled and the TSOP31238 is in a box, the pulses still occur (at bigger intervals) but the drop in voltage on Vout of TSOP is smaller. It is barely noticeable.

    Is the circuit ok? Or is something wrong with it? Is the behavior of the TSOP31238 normal?

    Thank you,

  4. praondevou

    AAC Fanatic!

    Jul 9, 2011
    I don't think it's normal. Did you try the battery option? I mean a completely isolated circuit. An oscilloscope would be really helpful, though.
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    I think you are saying you see these pulses even when there is no PIC connected, with the TSDP enclosed inside a box? If that is true then that is weird...

    I do see a few things...

    I do not see a bypass cap on the PIC itself. 0.1 uF is typical.

    The TSDP may need a tiny cap too, another 0.1. The larger the cap the lower frequency it works at, so using a large and small cap may help.

    R9 is not needed as the TSDP has an internal pull up, though making the pull up resistor larger makes it easier to drive the output low so maybe leave it there for now.

    I suspect if you had a scope you would be seeing a series of pulses output that have an average of 4V when you see the "small drop" from 4.5 to 4V.

    That said, you should see a solid output when inside the box with no PIC connected. Remove the PIC and the display from +5V and see if that helps. Until you see that output solid no sense in connecting the rest.

    (I hate simple problems like this!)
  6. buzaiandras

    Thread Starter Member

    Jul 18, 2011
    Thank you for your responses.

    Yes, I tried also with batteries.

    I spent some time trying to figure out if the TSOP31238 IR receiver sends out "pulses" even when it is isolated (in the cardboard box and with the PIC removed from the circuit - only the TSOP31238 - tried both with AAA batteries and also with a regulated power supply).
    I know that previously I said that when in isolation the "pulses" still occur and they are barely noticeable but now I think that my eyes played tricks on me.
    Now I am pretty sure that the pulses are not generated when the TSOP31238 IR receiver is isolated. I think that when isolated the output is a solid stable one. Unfortunately until I get an oscilloscope I can't be 100% sure.
    Until I get my hands on an oscilloscope lets assume that the TSOP is working properly (at least it seems so from my observations).

    So what could be causing the PIC to generate an interrupt in this case?

    Yes. I have now added a bypass cap but when the PIC is connected the random pulses still occur.

    Any suggestions?

    Thank you,

  7. praondevou

    AAC Fanatic!

    Jul 9, 2011
    The PIC itself can cause noise on the power supply. Sometimes people put ferrite beads near Vcc (in series with Vcc) to avoid distributing this noise onto the power supply lines.
    But you already have a filter for the Vcc of your TSOP...the RC.

    How far is the PIC away from the TSOP? I mean length of wire/trace from PIC interrupt pin to TSOP?

    Can you post a picture of your layout?
  8. buzaiandras

    Thread Starter Member

    Jul 18, 2011

    The wire length between the PIC and the TSOP 31238 is about 1 inch.
    I have attached a picture with my circuit (on a breadboard).
    I still couldn't find a solution to this :(.

    Thank you,

  9. praondevou

    AAC Fanatic!

    Jul 9, 2011
    Sorry to hear that.
    So it doesn't seem to be a noise problem. I am actually not sure if there should be absolutely no signal at the output. Sure, no datasheet is mentioning them, but in general the signal will be decoded afterwards. So even if there was noise it wouldn't cause any trouble in a commercial device, because the noise wouldn't be decoded and therefore no action would be taken.

    If nobody comes along with a solution I will try to measure the TSOP signal in an old defective DVD player this evening.

    If u are using a common IR remote to trigger your circuit you could leave the TSOP output on the interrupt input of the PIC but you could measure the burst length that comes in.. This way I think you would know if it was noise or a real signal.
    Last edited: Jul 28, 2011
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    AFAIK the TSOP works very hard to keep stray pulses from the output. It has internal filtering and all sorts of good stuff to make it only respond to IR pulses of the proper frequency.

    All I can think of is your TSOP is defective. Radio Shack sells a similar device if you want to try it for comparison.

    Also, you might want to try using your PIC as a scope: light a LED for a short time when the TSOP output changes. Don't do any decoding of the pulses, just an "I saw a change" indication. You can see a LED flash even in an incredibly brief interval as short as 10 mS, though it will look "ON" with a square wave of that period.
  11. gerty

    AAC Fanatic!

    Aug 30, 2007
    Have you checked the junction where r9 (pull up resistor) connects? If it's bad the input could be floating causing what you describe...
  12. debjit625

    Well-Known Member

    Apr 17, 2010

    Using an analog volt-meter you can't measure small voltage drops like that, but lets think for a moment if their is something like that ,then also it can't cause interrupt for the PIC as per I think a difference of (4.5 - 4.0) = 0.5V which will not give you a low logic level. Their must be something other going on, here is what you can try...

    First disconnect everything except the PIC stuffs, then write a program which will not use any interrupt ,only an I/O port to sense a switch (high and low) and output the status using a LED now if it works then just replace the switch with your photo module ,if it doesn’t work then the problem is with your photo module change it with another one, but if it works then you have some problem with your interrupt code.

    Many times when programming for interrupts people forget to clear the interrupt flag after interrupt happens and that makes programs to cause interrupts repeated times. Post your code so we could help.

    If nothing works it means you have problem with your PIC, check the oscillator, reset circuit and your configuration bits, they may also cause the PIC to behave like that.

    Good Luck
  13. praondevou

    AAC Fanatic!

    Jul 9, 2011
    I have to agree with Ernie. I just measured an TSOP output from my DVD-player, no pulses at all, not with ambient light nor near cell phones, nothing.

    So either it's a defective device, bad contact from TSOP to PIC, wrong interrupt handling or some extrem strong noise generating source in your neighborhood (not very likely, though)

    What will you be using as the transmitter? As I said , if it's a common remote control, do some decoding in the PIC and you should be good.
  14. buzaiandras

    Thread Starter Member

    Jul 18, 2011

    Thank you all for your responses.

    Yes, I will use a common remote control and the signal will be decoded in the PIC.
    The problem is that I do not know if this is a normal TSOP 31238 behavior or is there something wrong with my circuit :). If this is normal for the TSOP then it is Ok because the noise will be filtered out when the decoding is performed. But if there is something wrong with the circuit I would like to fix that. Unfortunately I can't figure out what is wrong :(.

    I also tried with several different TSOP31238 modules and several different PICs (16F688) but the behavior was the same :( so I would rule out a defective TSOP or a defective PIC.

    I am attaching the PIC code, maybe there is a problem with the software.
    I am using the internal oscillator of the PIC and I reset the interrupt flag after the interrupt occurs.
    The code is written using HI-TECH PICC.

    Code ( (Unknown Language)):
    2. #include <htc.h>
    3. #include <pic.h>
    4. #define _XTAL_FREQ 4000000
    10. void displayNumber(short nr);
    13. unsigned short cnt = 1;
    14. unsigned short nr = 0;
    17. void main()
    18. {
    19.     // set all pins to digital
    20.     ANSEL = 0b00000000;
    21.     // set direction of all PORTC pins to OUT.
    22.     TRISC = 0b00000000;
    23.     // set RA3/MCLR/VPP and RA2 to IN and the rest to OUT;
    24.     TRISA = 0b00001100;
    25.     // disable comparators
    26.     CMCON0 = 0x07;
    29.     // enable global and RA2 external interrupts;
    30.     INTCON = 0b10010000;    
    32.     // set PORTC and RA4 to 0
    33.     PORTC = 0b00000000;
    34.     PORTA = PORTA & 0b11101111;
    36.     // interrupt on falling edge;
    37.     INTEDG = 0;
    39.     do
    40.     {
    41.             displayNumber(nr);
    42.             __delay_ms(1);
    44.     } while (1);
    46. }
    49. void interrupt isr() {
    51.     if (INTF == 1) {
    52.         __delay_ms(15);
    54.         if (RA2 == 1) {
    55.             // blink the "0" for 5 times when an interrupt occurs on RA2 then
    56.             // increment the number to be displayed on the LED display
    57.             for (int iii=0; iii<5; iii++) {
    58.                 displayNumber(0);
    59.                 __delay_ms(100);
    60.                 // reset PORTC;
    61.                 PORTC = 0b00000000;
    62.                 // reset RA4;
    63.                 PORTA = PORTA & 0b11101111;            
    64.                 __delay_ms(100);
    65.             }
    67.             if (cnt < 10) {
    68.                 nr ++;
    69.             } else {
    70.                 nr = cnt % 10;
    71.             }
    72.             cnt++;
    73.         }
    74.     }
    76.     // reset interrupt flags   
    77.     INTF = 0;
    78.     RAIF = 0;
    79. }
    82. void displayNumber(short nr) {
    84.         // reset before new number is displayed;
    85.         PORTC = 0b00000000;
    86.         // reset RA4;
    87.         PORTA = PORTA & 0b11101111;
    89.         switch (nr) {
    90.             case 0: RC0=1; RC1=1; RC2=1; RC3=1; RC4=1; RC5=1;
    91.                     break;
    93.             case 1: RC1=1; RC2=1;
    94.                     break;
    96.             case 2: RC0=1; RC1=1; RA4=1;  RC4=1; RC3=1;
    97.                     break;
    99.             case 3: RC0=1; RC1=1; RC2=1;  RA4=1; RC3=1;
    100.                     break;
    102.             case 4: RA4=1; RC1=1; RC2=1; RC5=1;
    103.                     break;
    105.             case 5: RC0=1; RA4=1; RC2=1; RC3=1; RC5=1;
    106.                     break;
    108.             case 6: RC0=1; RA4=1; RC2=1; RC3=1; RC4=1; RC5=1;
    109.                     break;
    111.             case 7: RC0=1; RC1=1; RC2=1;
    112.                     break;
    114.             case 8: RC0=1; RC1=1; RC2=1; RC3=1; RC4=1; RC5=1; RA4=1;
    115.                     break;
    117.             case 9: RC0=1; RC1=1; RC2=1;  RA4=1; RC3=1; RC5=1;
    118.                     break;
    119.         }
    120. }

    Thank you all,

  15. praondevou

    AAC Fanatic!

    Jul 9, 2011
  16. buzaiandras

    Thread Starter Member

    Jul 18, 2011

    No problem praondevou :)

    But, I would greatly appreciate if there would be somebody who could look over the code to identify possible software faults that could produce the described behavior.

    Many thanks :),