Shop OBEX P1 Docs P2 Docs Learn Events
trouble with 38kHz receiver module... — Parallax Forums

trouble with 38kHz receiver module...

WhelzornWhelzorn Posts: 256
edited 2004-10-21 22:26 in BASIC Stamp
Ok, I have finally got all of my BS2 OEM modules up and running fine, and I have some of these 38kHz recievers. These things are amazingly dificult to use (for me at least). I have one of the BS2's modulate the frequency to 38kHz, and the other recieve it. heres the EXTREMELY SIMPLE code:

transmitter:
'{$STAMP BS2}
'{$PBASIC 2.5}
  DO
  FREQOUT 3, 1, 38000
  LOOP




receiver:
'{$STAMP BS2}
'{$PBASIC 2.5}

IR_detect  VAR  Bit

 DO
  IR_detect = IN6
  IF IR_detect = 0 THEN
    HIGH 14

  ELSE
    LOW 14
    ENDIF

LOOP




now it seems foolproof, but the LED attached to P14 flashes at a pretty random frequency. If debug "received" is put where the HIGH 14 is, and debug "nothing" is put where the LOW 14 is, then it returns about a 30% - 70% duty cycle for the receiver. I have no idea what to do to fix this, so I come to you all knowing people for the answer wink.gif

thanks people
-Justin

