PIC Beginner - Infrared Receiver and IR Protocol


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    From your schematic it appears you are using an IR receiver. Which one?

    IR receivers usually are active low while the code I supplied for the NEC protocol was for RF where the receiver is active high. Also, my code was meant to work with the RF transmitter code that accompanied it which used slightly different timing than the NEC IR protocol.

    The EDN article is wrong about details of the NEC IR protocol. It is explained in this NEC datasheet.You will need to modify my RF code in order to receive/decode IR codes.
    Code:
    '12F629
    
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    
    DEFINE PULSIN_MAX 1140				'>1140 RETURNS 0
    DEFINE DEBUG_REG GPIO
    DEFINE DEBUG_BIT 2				'GPIO.2
    DEFINE DEBUG_MODE 1 				'Inverted
    DEFINE DEBUG_BAUD 9600
    DEFINE OSCCAL_1K 1
    
    IR      VAR     byte[4]
    pulse   VAR     byte
    i       VAR     byte	         	
    stx     VAR     word            	'start of transmission
    
            CMCON = 7                   'comparators off
            Debug "IR NEC PROTOCOL"
    init:   IR[0]=0:IR[1]=0:IR[2]=0:IR[3]=0:i=0
            PulsIn GPIO.1, 0, stx	
            If (stx<760) Then init  		
            'debug #stx                 
            While GPIO.1=1:Wend			'wait space
            Repeat
              PulsIn GPIO.1, 1, pulse
              If (pulse>100) Then
                IR.0(i)=1				'set bit
              EndIf
              i=i+1 
            Until (i>31)
            For i = 0 To 3
              Debug IHEX2(IR[i] REV 8)
            Next
            GoTo init
    
            End
    I have not tested the above code (I don't have time to build a circuit with an IR receiver.) and you will need to convert it for your PIC and the pins you are using.

    Note also that my code does not deal with the NEC shortcut repeat code.
    Last edited by dhouston; - 30th August 2009 at 11:55.

  2. #2
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Change...
    Code:
            For i = 0 To 3
              Debug IHEX2(IR[i] REV 8)
            Next
    to...
    Code:
            For i = 0 To 3
              Debug IHEX2 IR[i]
            Next
    The bit order is already reversed as the bits are set by...
    Code:
    RF.0(i)=1

  3. #3
    Join Date
    Apr 2003
    Location
    Cambridge - UK
    Posts
    1,046


    Did you find this post helpful? Yes | No

    Default

    Moe, you might want to read this article: Controlling the world from your armchair

  4. #4
    Join Date
    Apr 2003
    Location
    Cambridge - UK
    Posts
    1,046


    Did you find this post helpful? Yes | No

    Default

    Moe, Infrared remote control decoding maybe considered something of a black art, however, this tutorial will show you that its principals are quite straightforward, and easy to implement on a PIC microcontroler.

    Thanks to BASIC’s shallow learning curve, software designs that used to take weeks can now be realised in a just few hours. This article presents software solutions in the PicBASIC Pro language.

    You might want to read the article: Controlling the world from your armchair

  5. #5
    Join Date
    Apr 2003
    Location
    Cambridge - UK
    Posts
    1,046


    Did you find this post helpful? Yes | No

    Default

    The article is an extract from the book, EXPERIMENTING with the PICBASIC PRO COMPILER, written by Les Johnson.

    The book is cuerrently out of publication, however we are considering publishing an online version as part of the new PIC BASIC portal that we are developing to support PIC BASIC Users.

  6. #6
    Join Date
    Aug 2009
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Pulsin and IR

    dhouston,
    When I change code, old result 0 turn to 255. All the keys press are same.




    Header Logic 0 Logic 1 Logic 1 logic 0

    2400 600 600 600 1200 600 1200 600 600
    x a b c d e f g h i j
    +------------------------+ +------+ +--------------+ +--------------+ +------+
    | | | | | | | | | |
    | | | | | | | | | |
    | | | | | | | | | |
    ---+ +------+ +------+ +------+ +------+ +------
    x____________________________|_____________|______ _____________|___________________|_____________|
    pulsin header 1st loop 2nd loop 3rd loop 4th loop

    return width of length





    -- code start -------------------------------
    Code:
              
             pulsin irIn , 0 , Header       'Line 1
        
                for i =0 to 3
                   pulsin irin, 0 , tmp       'line 3
    
                   if tmp > 90 then                
                        body.0[i] = 1         'line 5 
                   else
                        body.0[i] = 0         'line 7  
                   endif
                next
    -- end of code -------------------------------

    I think pulsin work as follow:

    1. pulsin is timeout when no rising edge was found. return width is zero.
    2. pulsin is time out when rising edge was found and then until falling edge. return the width length.


    so pulsin in code run like that:


    Line 1 : pulsin start measure (x) to end edge (b). Width is (a) to (b) so Header = 2400 (space (x) to (a) is not count.

    Loop 0 (1st loop)
    Line 3 : pulsin start measure (b) to end edge (d). Width is (c) to (d) so tmp = 600 (space (b) to (c) is not count.
    Line 5 and 7: see the width lenght (not space) and decided logic 0
    Loop 1 (2nd loop)
    Line 3 : pulsin start measure (d) to end edge (f). Width is (e) to (f) so tmp = 1200 (space (d) to (e) is not count.
    Line 5 and 7: see the width lenght (not space) and decide logic 1
    Loop 2 (3rd loop)
    Line 3 : pulsin start measure (f) to end edge (h). Width is (g) to (h) so tmp = 1200 (space (f) to (g) is not count.
    Line 5 and 7: see the width lenght (not space) and decide logic 1
    Loop 3 (4th loop)
    Line 3 : pulsin start measure (h) to end edge (j). Width is (i) to (j) so tmp = 600 (space (h) to (i) is not count.
    Line 5 and 7: see the width lenght (not space) and decide logic 0

    PULSIN can only measure the width length.

    When this code is used for NEC Protocol, all pulse are equal depending upon if statement (Logic 0 or 1)
    Because In NEC, logic 1 or 0 is determined by space length. How can I measure space with pulsin.

    lester
    Thanks.

    I already read Les Johnson's article and "Section 6: Experimenting with Remote Control" of that book. I already tested it. All are ok. But it's Sony IR Protocol (Pulse Width Modulation) that quite different from NEC IR Protocol (Pulse Distance Modulation).
    I admire you and dhouston when I found your join date.
    I start and learn picbasic at last week of July of this year. I search and collect PIC books (picbasic, C and Assembly) and article. I found about 60 books and articles. But I cannot find enough explanation for a command. eg. I want to know pulsin in detail. How pulsin work? examples relating pulsin. Pulsin in "PicBasic Pro Manual" is general. Picbasic is best language for me although I've little experience with C Language.


    Moe
    Last edited by komoe01; - 31st August 2009 at 12:27.

  7. #7
    Join Date
    Aug 2009
    Posts
    9


    Did you find this post helpful? Yes | No

    Default please see ir wave

    Sorry sample wave is broken.



    If wave picture is not found, Please see it in attachment picture

    Moe
    Attached Images Attached Images  
    Last edited by komoe01; - 31st August 2009 at 12:35.

  8. #8
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by komoe01 View Post
    When I change code, old result 0 turn to 255. All the keys press are same.
    It works fine for me. It's impossible for me to guess at what changes you have made to it. Try to test it using my code exactly as written. Once that works, try modifying it for your application, going step by step to isolate where the problem is being introduced.

    The waves you've attached (including the second one) are not NEC IR protocol.

    How are you sending the IR codes?

  9. #9
    Join Date
    Aug 2009
    Posts
    9


    Did you find this post helpful? Yes | No

    Default IR and PIC16FXXX

    dhouston

    The wave image is a sample (part of the sony protocol).


    Try to test it using my code exactly as written.
    Ok. dhouston

    But 12F629 pic is not available for me. Just a few PIC model can buy in my country. I have to use 16F84A or 16F628A. Beside I use IR, not RF.
    I'm a beginner for pic so I've not familiar with DEBUG that used in your code.

    So I write code to PIC than I see the result of LED signal and Computer program.

    When I test it using your code exactly, what can I see the result from where? Can I use Infrared remote control? or I must built your transmitter to test receiver.

    I think I must to change some code.

    I do my best as you say!

    Thanks.

    Moe

  10. #10
    Join Date
    Nov 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Lester, is there somewhere we can download the include files from the book? I'd like to use the Sony IR files in a project. Thanks!

    Quote Originally Posted by lester View Post
    The article is an extract from the book, EXPERIMENTING with the PICBASIC PRO COMPILER, written by Les Johnson.

    The book is cuerrently out of publication, however we are considering publishing an online version as part of the new PIC BASIC portal that we are developing to support PIC BASIC Users.

  11. #11
    Join Date
    Jun 2007
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: PIC Beginner - Infrared Receiver and IR Protocol

    dears ,

    i know its a very long time , but please am stick on this , can you post a full working code for pic16f84a to decode nec protocol .
    many many thanks .

Similar Threads

  1. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 21:01
  2. PIC to PIC "wired" serial one-way communication - SERIN2/SEROUT2
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th April 2008, 20:02
  3. Infrared Receiver
    By emavil in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th December 2006, 01:03
  4. how to get pic to pic communication
    By kinsiro in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th August 2005, 17:12
  5. Can this IR Xmitter/Rcvr be improved?
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th August 2005, 11:27

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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