IR decoder Sony code Help


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2012
    Posts
    4

    Exclamation IR decoder Sony code Help

    I have a pic16F628A my TSOP34838 is connected to pin 10 or RB4.

    I've set RB4 to I/O in the configuration bits when i program the chip.
    I'm attempting to use the internal oscillator.

    I've hooked an oscilloscope to the output of the TSOP34838 and I'm seeing the signal there just fine.

    The LCD output appears to work.

    I'm not getting it to display the IR information it received. It just appears to be going through the LCD initialization, then going to Sony_In getting an input of 0, going to No_Sig and relooping.



    I've been at this for hours and hours and can't figure out what's wrong. Any help would be appreciated, I'm completely lost.

    Code:
    'Program SONY_RX.BAS
    ' *************************************************************
    ' * For use with EXPERIMENTING WITH THE PICBASIC PRO COMPILER *
    ' *             *
    ' *  This source code may be freely used within your own      *
    ' *  programs. However, if it is used for profitable reasons, *
    ' *        please give credit where credit is due.       *
    ' *  And make a reference to myself or Rosetta Technologies   *
    ' *             *
    ' *   Les. Johnson         *
    ' *************************************************************
    '
    'This program reads signals from a Sony IR remote control, 
    'and displays them on a Serial LCD, connected to PortA.0 at inverted 9600 Baud 8-N-1
    'The infrared receiver module used is the Sharp GP1U58X.
    'The infrared receiver module for this experiment should, 
    'be a type that is set for a 38 kHz carrier frequency. 
    'If another type is used. some reduction in range may be noticed. 
    'The output pin of the IR module connects to PortB.0 
    'The remote control used, may be either a Sony manufactured unit,
    'or one of the universal remotes that can be configured for Sony equipment. 
    'This is important since we are dealing with a specific signal protocol.
    'With Sony’s SIRCS specification, a start pulse is initially sent to
    'indicate the beginning of a frame of data. This pulse is approx 2.5 msec in length. 
    'Following this, are 7-bits of data, which represent the instruction being sent. 
    'Then an additional 5-bit command byte, which signifies the target device (TV, VCR, etc.). 
    'Data bits are sent with the least significant bit first.
     Include "Modedefs.Bas"
    ' ** Setup the Crystal Frequency, in Mhz **
     Define  OSC  4  ' Set Xtal Frequency
     
    ' ** Declare the Variables **
     
        CMCON = 7
     IR_Sense  Var     PortB.4        ' The IR sensor is attached to this pin
     ST       Var     Word     ' Header length, signal
     IR_Word  Var St  ' Double up the variable, to save ram
     ID  Var Byte  ' The sony bit length 600us = 0, 1200us = 1
     IR_Data  Var Byte  ' The data byte returned
     IR_Dev  Var Byte  ' The command byte returned
     Sony_LP  Var Byte  ' Temporary variable used for a loop
     IR_Valid Var Bit  ' Flag to indicate a valid signal has been received
     
    Main:
        gosub InitializeDisplay
     Gosub Sony_In     ' Receive the remote control signal
     
        If IR_Valid=1 then    ' Do the following code, if a valid packet has been received
    ' Display the data Byte (7-bit code), and the command byte (5-bit code)
            lcdout $FE, 1, "Data"
            pause 500
            lcdout $FE, 1, BIN IR_Data
            lcdout $FE, $C0, bin IR_Dev
            pause 500   
     Endif
            Goto Main     ' Loop Forever.
    ' The subroutine "SONY_IN", receives the signal from a Sony remote control,
    ' and returns with the 7-bit data byte in the variable "IR_DATA",
    ' and the 5-bit command byte in the variable "IR_Dev".
    InitializeDisplay:  ' Subroutine to initialize NEWHAVEN NHD-0208AZ-RN-YBW 
    '=================  ' 2x8 LCD display                   
         ' LCD DEFINES FOR USING 2x8 LCD with PortA
               DEFINE LCD_DREG PORTB    ' Use PORTA for LCD Data
               DEFINE LCD_DBIT 0        ' Use lower(4) 4 bits of PORTB
                                          ' PORTA.0 thru PORTA.3 connect to
                                          ' LCD DB4 thru LCD DB-7 respectively
               DEFINE LCD_RSREG PORTA   ' PORTA for RegisterSelect (RS) bit
               DEFINE LCD_RSBIT 3       ' PORTA.3 pin for LCD's RS line
               DEFINE LCD_RWREG PORTA   ' LCD read/write port
               DEFINE LCD_RWBIT 4       ' LCD read/write bit
               DEFINE LCD_EREG PORTA    ' PORTA for Enable (E) bit
               DEFINE LCD_EBIT 7        ' PORTA.7 pin for LCD's E line
               DEFINE LCD_BITS 4        ' Using 4-bit bus
               DEFINE LCD_LINES 2       ' Using 2 line Display
               DEFINE LCD_COMMANDUS 10000' Command Delay (uS)
               DEFINE LCD_DATAUS 100     ' Data Delay (uS)
           
        ' DEFINE LCD Control Constants 
               Line1   CON 128          ' Point to beginning of line 1 ($80) 
               Line2   CON 192          ' Point to beginning of line 2 ($C0)   
        
        ' Test the LCD during initialization
               LCDOut $fe,1:FLAGS=0:Pause 250    ' Clear Display
               LCDOut $fe,Line1,"LCD TEST"       ' Display on 1st line
               Pause 500
               LCDOut $fe,Line2,"Power On!"      ' Display on 2nd line
               PAUSE 1000
    Return
    Sony_In:
     TrisB.4=1    ' Set the sensor pin to input
     IR_Valid=1    ' Initialize the valid data flag
     If IR_Sense=0 then goto No_Sig   ' We are already in the middle of a pulse so, exit
            IR_Word = 0:IR_Data=0:IR_Dev=0         ' Clear the variables used within the subroutine
            Pulsin IR_Sense,0,ST   ' Measure the header length.
            If St < 200 then goto No_Sig     ' Verify a good start bit, should be approx 240-260, using a 4mhz Crystal      
            If St > 270 then goto No_Sig        ' If not valid then return with "IR_DATA"=255
    ' Receive the 12 data bits (LSB first), and convert them into a 12-bit word,
    ' A high (1) should be approx 120, actual timing is 1200 us
    ' A low (0) should be approx 60 , actual timing is 600 us
    ' We split the difference and say that < 100 is a low, >= 100 is a high
    ' These values are for use with a 4mhz crystal
     For Sony_Lp=0 to 11   ' Do 12-bits
     Pulsin IR_Sense,0,ID   ' Receive the IR bit pulse
     If ID>=100 then 
     IR_Word.0[Sony_Lp]=1   ' If it's greater than 100 then we have received a 1
     Else 
     IR_Word.0[Sony_Lp]=0   ' If it's less than 100 we have received a 0 
     Endif
     Next      ' Close the loop
    ' Split the 7-bit data byte, and the 5-bit command byte
     IR_Data=IR_Word & 111111  ' Mask the first 7 "DATA" bits
     IR_Dev=(IR_Word >>7)&00011111  ' Move down and mask the last 5 "COMMAND" bits
     Return     ' Exit the subroutineNo_Sig:
     IR_Valid=0    ' Indicate, No signal detected
     Return     ' was detected
    Last edited by Thammink; - 27th April 2012 at 03:55.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: IR decoder Sony code Help

    I see 3 goto No_Sig calls and no No_Sig label for them to land on . . . and do you really want to slow your code down by going through the LCD initialization routine every loop? Missing Percent signs on these 2 lines:
    Code:
    Oh I see, it is not an error but vbulletin is truncating the percent sign and leading zeros
    Last edited by Archangel; - 27th April 2012 at 07:32. Reason: spell
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Apr 2012
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: IR decoder Sony code Help

    Sorry, looks like the No_Sig: accidentally got put at the end of the third to last line when I posted here. It's there, it just managed to not get on the next line.

    Also I don't want to go through it every loop, I should probably change that.

    Any more ideas?

  4. #4
    Join Date
    Nov 2006
    Location
    Brooklyn,NY
    Posts
    32


    Did you find this post helpful? Yes | No

    Default Re: IR decoder Sony code Help

    Check : www.rentron.com It will save you a lot of time if you just want to build a Sony decoder and use it to control something.

    Schlaray.

  5. #5
    Join Date
    Apr 2012
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: IR decoder Sony code Help

    I would order one of those, I took a look there. However, I had to create a custom circuit board for a class and am basing my work on that. I'm making an SPDIF/Optical audio switcher. I presented everything for the class and it wasn't working, however, the main reason I wanted to build this is so that I could use it. So it needs to be able to fit the circuit board I have, so I'm kind of stuck doing what I'm trying now.

    Anyone else have any ideas? Thanks for the ideas so far. Does the code look correct? or does it need to change?

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: IR decoder Sony code Help

    Can you give us a "fresh" copy of the code, exactly as you have it right now so we can see what you have, I was unaware of some quirks in vbulletin and probably messed up your original posting, I could fix it but then I wouldn't know if it is what you have now.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Apr 2012
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: IR decoder Sony code Help

    This is the current code I moved the LCD initialization before main: I believe that would work.

    Code:
    'Program SONY_RX.BAS
    ' *************************************************************
    ' * For use with EXPERIMENTING WITH THE PICBASIC PRO COMPILER *
    ' *             *
    ' *  This source code may be freely used within your own      *
    ' *  programs. However, if it is used for profitable reasons, *
    ' *        please give credit where credit is due.       *
    ' *  And make a reference to myself or Rosetta Technologies   *
    ' *             *
    ' *   Les. Johnson         *
    ' *************************************************************
    '
    'This program reads signals from a Sony IR remote control, 
    'and displays them on a Serial LCD, connected to PortA.0 at inverted 9600 Baud 8-N-1
    'The infrared receiver module used is the Sharp GP1U58X.
    'The infrared receiver module for this experiment should, 
    'be a type that is set for a 38 kHz carrier frequency. 
    'If another type is used. some reduction in range may be noticed. 
    'The output pin of the IR module connects to PortB.0 
    'The remote control used, may be either a Sony manufactured unit,
    'or one of the universal remotes that can be configured for Sony equipment. 
    'This is important since we are dealing with a specific signal protocol.
    'With Sony’s SIRCS specification, a start pulse is initially sent to
    'indicate the beginning of a frame of data. This pulse is approx 2.5 msec in length. 
    'Following this, are 7-bits of data, which represent the instruction being sent. 
    'Then an additional 5-bit command byte, which signifies the target device (TV, VCR, etc.). 
    'Data bits are sent with the least significant bit first.
     Include "Modedefs.Bas"
    ' ** Setup the Crystal Frequency, in Mhz **
     Define  OSC  4  ' Set Xtal Frequency
     
    ' ** Declare the Variables **
     
        CMCON = 7
     IR_Sense  Var     PortB.4        ' The IR sensor is attached to this pin
     ST       Var     Word     ' Header length, signal
     IR_Word  Var St  ' Double up the variable, to save ram
     ID  Var Byte  ' The sony bit length 600us = 0, 1200us = 1
     IR_Data  Var Byte  ' The data byte returned
     IR_Dev  Var Byte  ' The command byte returned
     Sony_LP  Var Byte  ' Temporary variable used for a loop
     IR_Valid Var Bit  ' Flag to indicate a valid signal has been received
    'initialize NEWHAVEN NHD-0208AZ-RN-YBW 
    '=================  ' 2x8 LCD display                   
         ' LCD DEFINES FOR USING 2x8 LCD with PortA
               DEFINE LCD_DREG PORTB    ' Use PORTA for LCD Data
               DEFINE LCD_DBIT 0        ' Use lower(4) 4 bits of PORTB
                                          ' PORTA.0 thru PORTA.3 connect to
                                          ' LCD DB4 thru LCD DB-7 respectively
               DEFINE LCD_RSREG PORTA   ' PORTA for RegisterSelect (RS) bit
               DEFINE LCD_RSBIT 3       ' PORTA.4 pin for LCD's RS line
               DEFINE LCD_RWREG PORTA   ' LCD read/write port
               DEFINE LCD_RWBIT 4       ' LCD read/write bit
               DEFINE LCD_EREG PORTA    ' PORTA for Enable (E) bit
               DEFINE LCD_EBIT 7        ' PORTA.5 pin for LCD's E line
               DEFINE LCD_BITS 4        ' Using 4-bit bus
               DEFINE LCD_LINES 2       ' Using 2 line Display
               DEFINE LCD_COMMANDUS 10000' Command Delay (uS)
               DEFINE LCD_DATAUS 100     ' Data Delay (uS)
           
        ' DEFINE LCD Control Constants 
               Line1   CON 128          ' Point to beginning of line 1 ($80) 
               Line2   CON 192          ' Point to beginning of line 2 ($C0)   
        
        ' Test the LCD during initialization
               LCDOut $fe,1:FLAGS=0:Pause 250    ' Clear Display
               LCDOut $fe,Line1,"LCD TEST"       ' Display on 1st line
               Pause 500
               LCDOut $fe,Line2,"Power On!"      ' Display on 2nd line
               PAUSE 1000
    Main:
     Gosub Sony_In     ' Receive the remote control signal
     
        If IR_Valid=1 then    ' Do the following code, if a valid packet has been received
    ' Display the data Byte (7-bit code), and the command byte (5-bit code)
            lcdout $FE, 1, "Data"
            pause 500
            lcdout $FE, 1, BIN IR_Data
            lcdout $FE, $C0, bin IR_Dev
            pause 500   
     Endif
            Goto Main     ' Loop Forever.
    ' The subroutine "SONY_IN", receives the signal from a Sony remote control,
    ' and returns with the 7-bit data byte in the variable "IR_DATA",
    ' and the 5-bit command byte in the variable "IR_Dev".
    
    Sony_In:
     TrisB.4=1    ' Set the sensor pin to input
     IR_Valid=1    ' Initialize the valid data flag
     If IR_Sense=0 then goto No_Sig   ' We are already in the middle of a pulse so, exit
            IR_Word = 0:IR_Data=0:IR_Dev=0         ' Clear the variables used within the subroutine
            Pulsin IR_Sense,0,ST   ' Measure the header length.
            If St < 200 then goto No_Sig     ' Verify a good start bit, should be approx 240-260, using a 4mhz Crystal      
            If St > 270 then goto No_Sig        ' If not valid then return with "IR_DATA"=255
    ' Receive the 12 data bits (LSB first), and convert them into a 12-bit word,
    ' A high (1) should be approx 120, actual timing is 1200 us
    ' A low (0) should be approx 60 , actual timing is 600 us
    ' We split the difference and say that < 100 is a low, >= 100 is a high
    ' These values are for use with a 4mhz crystal
     For Sony_Lp=0 to 11   ' Do 12-bits
     Pulsin IR_Sense,0,ID   ' Receive the IR bit pulse
     If ID>=100 then 
     IR_Word.0[Sony_Lp]=1   ' If it's greater than 100 then we have received a 1
     Else 
     IR_Word.0[Sony_Lp]=0   ' If it's less than 100 we have received a 0 
     Endif
     Next      ' Close the loop
    ' Split the 7-bit data byte, and the 5-bit command byte
     IR_Data=IR_Word & %01111111  ' Mask the first 7 "DATA" bits
     IR_Dev=(IR_Word >>7)&%00011111  ' Move down and mask the last 5 "COMMAND" bits
     Return     ' Exit the subroutine
    No_Sig:
     IR_Valid=0    ' Indicate, No signal detected
     Return     ' was detected

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: IR decoder Sony code Help

    Ok move this up above main TrisB.4 = 1 ' Set the sensor pin to input
    and add this TRISA = %00000000 ' up there too
    Check your defines RS bit cannot reside on PortA.3 as it is used as a data bit, you could move it to portB
    Last edited by Archangel; - 6th May 2012 at 10:43.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Re: IR decoder Sony code Help

    A nice encoder and decoder implemented in PBP (SIRC protocol).
    http://www.rentron.com/PicBasic/IR_Chips.htm

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


    Did you find this post helpful? Yes | No

    Default Re: IR decoder Sony code Help

    This is pretty old, but should work if you have a standard 12-bit type Sony IR transmitter. It's one of the simplest routines I have for decoding Sony IR.

    Code:
    DEFINE OSC 4
    
    IR_PULSE VAR BYTE(12) ' IR data received
    INDEX VAR BYTE        ' Index pointer
    DBYTE VAR BYTE        ' IR data received
    
    Main:
       PULSIN PORTC.3,0,IR_PULSE         '// Read-in start pulse
       IF (IR_PULSE < 200) OR (IR_PULSE = 0) THEN Main
    
    Verify:                              '// Read, Decode, then verify data
       FOR Index = 0 TO 11               '// Setup to read-in 12 pulses
        PULSIN PORTC.3,0,IR_PULSE[Index] '// Read 12 low-going pulses on C3
       NEXT Index                        '// Loop x times
       
       DBYTE = $7F                       '// Start with all 1's and find each 0
       
       FOR Index = 0 TO 6                '// Get 7 "data" bits
        IF IR_PULSE[Index] < 100 THEN DBYTE.0[Index]=0 '// Less than 1mS = 0
       NEXT Index
       
       DBYTE = DBYTE + 1                 '// Button code #1 = 0, Button #2 = 1, so add 1
                                         '// for actual button pressed for display
      
       HSEROUT ["Button #",#DBYTE," was pressed",13,10]
       GOTO Main
       
       END
    It's easy to change to pretty much any I/O-pin you want.
    Regards,

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

  11. #11
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default Re: IR decoder Sony code Help

    Hi Bruce,

    Just curious if you know how much memory that code takes up considering the use of the array?

    Cheerful regards, Mike

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