Comments

  • JonathanJonathan Posts: 1,023
    edited 2004-10-20 18:25
    Justin,

    The BS2 can't produce the 38kHz carrier AND modulate the output. Simply sending a steady 38kHz signal will not trigger most IR reciever modules. Try waving your hand in front of the transmitter. If you have a reasonably close to 38Khz signal coming from the transmitter, you should see the blinks. You can attach the LED directly to the output of the IR receiver so you don't have to bother having the Stamp send a pin high or low. In fact, for just testing the link, you don't need the Stamp at all.

    I have never tried to produce 38kHz from a BS2, so I don't know how well it works or how close the 38kHz it really is. Most IR receivers are sensitive to a Khz or two. Maybe someone who has made 38kHz from a BS2 could speak to this. Assuming that the 38kHz signal is OK, are you passing the signal through a Schmitt trigger? This really cleans up the signal and is necessary for data transfer in my experience.

    To transfer data, you need a source of 38kHz running constantly. Then you modulate the signal to send the data. This is best done by sending the carrier signal into one·gate of a Schmitt trigger NAND like the 74HC132. The BS2 then sends serial data to the other gate of the '132. The output of the '132 is fed to a transistor which runs the IR transmitter diode. Since the '132 has a built in Schmitt trigger, you get a nice clean signal.

    Another thing is that you need to drive the transmitter diode really hard. If you look in a TV remote, you will see that they use a transistor and a really low value current limiting resistor, like 2 ohms. You can get away with driving the LED this hard because of the low duty cycle. You can use a digital camera to compare the brightness of your transmitter with that of a TV remote. Yours should be just as bright or close.

    Another thing is that the receivers expect a pause of 100mS or so between data bursts. If you just send a continous flow of data, you lose the connection. Periodic pauses are required to make the TX/RX hook up. This confounded me until I looked·at the output of a TV remote on a scope.

    Anyway, HTH.

    Jonathan





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • JonathanJonathan Posts: 1,023
    edited 2004-10-20 18:28
    I forgot to add that Bruce at Rentron has a great page on IR data communication at:

    http://www.rentron.com/Infrared_Communication.htm

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-20 18:33
    On your transmitter demo you have very little on time (1 ms) and not much of a delay between cycles (~350 us based on instruction loading).· Try this:

    DO
      FREQOUT 3, 100, 38000
    
      PAUSE 900
    LOOP
    

    This will allow a bit of down-time between pulses.· If all goes well, you should see the receiver LED blink about once per second.· And here's a snappier receiver demo:

    LED  PIN  14
     
     
    Start:
      LOW LED
     
    DO
      LED = ~IN6
    LOOP
      
    


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 10/20/2004 6:36:00 PM GMT
  • WhelzornWhelzorn Posts: 256
    edited 2004-10-20 19:00
    Ok, first off, to answer johnathans post, I am using 2 seperate BS2's for this project. Second, jon, I tried your code, and the transmitter only works if I put LOW 3 or HIGH 3 at the top of the transmitter program. Second, the LED stays off, except for a second or so when it flashes 2 or three times very fast. What I am tryin to accomplish here is a continuous 38khz stream out of the infrared LED and I want the reciever to indefinitely look for the signal and turn the LED solid ON when it sees it.
    Thank you for responding!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-20 19:18
    FREQOUT makes the pin an output, so I don't know why you're having problems with that. If you want an continuous stream of modulated IR, then a 555 osciallator is a much better way to go. If your receiver input is looking at the demodulator while the transmitter is between instructions you might get a false off condition.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • WhelzornWhelzorn Posts: 256
    edited 2004-10-20 19:35
    Ok my code for the reciever looks like this, because I wanted it to debug:
    '{$STAMP BS2}
    '{$PBASIC 2.5}
    
    DO
      IF IN6 = 0 THEN
      DEBUG "1", CR
      HIGH 14
    
      ELSE
      DEBUG "0", CR
      LOW 14
    
      ENDIF
    LOOP
    
    



    and using this as a transmitter:
    '{$STAMP BS2}
    '{$PBASIC 2.5}
     LOW 3
    
      DO
      FREQOUT 3, 100, 38000
      PAUSE 900
      LOOP
    
    



    only once every 100 or so "0's" from the debug window will it display a "1"

    this is odd, because it appears that it flashes the Infrared LED once, and then stops it for the 900 ms pause, then flashes again.
    Shouldnt it output 38khz from the LED continuously for 900ms?
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-10-20 20:15
    FREQOUT PinNum, Num_mSec, Freq

    This will send a signal Num_mSec long of Freq.

    FREQOUT 3, 100, 38000 ' This sends a 38,000 hz signal for 100 mSec.
    PAUSE 900 ' Pause for 900 mSec

    During those 100 mSec, the IR Demodulator will output a LOW signal.
    During the Pause, it will output a HIGH signal.

    You *probably* want to use PULSIN to read the pulse.

    Duration VAR WORD

    PULSIN IR_Decoder, 0, Duration

    When the 'idle' state is high, using this PULSIN will cause:
    1. Wait up to 130 mSec for the 1 to 0 edge of the signal. Return 0 if the signal never goes low.
    Start counting immediately if the signal is already low when the command is issued.
    2. Start counting, in 2 uSec 'ticks', how long the signal is low.
    3. When the signal goes high, return the number of 'ticks' it was low. 1 mSec == 500 ticks.

    With this, you can "FREQOUT 3, 1, 38000", and "FREQOUT 3, 2, 38000", and the
    PULSIN command should return around 500 for the first, and 1000 for the second.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-20 20:18
    If you check the manual or help file (hint) you'll find that the 100 in the FREQOUT line of code means 100 milliseconds (0.1 seconds) on a stock BS2. This means that the transmitter IR is "on" for 0.1 seconds, then off for 0.9 seconds (during the PAUSE 900 statement).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • WhelzornWhelzorn Posts: 256
    edited 2004-10-21 01:39
    Ok, I figured out half the problem, but not why.

    I have diagrams of 2 configurations for this. In the first the transmitter is placed on the table next to the reciever, and lower to it:
    diagram.JPG

    this causes the LED to flash very fast, but it means its recieving a good signal which is strange because it does not seem that the infrared light is reaching the detectors eye at all...
    Also in the second example:
    diagram2.JPG
    notice that the IR LED is placed DIRECTLY OVER the detectors eye? well, it detects almost nothing, and is very unreliable if it detects anything. This one has me completely stumped. The detector seems to be the culprit here. The part I'm using can be found here: www.radioshack.com/product.asp?catalog_name=CTLG&product_id=276-640

    great thanks for trying to help, everyone...
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-10-21 13:41
    What code are you using? I'm not sure what modifications you've made so far.
  • JonathanJonathan Posts: 1,023
    edited 2004-10-21 14:48
    Justin,

    Are you driving the IR LED from a Stamp pin? If so, you won't get much output and the Stamp pin might get damaged. Have you verified the brightness of the IR LED? As I mentioned above, you can use a digital camera to see the output.

    The odd results you are getting might be because you need a pause in the stram of 38kHz IR to make the receiver module trigger. Do you get one blink when you use the second setup, then nothing? If so, that would tend to confirm this idea.

    Another issue might be the accuarcy of the 38kHz signal form the Stamp. You might try a 555 circuit as Jon suggested. I have never used the receiver module you are using, but I doubt it is the problem. You can pull one out of an old VCR to mkae sure.

    Jonathan



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-21 15:04
    Jonathan makes a point -- perhaps your series resistor is too large -- 220 ohms will be fine as the output is not constantly on.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • WhelzornWhelzorn Posts: 256
    edited 2004-10-21 20:32
    So are you saying I should drive the LED through a transistor, and use a smaller resistor?

    EDIT: ok, the bottom configuration only works if I write the code like this:
      DO
      FREQOUT 3, 1, 38500
      LOOP
    
    

    Post Edited (Whelzorn) : 10/21/2004 10:24:08 PM GMT
  • JonathanJonathan Posts: 1,023
    edited 2004-10-21 22:26
    Yes. I use a standard NPN switching type transistor and a 15 ohm resistor. You can actually push the resistance even lower if your duty cycle is low enough. Use the digital camera trick if you can get hold of one to determine how bright the LED is. Make sure to use a 1k resistor or so between the Stamp pin and the transistor.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Sign In or Register to comment.