IR decode problem "hitachi TV remote"


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2005
    Posts
    70

    Default IR decode problem "hitachi TV remote"

    I have to try decode IR hitachi TV format but not work pls advise

    We used pulsin for measure pulse with.
    1. we measure head pulse and next pluse bit and keep it .
    2. bring pulse bit to decode "0" or "1"
    3. Prind data tp pc

    Problem :
    The decode pulse with not consitance not show all same time after we push in the same key on remote.

    Hitachi =32 bit ,see attached picture
    head +8800 -2200
    Bit "0" +550 -1650
    Bit "1" +550 -550




    Here is my code:

    'PIC 16F877

    DEFINE LOADER_USED 1
    DEFINE OSC 4

    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG 12 ' 19200 Bauds

    Header Var Word ' Header pulse length
    Packet Var Word ' 16-bit IR information
    Packet1 Var Word ' 16-bit IR information
    P_Val Var Byte[32] ' Record pluse width
    IR_But Var Byte ' The BUTTON code returned
    IR_Dev Var Byte ' The DEVICE code returned
    Sony_LP Var Byte ' Temporary loop variable
    Green_LED Var Portb.3 ' Assign the red LED to this pin

    TRISA = 0
    LOW Green_LED

    START:

    GOSUB IRIN
    IF IR_But =255 THEN start 'HIGH Green_LED

    For Sony_Lp=0 to 23 ' Do 12-bits
    Pulsin PortB.0,0,P_Val[SONY_LP] ' Receive the IR bit pulse
    HSEROUT ["B ",DEC P_VAL[SONY_LP],13,10]
    NEXT
    HSEROUT ["Bottom ",DEC IR_But,13,10]
    HSEROUT ["Comand ",DEC IR_Dev,13,10]

    Packet =0
    Packet1 =1
    intcon.1=0
    GOTO START

    IRIN:
    IR_Dev=255:IR_But=255
    Pulsin PortB.0,0,Header ' Measure the header length.
    'HSEROUT ["H ",DEC Header,13,10]
    If Header < 792 then Return ' Verify a good header
    If Header > 968 then Return ' If not valid then exit

    For Sony_Lp=0 to 23 ' Do command 8-bits
    Pulsin PortB.0,1,P_Val[SONY_LP] ' Receive the IR bit pulse "0"

    NEXT

    For Sony_Lp=0 to 7 ' Do device 8-bits
    If P_Val[SONY_LP] >= 120 then ' If it's >= 120 then we've received a 1
    Packet.0[Sony_Lp] = 1 ' So set the appropriate bit of PACKET
    Else
    Packet.0[Sony_Lp] = 0
    Endif
    NEXT

    For Sony_Lp=17 to 24 ' Do 12-bits
    If P_Val[SONY_LP] >= 120 then ' If it's >= 120 then we've received a 1
    Packet1.0[Sony_Lp] = 1 ' So set the appropriate bit of PACKET1
    Else
    Packet1.0[Sony_Lp] = 0
    Endif
    NEXT

    ' Split the 7-bit BUTTON code, and the 5-bit DEVICE code

    'IR_But=Packet & %01111111 ' Mask the 7 BUTTON bits
    IR_But=Packet
    'IR_Dev=(Packet >>7) & %00011111 ' Move down and mask, the 5 DEVICE bits
    IR_dEV=Packet1

    Return
    Attached Images Attached Images  
    Last edited by chai98a; - 11th March 2006 at 20:25.

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


    Did you find this post helpful? Yes | No

    Default

    I'm not sure what you are asking but here's a code snippet that captures the 4 bytes represented by the Hitachi (same as NEC) code.
    Code:
    IR	VAR	byte[4]
    pulses  VAR     byte[33]
    BitMask VAR     byte
    i       VAR     byte            'loop index
    b       VAR     byte            'byte index
    LeadIn  VAR     word            'start pulse
    
    
    loop:   PulsIn GPIO.1, 0, LeadIn
            If LeadIn < 855 Then loop
       	If LeadIn > 1045 Then loop
       	For i = 0 TO 32
         	  PulsIn GPIO.1, 1, pulses[i]
       	Next
            For i = 1 To 32
              If (pulses[i] < 40) Or (pulses[i] > 200) Then 
                Goto loop
              EndIf
              b = i >> 3                      	'0,1,2,3
              If pulses[i] > 99 Then  
                IR[b] = IR[b] | BitMask       	'set bit 
              EndIf 
              BitMask = BitMask << 1        	'$01,$02,$04,$08,$10,$20,$40,$80
              If BitMask = 0 Then BitMask = $01 
            Next
    At this point IR[0:3] contain the data.

  3. #3
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    Hi dhouston thank for your advise.
    After we try on your code that show improvement of pulse capture ability but still not canisistance.

    Question. Refer code above.
    Why my code show low speed than your code?
    For my code show 4-5 value of pulse capture but your code can capture all bit.

    Do you have tips for make basic source code or not...

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


    Did you find this post helpful? Yes | No

    Default

    I wrote that from memory and made one mistake. The first capture in the loop is the space following the start pulse. The bits of the code are in pulses[1:32].

    The second loop should be changed to:
    Code:
            For i = 0 To 31
              If (pulses[i+1] < 40) Or (pulses[i+1] > 200) Then 
                Goto loop
              EndIf
              b = i >> 3                      	'0,1,2,3
              If pulses[i+1] > 99 Then  
                IR[b] = IR[b] | BitMask       	'set bit 
              EndIf 
              BitMask = BitMask << 1        	'$01,$02,$04,$08,$10,$20,$40,$80
              If BitMask = 0 Then BitMask = $01 
            Next
    I've used that basic algorithm for several years to capture X-10 RF codes which also use the NEC protocol. You can find a description of the protocol at http://www.cpcares.com/pdf/UPD6121G-001.PDF.

    If you're having a problem with consistency, it is most likely hardware related.

    With IR, you should also define a maximum value for PulsIn. That's not always needed with RF where there are constant noise pulses in the absence of a signal.

Similar Threads

  1. Ir problem sending data
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th December 2009, 05:27
  2. Plz help in completing RC-5 IR remote lamp dimmer project
    By vu2iia in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd April 2008, 08:44
  3. PIC10F200 Automated IR Light Switch
    By Bruce in forum Code Examples
    Replies: 7
    Last Post: - 3rd May 2007, 11:40
  4. How to decode IR Hitachi remate (TV) pls help
    By chai98a in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th March 2006, 11:55
  5. Problem with comparing IR signal to Binary
    By zazery in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd April 2004, 03:38

Members who have read this thread : 1

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