NEC IR Protocol remote decoder, help me before I kill myself!


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: NEC IR Protocol remote decoder, help me before I kill myself!

    Quote Originally Posted by bogdan View Post
    the code was for a samsung tv .... close, but not the same like the nec protocol

    SAMSUNG IR protocol:
    http://www.samsung.com/global/busine...000_090108.pdf (check "Figure 1. IR Signal")



    NEC IR protocol:
    http://www.mcselec.com/index.php?opt...=223&Itemid=57

    ... the leader/header for nec should be 9msec

    change the
    DEFINE PULSIN_MAX 990 (try with 10% deviation... 900*1.1)
    - - - - - - - - - - - - - - - - - - - - -
    IF (Header < 810) OR (Header > 990) THEN GOTO IRIN (again the -/+10% deviation)
    Did you try this?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Dec 2004
    Location
    Scarborough UK
    Posts
    77


    Did you find this post helpful? Yes | No

    Default Re: NEC IR Protocol remote decoder, help me before I kill myself!

    cncmachineguy

    Yes I did, i still did not get valuses to match, I got values in the range of 552 to 614 and everything in between.
    Reading the datasheet & understanding it are two different things.

  3. #3
    Join Date
    Jan 2009
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: NEC IR Protocol remote decoder, help me before I kill myself!

    please let us now the model # of the remote

    (i will try to upload the codes into a universal remote and i will check the protocol later today)

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


    Did you find this post helpful? Yes | No

    Default Re: NEC IR Protocol remote decoder, help me before I kill myself!

    There are much better/faster ways to do this, but this should get you started with something that's fairly easy to understand.

    Assuming you have an NEC transmitter that outputs something like the top portion of the graphic below;

    Name:  NEC2.JPG
Views: 11449
Size:  33.3 KB



    This should return similar results to what's shown in the serial terminal window just above.
    Code:
    #CONFIG
      __config _XT_OSC & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    #ENDCONFIG
     
    DEFINE OSC 4
     
    Leader VAR WORD     ' will be up to 900 for a 9mS leader pulse
    BtnVal VAR BYTE[32] ' holds 32 pulse results
    DByte1 VAR BYTE     ' address byte
    DByte2 VAR BYTE     ' inverse of address byte
    DByte3 VAR BYTE     ' command byte
    DByte4 VAR BYTE     ' inverse of command byte
    X      VAR BYTE     ' loop count
     
    Main: 
      PULSIN PORTB.0,0,Leader  ' leader pulse is ~9mS low-going
      IF Leader < 850 THEN Main
     
      FOR X = 0 TO 31          ' grab 32 incoming pulses
          PULSIN PORTB.0,1,BtnVal(X) ' now measuring high-going pulse widths
      NEXT X
     
      ' now we'll decode 4 bytes from 32 pulses
      FOR X = 0 TO 7               ' sort 1st 8 pulses
          IF BtnVal[X] > 150 THEN  ' > 150 x 10uS = > 1.5mS pulse period
             DByte1.0[X]=1
          ELSE
             DByte1.0[X]=0
          ENDIF
      NEXT X
     
      FOR X = 8 TO 15              ' sort 2nd 8 pulses, etc....
          IF BtnVal[X] > 150 THEN
             DByte2.0[X-8]=1
          ELSE
             DByte2.0[X-8]=0
          ENDIF
      NEXT X
     
      FOR X = 16 TO 23
          IF BtnVal[X] > 150 THEN
             DByte3.0[X-16]=1
          ELSE
             DByte3.0[X-16]=0
          ENDIF
      NEXT X
     
      FOR X = 24 TO 31
          IF BtnVal[X] > 150 THEN
             DByte4.0[X-24]=1
          ELSE
             DByte4.0[X-24]=0
          ENDIF
      NEXT X
     
      HSEROUT [BIN8 DByte1,13,10,BIN8 DByte2," Address",13,10,13,10]
      HSEROUT [BIN8 DByte3,13,10,BIN8 DByte4," Command",13,10,13,10]
      PAUSE 1000
      GOTO Main
    Last edited by Bruce; - 30th August 2011 at 00:10.
    Regards,

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

  5. #5
    Join Date
    Dec 2004
    Location
    Scarborough UK
    Posts
    77


    Did you find this post helpful? Yes | No

    Default Re: NEC IR Protocol remote decoder, help me before I kill myself!

    Bruce, thanks for uploading that code, I am going to try the code on my next day off work and will report back, I've had a look and its well commented and I can understand it, so I have fingers crossed that it's going to work :-), I think where I am falling down is my poor understanding of math, eg the osc speed and its relation to ms's & pulsin, I just dont get that, anyway I'm going to give your code a good go, thanks again.

    Bogdan, I have attached my remote pictures & instruction PDF that came with it, thanks also for your help with this :-)
    Attached Images Attached Images   
    Attached Images Attached Images
    Last edited by Bonxy; - 29th August 2011 at 20:31.
    Reading the datasheet & understanding it are two different things.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,122


    Did you find this post helpful? Yes | No

    Default Re: NEC IR Protocol remote decoder, help me before I kill myself!

    Quote Originally Posted by Bonxy View Post
    I think where I am falling down is my poor understanding of math, eg the osc speed and its relation to ms's & pulsin
    Look at post #8. Also the manual at the Pulsin command explains why is that.

    Ioannis

  7. #7
    Join Date
    Dec 2004
    Location
    Scarborough UK
    Posts
    77


    Did you find this post helpful? Yes | No

    Default Re: NEC IR Protocol remote decoder, help me before I kill myself!

    Bruce, thank you :-)

    Your code worked perfectly at 4 mhz first go :-)

    So, I've hacked away at it all day and through trial & error and determination I have got it to work at 20mhz, It was a total pain I could not work out the math for the life of me, so I searched the forum and net, but everyone seems to have a different idea on how to work it out, in the end I resorted to trial & error but I got it to work at 20mhz.

    The repeatsub does not work correctly all the time, again I assum a timing error

    I show the results below for all to see, I've also tried to add the repeat (button held down) function with limited success, if you or anyone would care to comment on or improve the end result that would be awesom..

    '#CONFIG
    '__config _XT_OSC & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    '#ENDCONFIG
    'Defines for EasyPic3
    DEFINE LCD_DREG PORTB ' Define LCD registers and bits
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 2
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3
    INCLUDE "AllDigital.pbp" 'Set ALL ports to Digital i/o
    include "LCDDEFS.bas" 'easy lcd

    DEFINE OSC 20 'set osc to 20mhz

    Leader VAR WORD ' will be up to 900 for a 9mS leader pulse
    BtnVal VAR word[32] ' holds 32 pulse results 'NEEDS TO BE WORD VAR FOR 20Mhz
    DByte1 VAR BYTE ' address byte
    DByte2 VAR BYTE ' inverse of address byte
    DByte3 VAR BYTE ' command byte
    DByte4 VAR BYTE ' inverse of command byte
    i VAR BYTE ' loop count

    Main:

    PULSIN PORTC.0,0,Leader ' leader pulse is ~9mS low-going

    IF Leader < 4400 THEN goto Main 'use 850 for 4mhz, use 4400 for 20mhz

    FOR i = 0 TO 31 ' grab 32 incoming pulses
    PULSIN PORTC.0,1,BtnVal(i) ' now measuring high-going pulse widths

    if btnval(i) > 950 then goto repeatsub 'capture repeat pulse ?

    NEXT i



    ' now we'll decode 4 bytes from 32 pulses (address)
    FOR i = 0 TO 7
    IF BtnVal[i] > 350 THEN ' > use 150 for 4mhz, use 350 for 20mhz
    DByte1.0[i]=1
    ELSE
    DByte1.0[i]=0
    ENDIF
    NEXT i


    'now we'll decode 4 bytes from 32 pulses (command)
    FOR i = 16 TO 23
    IF BtnVal[i] > 350 THEN ' > use 150 for 4mhz, use 350 for 20mhz
    DByte3.0[i-16]=1
    ELSE
    DByte3.0[i-16]=0
    ENDIF
    NEXT i

    'show results on LCD, address on top line & command on bottom line
    Lcdout cmd,clss,cmd,movtoA2, "Address " , hex DByte1 'debug to LCD display
    lcdout cmd,movtoB2, "Command " , hex DByte3 'debug to LCD display

    'HSEROUT [BIN8 DByte1,13,10,BIN8 DByte2," Address",13,10,13,10]
    'HSEROUT [BIN8 DByte3,13,10,BIN8 DByte4," Command",13,10,13,10]
    PAUSE 200 'dont know why this is needed for it to work ?
    GOTO Main




    'we get to heare if button on remote is held down
    repeatsub:
    toggle porta.0 ' led to tell us that a button is held down (repeat)

    PAUSE 400 'only god knows why this is needed for it to work ?
    goto main
    return


    Thanks..
    Bruce
    Ioannas
    dhouston
    bogdan
    cncmachineguy
    jumper
    Reading the datasheet & understanding it are two different things.

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