Sony IR Remote


Closed Thread
Results 1 to 40 of 41

Thread: Sony IR Remote

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Location
    Albuquerque
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Confused

    I am only 17 and I have partially self taught myself PICBasicPro. Since I have not taken any engineering courses and I am still in high school I do not understand much. I checked out the example from this http://www.picbasic.co.uk/forum/showthread.php?t=12555. I have never used the CCP module before so I am a little lost. I need this code for a 12f683. I highlighted the parts in red that I do not understand. I need to transmit the the data to a 1 wire serial lcd using serout command not the debug but I dont know how to do that. Please help.
    Code:
    ' Connections;
    ' IR detector output to PORTA.2 CAP1 input
    ' PORTB.0 ------/\/\/\/----|>|----GND LED on RB0 (for press/release indicator)
    ' PORTC.6 --MAX232---PC serial port RX (to print results)
    DEFINE NO_CLRWDT 1    ' it's disabled in config
    DEFINE LOADER_USED 1
    DEFINE OSC 4
    DEFINE DEBUG_REG PORTC
    DEFINE DEBUG_BIT 6 
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 0    ' 1 = inverted, 0 = true
     
    NumPulses CON 26       ' total signal states to learn (26 for Sony)
     
    T1     VAR WORD[NumPulses]
    INDEX  VAR BYTE
    KeyNum VAR BYTE
     
    SYMBOL Capture = PIR3.1
     
        CLEAR
     
        ANSEL0 = 0           ' all digital
        TRISA.2 = 1          ' cap1 input pin (Capture input)
        INTCON = 0           ' interrupts off
        TMR1H = 0            ' clear high byte of TMR5 count
        TMR1L = 0            ' clear low byte
        T1CON = %00000001    ' prescale=1:1, int clock, TMR5=on
     
    Main:
        CAP1CON = %01001000  ' auto time base reset, capture on every state change
        Capture = 0
     
        FOR KeyNum = 0 TO 14   ' learn 15 total button codes
          CAP1CON = %01001000  '      HIGH 0               ' indicate start (user press button)   
          Capture = 0          ' clear capture flag before starting
     
          ' Wait for 1st capture on state-change. Note: We don't care what the 1st capture
          ' value is since it's the beginning high-to-low edge (for IR), and of no significance.
          ' We only want the length of each high & low signal after the falling edge.
          WHILE Capture = 0 : WEND
          Capture = 0    
     
          FOR INDEX = 0 TO NumPulses-1 ' captures IR signal in 1uS increments
            WHILE Capture = 0 : WEND   ' wait for capture event
            Capture = 0                ' clear int flag after each capture
            T1[INDEX] = ((CAP1BUFH<<8) + CAP1BUFL) ' store capture values
          Next INDEX   
          CAP1CON = 0 ' disable capture immediately after to avoid unwanted captures
          Capture = 0
                      ' if user holds transmitter button down too long.
          LOW 0       ' indicates user should release transmitter button
          PAUSE 1000
     
          ' print button codes 
          FOR INDEX = 0 TO NumPulses-1 STEP 2
            DEBUG "low = ", DEC T1[INDEX],"uS",13,10   ' print low signal period
            DEBUG "high = ",DEC T1[INDEX+1],"uS",13,10 ' print high signal period
          NEXT INDEX
          DEBUG 10,13
        NEXT KeyNum
     
    Finished:  ' indicate finished
        TOGGLE 0
        PAUSE 200
        GOTO Finished
     
        END

  2. #2
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Confused:

    That code is specific to the 18F2431, with features not found in the 16F683.

    Take a look at the code here http://www.rentron.com/PicBasic/IR_Chips.htm by the same author for a better understanding of decoding IR remote signals.

  3. #3
    Join Date
    Feb 2010
    Location
    Albuquerque
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Still Not Right

    That is one way to do it but I need a simple way to read the Sony protocol. I liked the way this code works because it doesnt require any hardware peripherals. Please help me figure out why this isnt working.
    Code:
    pulse  var Word
    x      var byte
    signal var word
    
    ANSEL = %00000000
    
    Start:
        Pulsin PORTC.3, 0, pulse
        if (pulse < 220) or (pulse > 260) then start
        
    signal = 0
    x = 1
    
    Loop:
        pulsin PORTC.3, 0, pulse
        if (pulse > 90) then ADD_X
        
        READ_IR:
        x = x * 2
        if (x = 255) then start
        
        serout PORTC.2, 2, [#signal]
        
        goto loop
        
    ADD_X:
        signal = signal + x
        goto read_ir
        
    end

  4. #4
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    For one thing, I would take the SEROUT out of your loop: SEROUT takes a fair amount of time, and you will lose any IR pulses after the first while servicing the SEROUT.Save pulses to an array as you capture them, then SEROUT when done with capture.

    Also, the tolerance on this:
    Code:
     if (pulse < 220) or (pulse > 260) then start
    might be a little tight to capture the 240msec AGC pulse at the start. See below.


    From the link I gave you:

    Code:
    Decode:                             '// Shift right to remove bit RA.0
       H_Add = (PORTA >> 1) & %00011111 '// AND with %00011111 to mask upper 3-bits
                                        '// RA.1 to RA.5 = 5-bit hardware address
    Decode2:
       PULSIN PORTA.7,0,PULSE_IN        '// Read-in start pulse
       IF (PULSE_IN < 200) OR (PULSE_IN = 0) THEN '// Less than Start pulse, then keep looking
        Loops = 0                       '// Reset Loops on idle or key release
        IF LM = 1 THEN Decode           '// If mode = latching, don't change outputs.
        PORTB = 0                       '// Mode = momentary. Key = released or idle
        GOTO Decode                     '// so clear outputs & return.
       ENDIF
    
    Verify:                              '// Read, Decode, then verify data
       FOR Index = 0 TO 12               '// Setup to read-in 13 pulses
        PULSIN PORTA.7,0,IR_PULSE[Index] '// Read 13 low-going pulses on RA.7
       NEXT Index                        '// Loop x times
       DBYTE = $FF                       '// Start with all 1's and find each 0
       FOR Index = 0 TO 7                '// Get 8 "data" bits
        IF IR_PULSE[Index] < 100 THEN DBYTE.0[Index]=0 '// Less than 1mS = 0
       NEXT Index
       ABYTE = $FF           '// Start with all 1's and find each 0 in pattern
       X=0                   '// Initialize address bit index pointer to bit 0
       FOR Index = 8 TO 12   '// Get 5 address bits from IR_PULSE bits 8-12
        IF IR_PULSE[Index] < 100 THEN ABYTE.0[X]=0
        X = X + 1            '// Increment address bit index pointer
       NEXT Index
       ABYTE = ABYTE & %00011111 '// Mask out upper 3-bits. Result = 5-bit address.
    is a good start. ABYTE and DBYTE together give you the 12 bit decoded command.

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    949


    Did you find this post helpful? Yes | No

    Default PULSIN resolution

    Quote Originally Posted by gmglickman View Post
    Code:
     if (pulse < 220) or (pulse > 260) then start
    might be a little tight to capture the 240msec AGC pulse at the start. See below.
    @ 4MHz, PULSIN has 10µs resolution.

    If you need to capture 240msec, then you would have:
    Code:
     if (pulse < 22) or (pulse > 26) then start
    I did something similar and left PULSIN by side - I use TMR1 instead. Have a look to the "code" section here http://home.citycable.ch/flotulopex/...I_Frames_e.htm

    HTH
    Roger

  6. #6
    Join Date
    Feb 2010
    Location
    Albuquerque
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Timing

    I dont think the timing is off becuase I used a portion of the first code to make shure the range of numbers was correct.

    Code:
    start:
    if (pulse < 220) or (pulse > 260) then start
    high GPIO.2
    pause 100
    low GPIO.2
    goto start
    I think this was the code but I used 220 through 260 and the led would flash every time it detected the ACG pulse. So I dont think the values are incorrect. I just dont know how to excecute the program.
    I would really like to use this code below because I understand it, it's simple and I can do it all in software. If anyone can please tell me what is wrong with this code please let me know.
    Code:
    pulse  var Word
    x      var byte
    signal var word
    
    ANSEL = %00000000
    
    Start:
        Pulsin PORTC.3, 0, pulse
        if (pulse < 220) or (pulse > 260) then start
        
    signal = 0
    x = 1
    
    Loop:
        pulsin PORTC.3, 0, pulse
        if (pulse > 90) then ADD_X
        
        READ_IR:
        x = x * 2
        if (x = 255) then start
        
        serout PORTC.2, 2, [#signal]
        
        goto loop
        
    ADD_X:
        signal = signal + x
        goto read_ir
        
    end

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


    Did you find this post helpful? Yes | No

    Default

    One Sony decoder chip comin up..

    This should be easy to understand & modify for your PIC type. And you can easily change it to display buttons like channel-up, down, volume-up, down, etc..
    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 RC.3
       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 pressed was ",#DBYTE,13,10]
       GOTO Main
     
       END
    This will print buttons #1 through #9. Buttons 0, channel, volume, etc will output the numeric values corresponding to buttons pressed.

    I know you don't care about the device codes like TV, VCR, etc, but it's easier to keep in-synch if you read these in anyway.
    Last edited by Bruce; - 15th May 2010 at 06:22.
    Regards,

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

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