Shop OBEX P1 Docs P2 Docs Learn Events
NEC IR Protocol — Parallax Forums

NEC IR Protocol

absolutmaximusabsolutmaximus Posts: 3
edited 2008-05-29 21:11 in BASIC Stamp
I see there is plenty of information on transmitting IR code Sony IR Protocol with Stamp, but has anyone seen any on NEC IR Protocol?

Thanks,
George

Comments

  • stephenwagnerstephenwagner Posts: 147
    edited 2008-05-27 11:55
    George,

    Customer Application, IR Reater, RCA receiver NEC transmitter.

    http://www.parallax.com/tabid/321/Default.aspx

    Here is the RCA receiver code and NEC transmitter code:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    'RCA 24 bits. 8 bits highcode.lowbyte, 16 bits lowcode (Four (4) groups of six (6))
    'Magnavox TV 32 bits. 16bits highcode, 16 bits lowcode (Four (4) groups of eight (8))
    'RCA 24 bits. 6 bits custom/appliance code, 6 bits data, 6 bits NOT custom/appliance code, 6 bits NOT data.
    'Magnavox TV 32 bits. 8 bits custom/appliance code, 8 bits NOT custom/appliance code, 8 bits data, 8 bits NOT data.
    'PINS
    det PIN 1
    mod PIN 0
    delaypin PIN 4
    'variables
    pulse VAR Word
    idx VAR Nib
    codehigh VAR Word
    codelow VAR Word
    reps VAR Nib
    transmit VAR Bit
    delay VAR Word
    burst CON 52 'Note used right now
    adjust1 CON 562
    adjust2 CON 276
    'RCA Receiver V1 Code
    start:
    LOW mod
    codehigh = 0
    codelow = 0
    checking:
    IF det = 1 THEN checking
    PULSIN det, 1, pulse
    IF pulse < 1935 OR pulse > 2005 THEN checking 'check for 4000 uSec (3930)/2 = 1965 +/- 30 =
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codehigh.BIT7 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codehigh.BIT6 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codehigh.BIT5 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codehigh.BIT4 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codehigh.BIT3 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codehigh.BIT2 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codehigh.BIT1 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codehigh.BIT0 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT15 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT14 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT13 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT12 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT11 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT10 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT9 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT8 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT7 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT6 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT5 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT4 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT3 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT2 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT1 = 1
    RCTIME det, 1, pulse
    IF pulse > 557 THEN codelow.BIT0 = 1
    transmit = 0
    SELECT· codelow
    CASE = 43221 'RCA Sat. Receiver on/off
    codehigh = 189 'Magnavox power code high
    codelow = 32895 'Magnavox power low
    reps = 1
    delay = 250
    transmit = 1
    CASE = 57553 'RCA TV -volume code
    codehigh = 189 'Magnavox -volume code high
    codelow = 2295 'Magnavox -volume code low
    reps = 15
    delay = 150
    Transmit = 1
    CASE = 61648 'RCA TV +volume code
    codehigh = 189 'Magnavox +volume code high
    codelow = 12495 ' Magnavox +volume code low
    reps = 5
    delay = 200
    Transmit = 1
    CASE = 61632 'RCA TV mute code
    codehigh = 189 'Magnavox mute code high
    codelow = 8415 'Magnavox mute code low
    reps = 1
    delay = 250
    transmit = 1
    ENDSELECT
    IF transmit = 0 THEN start
    PAUSE 1000
    FOR idx = 1 TO reps
    'Magnivox Transmitter code V2. 9000 uSec burst, 4500 uSec off followed by 32 data (564/566 uSec or 2690 uSec)· and 33 burst (560/572 uSec.)
    HIGH mod 'Turn on Transmitter
    PULSOUT delaypin, 4254 ' 9000 uSec burst. On for 9000 uSec
    PULSOUT mod, 2247 'Off for 4500 Usec
    'PULSOUT delaypin, 4254 ' 9000 uSec burst. On for 8990 uSec
    'PULSOUT mod, 2247 'Off for 4500 Usec
    'PULSOUT delaypin, 4254 ' 9000 uSec burst. On for 8990 uSec
    'PULSOUT mod, 2247 'Off for 4500 Usec
    'bit 15 = 0
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 282' bit 15 564/566 uSec or 1690 uSec
    'bit 14 = 0
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 283' 566 uSec
    'bit 13 = 0
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 282' 564 uSec
    'bit 12 = 0
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 283' 566 uSec
    'bit 11 = 0
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 282' 564 uSec
    'bit 10 = 0
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 283' 566 uSec
    'bit 9 = 0
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 282' 564 uSec
    'bit 8 = 0
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 283' 566 uSec
    'bit 7 = 1
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 845' 1690 uSec
    'bit 6 = 0
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 283' 566 uSec
    'Bit 5 = 1
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 845' 1690 uSec
    'bit 4 = 1
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 845' 1690 uSec
    'bit 3 = 1
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 845' 1690 uSec
    'bit 2 = 1
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 845' 1690 uSec
    'bit 1 = 0
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 282' 564 uSec
    'bit 0 = 1
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 845' 1690 uSec
    'bit 15 (572 uSec and 552/554 uSec or 1678 uSec)
    'No instruction before .bit math yields 572 uSec. 12 uSec over. Therefor the below code must be 12 uSec under. total 1125 or 2250
    PULSOUT mod, codelow.BIT15 * adjust1 + adjust2
    'bit 14
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 283' 566 uSec
    'bit 13
    'No instruction befor .bit math yields 572 uSec.
    PULSOUT mod, codelow.BIT13 * adjust1 + adjust2
    'bit 12
    'No instruction befor .bit math yields 572 uSec.
    PULSOUT mod, codelow.BIT12 * adjust1 + adjust2
    'bit 11
    'No instruction befor .bit math yields 572 uSec.
    PULSOUT mod, codelow.BIT11 * adjust1 + adjust2
    'bit 10
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 283' 566 uSec
    'bit 9
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 282' 564 uSec
    'bit 8
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 283' 566 uSec
    'bit 7
    'No instruction befor .bit math yields 572 uSec.
    PULSOUT mod, codelow.BIT7 * adjust1 + adjust2
    'bit 6
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 845' 1690 uSec
    'bit 5
    'No instruction befor .bit math yields 572 uSec.
    PULSOUT mod, codelow.BIT5 * adjust1 + adjust2
    'bit 4
    'No instruction befor .bit math yields 572 uSec.
    PULSOUT mod, codelow.BIT4 * adjust1 + adjust2
    'bit 3
    'No instruction befor .bit math yields 572 uSec.
    PULSOUT mod, codelow.BIT3 * adjust1 + adjust2
    'bit 2
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 845' 1690 uSec
    'bit 1
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 845' 1690 uSec
    'bit 0
    PULSOUT delaypin, 52' to yield 560 uSec
    PULSOUT mod, 845' 1690 uSec
    'stop bit = 560 uSec
    PULSOUT delaypin, 99 '99 yields 560 uSec Last One
    LOW mod 'Turn transmitter off
    PAUSE delay
    NEXT
    GOTO start
    ·
  • absolutmaximusabsolutmaximus Posts: 3
    edited 2008-05-28 13:05
    Stephan,

    Thanks, I saw your project on the website but I was not able to find your source code so thanks. A few questions:
    1. How did you get a burst of 9000usec with the decimal value of 4254?
    2. Why did you pulsout the ON bursts on one pin and the OFF on a another pin?

    Thanks,
    George
  • stephenwagnerstephenwagner Posts: 147
    edited 2008-05-29 17:27
    George,

    The first thing the transmitter does is turn the modulated IR light ON, HIGH modpin.
    ·
    The second thing is PULSOUT 4254 delaypin. 4254 X 2 = 8508 uSec. This instruction leaves the light ON. It took about 492 uSec for the PULSOUT instruction to start the pulse out execution. 8508 + 492 = 9000 uSec.
    ·
    The third thing is to PULSOUT 2247 modpin. 2247 X 2 = 4494 uSec. This instruction turns the light off for 4494 or 4500 uSec. My measurements yielded 4500 uSec using PULSOUT of 2247. Remember the light is ON, the original condition of the mod pin is "1" high. PULSOUT will pulse out a "0" low for 4494 uSec.
    ·
    The last thing is to turn the light off LOW mod pin.
    ·
    All the information for the NEC protocol is in the light off time period. If you study the code, you will note in some cases there is no instruction to turn the light on. The PULSOUT mod pin turns the light OFF. The time it takes one PULSOUT mod pin to execute to the next PULSOUT mod pin is 572 uSec. 572 uSec of light on time. This is the shortest time possible with a BS2 and the associated instruction delay time. The NEC protocol specifies 560 uSec burst of light. I am only 12 uSec over. I just subtract this time from the light off period to compensate. I only needed to toggle a few bits remote bits The code can easily be modified to control all the bits.
    ·
    The below code is a complete transmitter less the constants and other things.
    ·
    HIGH mod 'Turn on Transmitter
    PULSOUT delaypin, 4254 ' 9000 uSec burst. On for 9000 uSec
    PULSOUT mod, 2247 'Off for 4500 Usec
    PULSOUT mod, codelow.BIT15 * adjust1 + adjust2 'turn light off
    PULSOUT mod, codelow.BIT14 * adjust1 + adjust2 'turn light off
    PULSOUT mod, codelow.BIT13 * adjust1 + adjust2
    .
    .
    .
    PULSOUT mod, codelow.BIT2 * adjust1 + adjust2
    PULSOUT mod, codelow.BIT1 * adjust1 + adjust2
    PULSOUT mod, codelow.BIT0 * adjust1 + adjust2
    PULSOUT delaypin, 99 '99 yields 560 uSec Last One
    LOW mod 'Turn transmitter off
    ·
    At the completion of each instruction, the light will turn on for 572 uSec.
    During the PULSOUT mod pin execution, the light will be off for 552/554 uSec or 1678 uSec. These are 12 uSec under the 565 or 1690 specified in the NEC protocol. A 572 burst of light followed by a 552/554 light off yields 1124/1126 uSec for a logical IR code of "0". A 572 uSec burst of light followed by 1678 uSec light off yields 2250 uSec for a logical IR code of "1".
    ·
    I hope this answers your questions.

    I will be happy to answer any further questions.

    SJW
  • stephenwagnerstephenwagner Posts: 147
    edited 2008-05-29 17:29
    George,

    The delaypin is just a dummy pin to kill time. This keeps the IR light on.

    I hope this helps more.



    SJW
  • absolutmaximusabsolutmaximus Posts: 3
    edited 2008-05-29 18:38
    Stephan,

    Thank you very much, now i just need to jam some code together and try it out...thanks again.

    George
  • stephenwagnerstephenwagner Posts: 147
    edited 2008-05-29 21:11
    George,

    The 38KHz modulator for the IR LED. Keep the ontime to 8.8 uSec and the off time to 17.5 uSec. 8.8 + 17.5 = 26.8 uSec.

    1 / 26.3 uSec = 38 KHz.

    The IR receivers like a 1/3 on and 2/3 off duty cycle IR 38 KHz modulator. The IR remotes that I have measured were all 1/3 on and 2/3 off. 33% duty cycle. I don't know why.

    There are some 555 timers circuits arround with a diode accross one of the two charging resistors to creat a time on and time off generator. Check the TI and or National application/data sheets.

    I used a modulator from rentron. it was closer to a 50% modulator however. It worked in my application.

    http://www.rentron.com/remote_control/TX-IR.htm


    SJW
Sign In or Register to comment.