Decoding an incoming infrared signal: need advice


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    xnihilo's Avatar
    xnihilo Guest

    Smile Decoding an incoming infrared signal: need advice

    Here is the stuff:

    I'm using PIC16F684 (as usual) and I connected a Vishay TSOP4840 IR receiver-demodulator.
    It has 3 leads: GND, VSS and DATA.
    The data lead connects to RA0 of my pic. RA0 is set as input and has its WPU enabled so when the receiver gets 40KHz IR signal at 940 nm (and amplified it) it brings RA0 low.

    Well.

    Now I have to write a routine that will decode the signal.

    Signal is a PWM signal (40KHz, 30% duty cycle).
    The data encoding is:

    Header: High 2400us.

    Data: 8 bits, sent from MSB to LSB, decoded from MSB to LSB.
    Each byte is prefixed with a 600us no-pulse pause (the 'spacer'). If a bit is set, there is a 1200us pulse, if bit is cleared, there is a 600us pulse.

    The routine I would like to use is:
    -----------------------------------------------

    WHEN INT OCCURS:

    (inside my int handler, once i've cleared port latch mismatch anr reset int flag)

    Code:
    databyte = %00000000
    
    'wait for the header pulse to end and check if duration is about 2400us+/-100us
    j = 0
    WHILE (porta.0 == 0)
      PAUSEUS 20
      j = j + 1
    WEND
    IF (( j < 115) || (j > 125)) then abort    'wrong pulse duration
    
    FOR i = 0 to 7
    
    j = 0  
    WHILE (porta.0 == 1)    'wait until the bit prefix (600us no-pulse) ends
      PAUSEUS 20
      j = j + 1
    WEND
    IF ((j < 25) || (j > 35)) then abort    'wrong no-pulse duration, we want it to be 600us+/-100us
    
    j = 0
      WHILE (porta.0 == 0)
        PAUSEUS 20
        j = j + 1
      WEND
      IF ((j > 25) && (j < 35)) THEN
        databyte.0(i) = 0
        GOTO bypass
      ENDIF
      IF ((j > 55) && (j < 65)) THEN
        databyte.0(i) = 1
        GOTO bypass
      ENDIF 
    GOTO abort    'wrong pulse duration
    bypass:
    
    NEXT i
    
    abort:
    ------------------------


    I'm afraid this code is pretty heavy and I don't like the lack of accuracy in the timing that force me to use stupid code like:
    IF ((j < 25) || (j > 35)) then abort

    Is there a faster and more accurate way to decode my signal?

    THANKS A LOT for any help or advice.

    regards

    charles

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Maybe you can find some tips with the following
    http://rentron.com/PicBasic/IR_Chips.htm
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    From the bit timing you indicate, I would guess this is a Sony IR transmitter? PULSIN should
    be all you need to decode this type. It's one of the easiest around to encode & decode.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Smile Decoding routine for IR encoded signal

    No guys,

    I can't change my hardware.

    BRUCE:
    "From the bit timing you indicate, I would guess this is a Sony IR transmitter? PULSIN should
    be all you need to decode this type. It's one of the easiest around to encode & decode."

    It is a VISHAY TSOP4840 receiver (see mouser for the datasheet) and the emiter is a VISHAY TSAL6100 led. I'm using pic's PWM output to encode and I need to decode on the other side but do it quickly and acurately. I'm not using pulsin, I'm polling the input pin, what's wrong with that?

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Nothing's wrong with polling, if it works for you. I just prefer PULSIN since it's more
    than accurate enough, and a lot easier.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Bruce View Post
    Nothing's wrong with polling, if it works for you. I just prefer PULSIN since it's more
    than accurate enough, and a lot easier.
    I agree.

    Thank you very much.

Similar Threads

  1. Recording incoming logic signal duration, both edges - how to?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 6th January 2010, 07:56
  2. signal decoding
    By Steve S. in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 14th September 2008, 20:58
  3. PIC16F684 + LCD to use the 256bytes of EEPROM - HELP
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th March 2008, 14:19
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. "momentary" IR decoding
    By sporker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th June 2005, 01:53

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts