Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:59 22 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : IR Remote Control Rx and Tx for Philips RC-5 Protocol.

Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2133
Posted: 08:16am 23 Sep 2024
Copy link to clipboard 
Print this post

To go with the NEC protocol here is Philips RC-5
Sub IR_RC5_Rx and Sub IR_RC5_Tx are the useful bits in this program.
The rest just reads and decodes the Manchester protocol, sending the result to the console.
Then transmits the IR code 3 seconds later to the device so you can verify that it is correct. The codes it produces match the published ones so it should be ok.

The older version of RC-5 sends a Start pulse, a Control bit to distinguish a double press from auto-repeat, a 5 bit device code and a 6 bit key code.
As that only gives 64 key codes the current version has a Field bit between the Start and Control bits to provide another 64 key codes.
Field = 1 for keys 0 to 63
Field = 0 for keys 64 to 127
Control alternates between 0 and 1 on each key press.

Sub IR_RC5_Tx should work with all the above but the devices I have (Philips audio system & Schaub Lorenz TV) both use Start = 1 & Field = 1 so the others are untested.
For old devices that don't use the Field bit set the Start bit to 0 and the Field bit to 1. The Field bit becomes the Start bit.

Usage: IR_RC5_Tx start, field, control, device, key
Eg: IR_RC5_Tx 1,0,17,63 turns on the sterio and IR_RC5_Tx 1,1,17,12 turns it off.

If you want to modify the subs for your own projects there are plenty of comments and diagnostic prints to help.
' "IR Philips RC-5 code Rx & Tx.bas"
'Option explicit
Dim integer RxPin=MM.Info(pinno GP1), TxPin=MM.Info(pinno GP0) ' set GPxx for IR Tx & Tx
Dim Integer N = 29 ' expected maximum number of transitions, plus a few

Dim integer m, b(N), c(N\2), dev, key, r(N*2), strt=1, Tend
Dim Float T
SetPin RxPin, intl, IR_RC5_Rx 'wait for IR activity to pull IRpin low
SetPin TxPin, DOUT : Dim integer ctrl '<-- only needed for Sub IR_RC5_Tx demo

Print " To send commands un-comment 2 lines in the loop at the end of the program then:-"
Print " Start = 1 for new RC-5, Start = 0 for original (obsolete) RC-5"
Print " Field = 1 for Key codes 0 to 63, Field = 0 for Key codes 64 to 127"
Print " Control toggle between 0 and 1 on each Key press to distinguish from auto-repeat"
Print " Device = device code, 0 to 31"
Print " Key = Key code, 0 to 63. Field = 0 shifts these up by 128" : Print
Print " Press a key on the IR remote control to record the RC-5 code" : Print

Sub IR_RC5_Rx
  T=Timer :Tend = T
  SetPin RxPin, off : SetPin RxPin, Din :m=1 :b(0)=0
 Do While m<(N-1)And(Timer-T<300) 'get pulses/pauses & convert to Manchester bits
  Do While (Pin(RxPin)=0(And(Timer-T<300) :Loop
  If (Timer-T)>2.2 Then Exit Do
  b(m)=1:If (Timer-T)>1.6 Then:Inc m :b(m)=1:EndIf
  T=Timer :Inc m
  Do While (Pin(RxPin)=1)And(Timer-T<300):Loop
  If (Timer-T)>2.2 Then Exit Do
   b(m)=0:If (Timer-T)>1.6 Then:Inc m :b(m)=0:EndIf
  T=Timer :Inc m
 Loop

 SetPin RxPin, off : b(N)=Timer-Tend : m=0 'disable interrupt while processing
'  Print :Print "IR BitStream - b() ";:Math V_Print b()
 If b(4)+b(5)+b(6)+b(7)+b(8)=0 Then GoTo no.data

 If b(N-2)=0 And b(N-3)=0 Then strt = 0 'detect obsolete RC-5 code (no field bit)
 If b(N-2)=1 Xor b(N-3)=1 Then strt = 1 'detect new RC-5 code (with field bit)
 If strt = 0 Then
  For m=(N-2) To 0 Step -1
   b(m+2)=b(m)
  Next
  b(0)=0 : b(1)=0
 EndIf
 m=2
 Do While m<(N) 'convert pairs of Manchester half-bits to ordinary bits
  If (b(m)=0)And(b(m+1)=1) Then c(m\2-1)=1
  If (b(m)=1)And(b(m+1)=0) Then c(m\2-1)=0
  Inc m, 2
 Loop
 Print "c()=bits  ";:Math V_print c()
 field=c(0): ctrl=c(1): dev=0: key=0

'ctrl toggles on each key press to distinguish autorepeat from double press
 For m=2 To 6:Inc dev,dev +c(m):Next 'assemble Device code
 For m=7 To 12:Inc key,key +c(m):Next 'assemble Key code

 If strt=1 Then Print "field";field;"  control";ctrl;"  dev";dev;"  key";key
 If strt=0 Then Print "old RC-5 no field.   control";ctrl;"  dev";dev;"  key";key

'  Pause 3000 : IR_RC5_Tx 1, field, ctrl, dev, key 'resend the received code after 3S
'  ctrl=Not ctrl

 no.data:
 T=0
 Math set 0, b()
 Math set 0, c()
 Pause 400 'block repeat codes
 SetPin RxPin, intl, IR_RC5_Rx 're-enable interrupt for next key

End Sub

Sub IR_RC5_Tx(strt, field, ctrl, dev, key) As integer
 strt=strt And 1 : field=field And 1 : ctrl=ctrl And 1 : dev=dev And 31 : key=key And 63
 Local integer ord(14), bs(900), m=0, n, z
 Math set 14, bs() 'load BitStream array with 36kHz half cycles (14uS)
 'assemble ordinary bit array
 For n=6 To 2 Step -1 : ord(n) = (dev >> m) And 1 : Inc m :Next
 m=0
 For n=12 To 7 Step -1 : ord(n) = (key >> m) And 1 : Inc m :Next
 If strt = 0 Then field = 1
 ord(0)=field : ord(1)=ctrl

'  Print "f";field,"c";ctrl,"dev";dev,"key";key,, "ord()";:Math V_print ord()' :Print
' Print "  b() ";:Math V_Print b()' :Print
'convert ordinary bits to pairs of Manchester half-bits and load into BitStream array -
'merging adjacent high or low pairs of half-bits into long highs or long lows,
' without causing inversions in the BitStream

'half cycle at 36kHz = 14uS = 64 or 65 half cycles per short pulse, 129 per long pulse
  m=0
 If strt=1 Then m=64 'Else m=1 'm=65 -> start pulse
 If (field=1)And(strt=1) Then : bs(65)=889 :Inc m,65 : EndIf
 If (field=0)And(strt=1) Then : Inc m,64 : bs(m)=889 : EndIf

 If strt = 0 Then m=65

 For n=0 To 11
  If (ord(n)=1)And(ord(n+1)=1) Then : bs(m)=889 : Inc m,64 : EndIf
  If (ord(n)=1)And(ord(n+1)=0) Then : Inc m,64 : bs(m)=889 : EndIf
  If (ord(n)=0)And(ord(n+1)=1) Then : bs(m)=1778 : Inc m,64 : EndIf
  If (ord(n)=0)And(ord(n+1)=0) Then : bs(m)=889 : Inc m,64 : EndIf
 Next
 Inc m

'  BitBang BitStream TxPin, m, bs() 'for ARMMiteF4
 Device BitStream TxPin, 832+66*strt, bs() 'for PicoMite
 Pause 88
 Device BitStream TxPin, 832+66*strt, bs() 'for PicoMite
 Pin(TxPin) = 0 'ensure correct polarity for next run
' Print : Math V_print bs() :Print

End Sub

Do 'un-comment the next 2 lines to send data
 'Input "Enter RC-5 Data:- Start, Field, Control, Device, Key ";strt,field,ctrl,dev,key
 'IR_RC5_Tx strt,field,ctrl,dev,key
 Pause 400
Loop
End

Getting the BitStream to work properly with Manchester half-bits realy taxed my geriatric brain. Senility is advancing.

Edit 29/09/2024
The code above has been edited. A closer inspection of the output for the old version of RC-5 was not quite right. Should now be ok, but still can't test on an actual device.
However sending from one Pico to another does work and scope pics of the data appear to match the specification.

Also added automatic detection of old RC-5 to IR_RC5_Rx Sub.
Output when receiving.
RUN
Press a key on the IR remote control to record the RC-5 code
field 1  control 0  dev 1  key 53
field 1  control 1  dev 1  key 0
field 1  control 0  dev 17  key 63
field 1  control 1  dev 17  key 7
field 1  control 0  dev 18  key 63
old RC-5 no field.   control 1  dev 28  key 0
field 0  control 0  dev 20  key 63
field 0  control 1  dev 20  key 8
field 0  control 0  dev 20  key 54
field 1  control 1  dev 20  key 63

Edited 2024-09-29 14:31 by phil99
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2133
Posted: 08:27am 01 Oct 2024
Copy link to clipboard 
Print this post

RC-6 Rx and Tx
Although I don't have any RC-6 devices to test it on scope traces of the output match those published by others on the net.
Tested ok going from one PicoMite to another.
RC-6 has provision for 8 different modes but it appears all consumer devices use mode 0. There is little I could find on the other modes so Tx only supports mode 0.
The Rx Sub should however be able to show the mode number other modes but might not decode them correctly.
' "IR Philips RC-6 Mode 0 Rx & Tx.bas"
'Option explicit
Dim integer RxPin=MM.Info(pinno GP0), TxPin=MM.Info(pinno GP1) ' set GPxx for IR Tx & Tx
Dim Integer N = 44 ' expected maximum number of transitions, plus a few

Dim integer m, b(N), c(N\2), dev, key, r(N*2), Tend, Toggle, Type'Type = RC6 Mode or Field
Dim Float T
SetPin RxPin, intl, IR_RC6_Rx 'wait for IR activity to pull IRpin low
SetPin TxPin, DOUT

Print " To send commands un-comment the lines near the end of the program then:-"
Print " Toggle toggles between 0 and 1 on each Key press to distinguish from auto-repeat"
Print " Device = device code, 0 to 255"
Print " Key = Key code, 0 to 255." : Print
Print " Press a key on the IR remote control to record the RC-6 code" : Print

Sub IR_RC6_Rx
 T=Timer :Tend = T
 SetPin RxPin, off : SetPin RxPin, Din :m=1 :b(0)=0

 Do While m<(N-1)And(Timer-T<300) 'get pulses/pauses & convert to Manchester bits
  Do While (Pin(RxPin)=0)And(Timer-T<300) :Loop
  If (Timer-T)>3 Then Exit Do
  b(m)=1
  If m=11 Then 'toggle is double normal pulse
    If (Timer-T)>1.2 Then:Inc m :b(m)=1:EndIf
   Else
    If (Timer-T)>0.66 Then:Inc m :b(m)=1:EndIf
  EndIf
  T=Timer :Inc m
  Do While (Pin(RxPin)=1)And(Timer-T<300):Loop
   If (Timer-T)>1.6 Then Exit Do
   b(m)=0
  If m=10 Then 'toggle is double normal pause
    If (Timer-T)>1.33 Then:Inc m :b(m)=0:EndIf
   Else
    If (Timer-T)>0.66 Then:Inc m :b(m)=0:EndIf
  EndIf
  T=Timer :Inc m
 Loop

 SetPin RxPin, off' : b(N)=Timer-Tend : m=0 'disable interrupt while processing
 If b(4)+b(5)+b(6)+b(7)+b(8)=0 Then GoTo no.data
'  Print :Print "IR BitStream - b() ";:Math V_Print b()

 m=2
 Do While m<(N) 'convert pairs of Manchester half-bits to ordinary bits (oposite of RC-5)
  If (b(m)=0)And(b(m+1)=1) Then c(m\2-1)=0 '01 = 0
  If (b(m)=1)And(b(m+1)=0) Then c(m\2-1)=1 '10 = 1
  Inc m, 2
 Loop
 Print "c()=bits  ";:Math V_print c()
 Type = c(1)*4+c(2)*2+c(3) : toggle=c(4) : dev=0 : key=0

 'ctrl toggles on each key press to distinguish autorepeat from double press
 For m=5 To 12 : Inc dev,dev + c(m) : Next 'assemble Device code
 For m=13 To 20 : Inc key,key + c(m) : Next 'assemble Key code

 Print "Mode";type;"  Toggle";toggle;"  Dev";dev;"  Key";key :Print

'un-comment the following lines to re-transmit the received code to verify operation
'  Pause 3000
'  IR_RC6_Tx 1, toggle, dev, key 'resend the received code after 3S
'  Pause 83
'  IR_RC6_Tx 1, toggle, dev, key 'resend the received code after 3S
'  toggle=Not toggle

 no.data:
 T=0
 Math set 0, b()
 Math set 0, c()
 Pause 400 'block repeat codes
 SetPin RxPin, intl, IR_RC6_Rx 're-enable interrupt for next key

End Sub

Sub IR_RC6_Tx(toggle, dev, key) As integer
 toggle=toggle And 1 : dev=dev And 255 : key=key And 255 ': type=type And 7 'only uses Mode 0
 Local integer ord(19), bs(1993), m=0, n, z
 Math set 14, bs() 'load BitStream array with 36kHz half cycles (14uS)
 'assemble ordinary bit array
'  For n=3 To 0 Step -1 : ord(n) = (dev >> m) And 1 : Inc m :Next
'  ord(4)=toggle
 m=0 : For n=15 To 8 Step -1 : ord(n) = (key >> m) And 1 : Inc m :Next
 m=0 : For n=7 To 0 Step -1 : ord(n) = (dev >> m) And 1 : Inc m :Next

 Print "toggle";toggle,"dev";dev,"key";key,, "ord()  ";:Math V_print ord()
'convert ordinary bits to pairs of Manchester half-bits and load into BitStream array -
'merging adjacent high or low pairs of half-bits into long highs or long lows,
' without causing inversions in the BitStream

'half cycle at 36kHz = 14uS = 32 half cycles per short pulse, 65 per long pulse
  bs(193)=1333 : bs(225)=444 : bs(257)=444' : bs(289)=444 ' Start pulse + Mode=0 3 bits
 If toggle=0 Then bs(289)=889 'long pause - long pulse
 If toggle=1 Then bs(355)=889 'long pulse - long pause
 m=355
 If (toggle=1) And (ord(0)=1) Then bs(355)=444 : Inc m,32 : EndIf
 If (toggle=1) And (ord(0)=0) Then bs(355)=1333 : Inc m,32 : EndIf
 If (toggle=0) And (ord(0)=1) Then Inc m,32 : bs(m)=444 : EndIf
 If (toggle=0) And (ord(0)=0) Then bs(355)=444 :Inc m,32 : EndIf

 For n=0 To 15
  If (ord(n)=1)And(ord(n+1)=1) Then : bs(m)=444 : Inc m,32 : EndIf
  If (ord(n)=1)And(ord(n+1)=0) Then : bs(m)=889 : Inc m,32 : EndIf
  If (ord(n)=0)And(ord(n+1)=1) Then : Inc m,32 : bs(m)=444 : EndIf
  If (ord(n)=0)And(ord(n+1)=0) Then : bs(m)=444 : Inc m,32 : EndIf
 Next

'  BitBang BitStream TxPin, 868, bs() 'for ARMMiteF4
 Device BitStream TxPin, 868, bs() 'for PicoMite
 Pin(TxPin) = 0 'ensure correct polarity for next run
 Pause 83
 Device BitStream TxPin, 868, bs() 'for PicoMite
 Pin(TxPin) = 0 'ensure correct polarity for next run
'  Print : Math V_print bs() :Print

End Sub

Do 'un-comment the next 2 lines to send data
'  Input "Enter RC-6 Data:- toggle, Device, Key "; toggle,dev,key
'  IR_RC6_Tx toggle,dev,key
'  toggle = Not toggle
 Pause 300
Loop
End

Tx usage:-
IR_RC6_Tx toggle, device, key
.
Edited 2024-10-01 22:27 by phil99

Footnote added 2024-10-03 11:36 by phil99
Sub IR_RC6_Tx needed some tidying up, so here it is.
Sub IR_RC6_Tx(toggle, dev, key) As integer
 toggle=toggle And 1 : dev=dev And 255 : key=key And 255 'only uses Mode 0
 Local integer ord(16), bs(870), m=0, n
 Math set 14, bs() 'load BitStream array with 36kHz half cycles (14uS)
 'assemble ordinary bit array
 m=0 : For n=15 To 8 Step -1 : ord(n) = (key >> m) And 1 : Inc m :Next
 m=0 : For n=7 To 0 Step -1 : ord(n) = (dev >> m) And 1 : Inc m :Next

 Print "toggle";toggle,"dev";dev,"key";key,, "ord()  ";:Math V_print ord()
 'fixed 3 bit Field / Mode number = 0 for consumer electronics
 'convert ordinary bits to pairs of Manchester half-bits and load into BitStream array -
 'merging adjacent high or low pairs of half-bits into long highs or long lows,
 ' without causing inversions in the BitStream

 'half cycle at 36kHz = 14uS = 32 half cycles per short pulse, 65 per long pulse
  bs(193)=1333 : bs(225)=444 : bs(257)=444 ' Start pulse + Mode=0 3 bits
 If toggle=0 Then bs(289)=889 'long pause - long pulse for toggle bit
 If toggle=1 Then bs(355)=889 'long pulse - long pause
 m=355
 If (toggle=1) And (ord(0)=1) Then bs(355)=444
 If (toggle=1) And (ord(0)=0) Then bs(355)=1333
 If (toggle=0) And (ord(0)=1) Then bs(m+32)=444
 If (toggle=0) And (ord(0)=0) Then bs(355)=444
 Inc m,32

 For n=0 To 15
  If (ord(n)=1)And(ord(n+1)=1) Then bs(m)=444
  If (ord(n)=1)And(ord(n+1)=0) Then bs(m)=889
  If (ord(n)=0)And(ord(n+1)=1) Then bs(m+32)=444
  If (ord(n)=0)And(ord(n+1)=0) Then bs(m)=444
  Inc m,32
 Next

'  BitBang BitStream TxPin, 868, bs() 'for ARMMiteF4
 Device BitStream TxPin, 868, bs() 'for PicoMite
 Pin(TxPin) = 0 'ensure correct polarity for next run
 Pause 83
 Device BitStream TxPin, 868, bs() 'for PicoMite
 Pin(TxPin) = 0 'ensure correct polarity for next run
'  Print : Math V_print bs() :Print

End Sub
 
Marcel27

Regular Member

Joined: 13/08/2024
Location: Netherlands
Posts: 53
Posted: 07:06am 02 Oct 2024
Copy link to clipboard 
Print this post

Thanks phil99, I love this timing stuff.

  Quote  Getting the BitStream to work properly with Manchester half-bits realy taxed my geriatric brain. Senility is advancing.


Yes! I know how it feels, I've seen man in white coats and dispensing yellow pills to keep me stable at some programming jobs.  
If you use AI, you lose your mind.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6764
Posted: 07:18am 02 Oct 2024
Copy link to clipboard 
Print this post

The answer is (usually) Dried Frog Pills, I believe. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2133
Posted: 12:55am 11 Oct 2024
Copy link to clipboard 
Print this post

This months edition of Silicon Chip has an article that includes a description of IR protocols. From that I see that my RC-6 Rx and Tx Subs aren't quite right. The start sequence includes a Bit that I missed.

Here is an updated version.
Not having anything to test it on is a bit of a problem so any feedback from anyone that does have RC-6 equipment would be welcome.
' "IR Philips RC-6 Mode 0 Rx & Tx.bas"
'Option explicit
Dim integer RxPin=MM.Info(pinno GP0), TxPin=MM.Info(pinno GP1) ' set GPxx for IR Rx & Tx
Dim Integer N = 48 ' expected maximum number of transitions, plus a few

Dim integer m, b(N), c(N\2), dev, key, r(N*2), Tend, Toggle, Type'Type = RC6 Mode or Field
Dim Float T
'SetPin RxPin, off 'for RP2350 if all pins have been set to DIN Pullup at start-up.
SetPin RxPin, intl, IR_RC6_Rx 'wait for IR activity to pull IRpin low
'SetPin TxPin, off 'for RP2350 if all pins have been set to DIN Pullup at start-up.
SetPin TxPin, DOUT

Print " To send commands un-comment the lines near the end of the program then:-"
Print " Toggle toggles between 0 and 1 on each Key press to distinguish from auto-repeat"
Print " Device = device code, 0 to 255"
Print " Key = Key code, 0 to 255." : Print
Print " Press a key on the IR remote control to record the RC-6 code" : Print

Sub IR_RC6_Rx
 SetPin RxPin, off : SetPin RxPin, Din :m=1 :b(0)=0 :T=Timer
 Do While (Pin(RxPin)=0) And (Timer-T<300) :Loop 'skip lead-in pulse
 Do While (Pin(RxPin)=1) And (Timer-T<300) :Loop
 Do While m<(N-1) And (Timer-T<300)  'get pulses/pauses & convert to Manchester bits
  Do While (Pin(RxPin)=0) And (Timer-T<300) :Loop
  If (Timer-T)>5 Then Exit Do
  b(m)=1
  If m=10 Or m=11 Then Inc T,0.444 'toggle is 444uS longer than normal pulse
  If (Timer-T)>0.66 Then : Inc m : b(m)=1 : EndIf
  T=Timer :Inc m
  Do While (Pin(RxPin)=1) And (Timer-T<300):Loop
  If (Timer-T)>1.9 Then Exit Do
  b(m)=0
  If m=10 Or m=11 Then Inc T,0.444 'toggle is 444uS longer than normal pause
  If (Timer-T)>.66 Then : Inc m :b(m)=0 : EndIf
  T=Timer :Inc m
 Loop

 SetPin RxPin, off 'disable interrupt while processing
 If b(6)+b(7)+b(8)+b(9)=0 Then GoTo no.data
'  Print :Print "IR BitStream - b() ":Math V_Print b()

 m=2
 Do While m<(N) 'convert pairs of Manchester half-bits to ordinary bits (oposite of RC-5)
  If (b(m)=0)And(b(m+1)=1) Then c(m\2-1)=0 '01 = 0
  If (b(m)=1)And(b(m+1)=0) Then c(m\2-1)=1 '10 = 1
   Inc m, 2
 Loop

'  Print "c()=bits  ";:Math V_print c()
 Type = c(1)*4+c(2)*2+c(3) : toggle=c(4) : dev=0 : key=0

 'Toggle toggles on each key press to distinguish autorepeat from double press
 For m=5 To 12 : Inc dev,dev + c(m) : Next 'assemble Device code
 For m=13 To 20 : Inc key,key + c(m) : Next 'assemble Key code

 Print "Received:- Type";type;"  Toggle";toggle;"  Dev";dev;"  Key";key :Print

'un-comment the following lines to re-transmit the received code to verify operation
'  Pause 3000 : Print "re-sendimg above codes, with Type = 0"
'  IR_RC6_Tx toggle, dev, key 'resend the received code after 3S
'  Pause 83
'  IR_RC6_Tx toggle, dev, key 'resend the received code after 3S
'  toggle=Not toggle

 no.data:
 T=0
 Math set 0, b()
 Math set 0, c()
 Pause 400 'block repeat codes
 SetPin RxPin, intl, IR_RC6_Rx 're-enable interrupt for next key

End Sub

Sub IR_RC6_Tx(toggle, dev, key) As integer
 toggle=toggle And 1 : dev=dev And 255 : key=key And 255 'only uses Field=0
 Local integer ord(16), bs(900), m=0, n
 Math set 14, bs() 'load BitStream array with 36kHz half cycles (14uS)
 'assemble ordinary bit array
 m=0 : For n=15 To 8 Step -1 : ord(n) = (key >> m) And 1 : Inc m :Next
 m=0 : For n=7 To 0 Step -1 : ord(n) = (dev >> m) And 1 : Inc m :Next

 'Print "ord()  ";:Math V_print ord()
 'fixed 3 bit Field / Mode number = 0 for consumer electronics
 'convert ordinary bits to pairs of Manchester half-bits and load into BitStream array -
 'merging adjacent high or low pairs of half-bits into long highs or long lows,
 ' without causing inversions in the BitStream

 'half cycle at 36kHz = 14uS = 32 half cycles per short pulse, 65 per long pulse
  bs(193)=889 : bs(225)=889 : bs(257)=444 : bs(289)=444
   ' Leader pulse + Start bit=1 + Mode=0 3 bits
 If toggle=0 Then bs(321)=889 'long pause - long pulse for toggle bit
 If toggle=1 Then bs(387)=889 'short pulse+long pulse - long pause
 m=387
 If toggle=0 And ord(0)=0 Then bs(m)=444
 If toggle=1 And ord(0)=1 Then bs(m)=889
 If toggle=1 And ord(0)=0 Then bs(m)=1333
 If toggle=0 And ord(0)=1 Then bs(m+32)=444
 Inc m,32

 For n=0 To 15
  If ord(n)=ord(n+1) Then bs(m)=444
  If ord(n)=1 And ord(n+1)=0 Then bs(m)=889
  If ord(n)=0 And ord(n+1)=1 Then bs(m+32)=444
  Inc m,32
 Next

'  BitBang BitStream TxPin, 900, bs() 'for ARMMiteF4
 Device BitStream TxPin, 900, bs() 'for PicoMite
 Pin(TxPin) = 0 'ensure correct polarity for next run
 Pause 5
 Device BitStream TxPin, 900, bs() 'for PicoMite
 Pin(TxPin) = 0 'ensure correct polarity for next run
'  Print : Math V_print bs() :Print

End Sub

dev = 128 : key = 0
Do 'un-comment the next line to send data
'  Input "Enter RC-6 Data:- toggle, Device, Key "; toggle,dev,key
 IR_RC6_Tx toggle,dev,key
 Print "Sent:- toggle";toggle,"dev";dev,"key";key
 Inc key
 Pause 2000
 IR_RC6_Tx toggle,dev,key
 Print "Sent:- toggle";toggle,"dev";dev,"key";key
 Inc dev
 Pause 2000
 toggle = Not toggle

Loop
End

Edited 2024-10-11 11:45 by phil99

Footnote added 2024-10-12 21:48 by phil99
Noticed some redundant variables and commands left over from development.

in this line near the start:
Dim integer m, b(N), c(N\2), dev, key, r(N*2), Tend, Toggle, Type'Type = RC6 Mode or Field
delete:
r(N*2), Tend,

And near the end of Sub IR_RC6_Rx remove:
Math set 0, b()
Math set 0, c()


Footnote added 2024-10-13 16:38 by phil99
Red Face Time!

Math set 0, b()

does serve a purpose. As the number of transitions for a fixed number of bits can vary in Manchester encoded data, there can be a left-over bit or two in b() from the previous IR input.
This can result in the last bit of the Key code being a 0 instead of 1.

However you don't need to set the whole array to 0. Replacing Math set 0, b() with b(43)=0 is all that is needed to fix it.

Footnote added 2024-10-13 22:16 by phil99
Bought a universal remote control and programmed it for a Philips RC-6 TV and Sub IR_RC6_Rx outputs the correct codes for all the buttons!
When those codes are fed into Sub IR_RC6_Tx the Rx Sub repeats them so it all works.
 
Marcel27

Regular Member

Joined: 13/08/2024
Location: Netherlands
Posts: 53
Posted: 09:26am 11 Oct 2024
Copy link to clipboard 
Print this post

At the moment I do some reading about the NEC protocol. This is very good information at a level that I can understand.  

The reason for this is that I bought a beautiful vintage amplifier, HK6350R, without a remote. The device had some strange problems, the volume runs high or low at random or dropped random in standby mode. The problem was the M50761 processor IC201. After I removed this chip everything worked normal albeit without remote control.

Now I'm trying to add "something" to this amplifier to get the simple remote function for volume and standby back. I can drop in an Pico or Arduino but I also have some PIC-controllers lying around that I can use, such as the PIC10F200. A simple little controller.

[Edit:start]
But I will start with the Pico and MMbasic for a faster result. What the hack cost a Pico these days.[Edit:end]

I'll keep you posted and see where the ship ends up. I'm retired and have far too many "projects" again.


Edited 2024-10-11 19:34 by Marcel27
If you use AI, you lose your mind.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2133
Posted: 12:22pm 11 Oct 2024
Copy link to clipboard 
Print this post

The NEC protocol is a good choice, used on almost everything.
The MMBasic version on this thread  can record the required button codes of whatever spare remote you have. Those codes can then be programmed to trigger what ever output you need.
 
EDNEDN
Senior Member

Joined: 18/02/2023
Location: United States
Posts: 117
Posted: 02:51pm 11 Oct 2024
Copy link to clipboard 
Print this post

@Marcel27   Please check out the JP-1 forums at http://www.hifi-remote.com/forums/

I've been a JP-1 user for 20 years.   It is absolutely fantastic to be able to put any function of any device anywhere on your remote.     You get complete control of things like Volume Punch Through and Channel Punch Through.   (Where regardless of what device the remote is talking to...  Those buttons are hard assigned to a particular device.)

It is very possible they have your device's remote codes stored in their library and you just need to load them onto a JP-1 compatible remote.    

And you can get a 5 device JP-1 compatible remote on eBay for $7 or $8 without even trying for a good deal.   I primarily use these:

https://www.ebay.com/itm/286050799445

(And incidentally...   If they don't have your device in the library, there are ways to have a JP-1 remote brute force send all possible command codes to your device to find the values you need to program into your remote.)
Edited 2024-10-12 01:13 by EDNEDN
 
Marcel27

Regular Member

Joined: 13/08/2024
Location: Netherlands
Posts: 53
Posted: 06:11pm 11 Oct 2024
Copy link to clipboard 
Print this post

@EDNEDN. If the idea I have in mind works, I can program the code from my HK AVR145 remote for volume + and - and Pon, Standby in the pico and use my HK AVR145 remote for the HK6350R. The controller chip M50761 I removed from the HK6350R controlled only volume and standby/pon and did no security checks. I can even use an Onkyo amplifier remote. The only thing I have to do is to integrate the pico in the HK6350R with all the klimbim. The HK AVR145 or HK6350R never run simultaneously and when they do I use an unused device code e.g. TAPE device button.

Thanks anyway for the information   , I'll check it out.

Marcel
If you use AI, you lose your mind.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024