Programmable RC-5 Remote Control

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Programmable RC-5 Remote Control

Postby Sean » Fri Oct 29, 2010 10:09 am

Programmable RC-5 System

Introduction
This article describes how the new Infra-Red RC-5 E-block (EB-060) can be used with Flowcode to develop a remote control device with the ability to learn codes from other handsets.

The RC-5 E-block contains the hardware required to transmit and receive RC-5 encoded infrared signals.

In this application the transmit channel is used to transmit individual codes allocated to each of the numeric keys on a keypad. The receive channel can be used to allow individual keys to 'learn' new messages (codes) from existing, compatible, equipment handsets.

System3.jpg
System3.jpg (32.02 KiB) Viewed 13707 times


Component
The example program attached to this article uses a Flowcode Custom Component C file (also supplied) to control the EB-060 hardware.
The code contains definitions to allow this application to run on a PIC16F877A with a 19.6608MHz crystal.

ProgRC5_1.fcf
(20.44 KiB) Downloaded 1093 times

PIC_Custom.c
(13.66 KiB) Downloaded 721 times

A fully integrated Flowcode RC-5 component will be available in the near future.

Custom code
To allow Flowcode to access the macros in the custom component, the attached PIC_custom.c file must be saved into the Components folder of the Flowcode installation. There will already be a file named PIC_custom.c in the folder, which should be renamed or moved before copying the new file into the folder.

Hardware
The EB-060 should be connected to Port B and configured as follows:
A wire link in the J9 sockets between pins 0 and 6.
The input selector jumper on J6.
The J8 jumper in the OFF position.
The J2 jumper in the 5V position.

The LCD E-Block (if used) should be connected to Port C
The Keypad E-Block should be connected to Port D

Program
The example program accompanying this article uses a keypad and (optional) LCD E-block to represent a traditional remote handset arrangement.

A previous article "RC5 remote control" explained the basics of the RC-5 protocol, which will not be covered in this article.

BlockDiagram.jpg
BlockDiagram.jpg (8.69 KiB) Viewed 13707 times


Default settings
On power-up the keys default to the typical values used for a main television (address = 0; command = key value). Pressing any of the numeric keys will cause the corresponding message to be transmitted.

Transmit mode
The example program handles each key press individually so the toggle bit changes state as each message is transmitted. The program can be modified to allow key presses to auto-repeat (volume control), transmitting repeated messages, with a constant toggle bit value, while a key is being pressed.

Learning mode
The program allows codes from existing, RC-5 compatible handsets to be detected and allocated to individual keys on an EB-014 keypad E-block. Codes for multiple types of equipment (different address values) can be acquired as long as they are all RC-5 compatible. The keys can then be used to control the transmission of each message (the program can be easily modified to use alternative input devices, or internal microcontroller events, to transmit each message).

The program uses the # key to toggle between 'Transmit' and 'Learn' mode. To prevent accidental re-programming, when the # key is used to enter programming mode, it must be followed by the * key. The # key can be used at any time to return to transmit mode.

When in 'Learn' mode, press the key to be re-programmed. Confirmation of the selected key will appear on the LCD (if it is being use).

Point a handset at the receiver on the RC-5 E-block and press the handset button that you want the system to learn. If the message is detected correctly, the values are assigned to the selected key and the system returns to transmit mode.

Further development

The system does not support auto-repeated transmission of messages while a key is held down. This feature may be required for functions like volume control. The program can be modified to continually transmit a message, at the RC-5 repeat rate (8 messages per second), with the toggle bit set at the same value for each transmission, while a button is being pressed.

Codes taught to the system are stored in RAM and are only retained while power is applied. The program can be modified to store alternative codes in EEPROM, and to search for them on power-up, so they can be retained indefinitely.

The program can be modified to accept signals from additional or alternative input devices to control system setup and message transmission.

Sparkoids
Posts: 267
Joined: Mon Sep 14, 2009 10:34 am
Has thanked: 30 times
Been thanked: 19 times
Contact:

Re: Programmable RC-5 Remote Control

Postby Sparkoids » Wed Nov 10, 2010 6:59 am

Hi Sean,

Another adaptation of RC5 is the Philips extension that is also used by Sky TV remote controls amongst others.

http://www.arduino.cc/cgi-bin/yabb2/YaB ... 1231706417

Can your code be modified to run these remotes as well?

Thanks for this stuff anyway!

James :-}

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8615
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2480 times
Been thanked: 3564 times
Contact:

Re: Programmable RC-5 Remote Control

Postby medelec35 » Wed Jan 05, 2011 1:24 am

Thanks Sean. This is a great article!
What would make it even better is if it will work for 18F4455 :P
Unfortunately I can only change defines like tmr0 to tmr0l
Since option_reg does not exist within 18F4455 not sure how to proceed any further.
would you be able to produce a PIC_Custom.c file for my target device,
Or post how It can be adapted for my device please?
Would like to get this working with my IrDA board EB012.
Thanks again.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Programmable RC-5 Remote Control

Postby Sean » Wed Jan 05, 2011 10:02 am

The 877 OPTION_REG is used to swap signal edge causing an INT interrupt (so every edge is detected). This feature is available in the INTCON2 register of the 4455.

The timer values used in the state machine macro will depend on the clock frequency and prescaler being used with TMR0.

the timer should be set to operate in 8-bit mode with the lowest prescaler value that will allow an overflow period greater than 2222us.

When receiving pulses, the timer should be pre-loaded with an initial offset value that will cause an overflow after 2222us (the longest allowable pulse width).
The timer overflow flag is used to confirm that a count is not valid - but does not generate an interrupt.

The important detection periods are:
444us (minimum pulse width)
1332us (change from short to long pulse)
2222us (maximum pulse width)

Remember: the values read back from the timer will include the initial offset value.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8615
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2480 times
Been thanked: 3564 times
Contact:

Re: Programmable RC-5 Remote Control

Postby medelec35 » Wed Jan 05, 2011 11:13 am

Thanks for your reply Sean.
I have edited PIC_Custom.c for the 4455, but still fails to compile.

Code: Select all

//common defines
#define MX_RC5_TIMER_PRELOAD   85         //Auto added to timer count
#define MX_RC5_TIMER_REGISTER   tmr0l         //Timer count register
#define MX_RC5_TIMER_TOUTREG   intcon
#define MX_RC5_TIMER_TOUTBIT   TMR0IF
#define MX_RC5_TIMER_ENREG      intcon
#define MX_RC5_TIMER_ENVAL      0x05         //Prescaler for timer
#define MX_RC5_INT_EDGEREG      intcon2
#define MX_RC5_INT_EDGEBIT      intedg0
#define MX_RC5_INT_PORT         portb
#define MX_RC5_INT_TRIS         trisb
#define MX_RC5_INT_PIN         0
#define MX_RC5_INT_ENREG      intcon
#define MX_RC5_INT_ENBIT      INT0IE
#define MX_RC5_INT_FLAGREG      intcon
#define MX_RC5_INT_FLAGBIT      INT0IF
#define MX_RC5_SIGNAL_INVERT   1
#define MX_RC5_UPPER_WIDTH      255            //2222us Approx - Must be over 1778us
#define MX_RC5_LOWER_WIDTH      119            //444us Approx - Must be under 889us
#define MX_RC5_CUTOFF_WIDTH      187            //1334us Approx - Must be around 1333us
#define MX_RC5_TX_TRIS         trisb
#define MX_RC5_TX_PORT         portb
#define MX_RC5_TX_PIN         7
#define MX_RC5_PWM            1
#define MX_RC5_PWM_PERIOD      33
#define MX_RC5_PWM_SCALER      5
#define MX_RC5_PWM_CHANNEL      1


All display of errors are suppressed, So maybe there are too many?
I am just getting:

Code: Select all

Launching the compiler...

C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\BoostC\boostc.pic18.flowcode.exe -v -t PIC18F4455 "ProgRC5_1.c"



.

Return code = 1



Flowcode was unable to compile the flowchart's C code due to the following errors:





If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.



FINISHED

Would you mind looking at all my alterations please?
Attachments
ProgRC5_1.c
(35.83 KiB) Downloaded 367 times
PIC_Custom.c
(13.66 KiB) Downloaded 324 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Programmable RC-5 Remote Control

Postby Sean » Wed Jan 05, 2011 1:39 pm

Compilation succeeds if intedg0 is changed to INTEDG0.

I am not able to do any hardware testing at the moment.

If it's any help, the original MIAC RC5 article program contains the same basic receiver program (written in Flowcode) and compiled for the 18F4455. Timing and timer configuration details might be useful and are based on a 48MHz clock.

Note: The signal is inverted in the MIAC application, and connected to INT2, so the INT details should not be used for a non-MIAC application.
These users thanked the author Sean for the post:
medelec35 (Wed Jan 05, 2011 2:16 pm)
Rating: 5%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8615
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2480 times
Been thanked: 3564 times
Contact:

Re: Programmable RC-5 Remote Control

Postby medelec35 » Wed Jan 05, 2011 2:42 pm

Thanks Sean.
The unusual thing is after the suggested change, errors now show, so does not compile like your flowchart does.
I got:

Code: Select all

ProgRC5_1 for 18F4455.c
Starting preprocessor: C:\PROGRA~2\MATRIX~1\FLOWCO~1\BoostC\pp.exe "D:\Flowcode V4 Install and  Examples and Drivers\ProgRC5_1 for 18F4455.c" -i C:\PROGRA~2\MATRIX~1\FLOWCO~1\BoostC\include -d _PIC18F4455 -la -c2 -o "D:\Flowcode V4 Install and  Examples and Drivers\ProgRC5_1 for 18F4455.pp" -v -d _BOOSTC -d _PIC18

D:\Flowcode V4 Install and  Examples and Drivers\ProgRC5_1 for 18F4455.c(273): Illegal redefinition of symbol: MX_RC5_TIMER_REGISTER
D:\Flowcode V4 Install and  Examples and Drivers\ProgRC5_1 for 18F4455.c(276): Illegal redefinition of symbol: MX_RC5_TIMER_ENREG
D:\Flowcode V4 Install and  Examples and Drivers\ProgRC5_1 for 18F4455.c(278): Illegal redefinition of symbol: MX_RC5_INT_EDGEREG
D:\Flowcode V4 Install and  Examples and Drivers\ProgRC5_1 for 18F4455.c(279): Illegal redefinition of symbol: MX_RC5_INT_EDGEBIT
D:\Flowcode V4 Install and  Examples and Drivers\ProgRC5_1 for 18F4455.c(284): Illegal redefinition of symbol: MX_RC5_INT_ENBIT
D:\Flowcode V4 Install and  Examples and Drivers\ProgRC5_1 for 18F4455.c(286): Illegal redefinition of symbol: MX_RC5_INT_FLAGBIT

6 errors detected
Error: preprocessing error

failure

Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:


If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.

FINISHED

After looking at the C file, it looks like its picking up both altered and pre-altered PIC_Custom.c,
So had a look at custom code within Flowchart and that look fine.
Custom code 18F4455.jpg
Custom code 18F4455.jpg (126.07 KiB) Viewed 13362 times

Also how would you know whether to use upper or lower case, as there is a mixture?
Attachments
ProgRC5_1 for 18F4455.c
(35.95 KiB) Downloaded 352 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Programmable RC-5 Remote Control

Postby Sean » Wed Jan 05, 2011 3:25 pm

If the definitions were being edited in the code customization window, Flowcode will have registered the edit and be including this version of the defines code along with the new version provided by the custom c file.

You could try deleting the contents of the custom code window. This should force Flowcode to revert to using the code supplied by the c file only.


Boost C uses lower-case text for register names and upper-case for bit definitions (this does not apply to all C compilers).

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8615
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2480 times
Been thanked: 3564 times
Contact:

Re: Programmable RC-5 Remote Control

Postby medelec35 » Wed Jan 05, 2011 3:45 pm

Deleted the Customised code from within flowchart, so its blank.
Still get:

Code: Select all

http://www.matrixmultimedia.com


Launching the compiler...
C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\BoostC\boostc.pic18.flowcode.exe -v -t PIC18F4455 "ProgRC5_1 for 18F4455.c"

...........................................................
Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:


If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.

FINISHED

I have also copied the corrected definitions from PIC_Custom.c and still the same.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Steve
Matrix Staff
Posts: 3111
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 398 times
Contact:

Re: Programmable RC-5 Remote Control

Postby Steve » Wed Jan 05, 2011 3:49 pm

Is this the Win7 libraries issue again??

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8615
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2480 times
Been thanked: 3564 times
Contact:

Re: Programmable RC-5 Remote Control

Postby medelec35 » Wed Jan 05, 2011 5:38 pm

Steve wrote:Is this the Win7 libraries issue again??

Nope as now I know what issues the libraries can cause :p
It's probably an issue with suppressing errors if too many?
Is there a way to fix that ( if that is the issue of course), or is it a boost C issue?

Was on the D drive in a folder, now moved to C drive in a folder called C:\Flowcode_Testing
Here is the full msg with just last name removed so you can see the path:

Code: Select all

File name:     C:\Flowcode_Testing\ProgRC5_1.c

Generated by:  Flowcode v4.3.7.63

Date:          Wednesday, January 05, 2011 17:58:34

Licence:       Professional

Registered to: Martin





http://www.matrixmultimedia.com





Launching the compiler...

C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\BoostC\boostc.pic18.flowcode.exe -v -t PIC18F4455 "ProgRC5_1.c"



Return code = 1



Flowcode was unable to compile the flowchart's C code due to the following errors:





If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.



FINISHED
Attachments
ProgRC5_1.c
(35.91 KiB) Downloaded 315 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Steve
Matrix Staff
Posts: 3111
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 398 times
Contact:

Re: Programmable RC-5 Remote Control

Postby Steve » Thu Jan 06, 2011 12:40 pm

Can you please attach (or PM) your FCF file so we can investigate further. It looks like there is an issue with the customisation of the component code somewhere.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8615
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2480 times
Been thanked: 3564 times
Contact:

Re: Programmable RC-5 Remote Control

Postby medelec35 » Thu Jan 06, 2011 6:58 pm

No problem. I will post flowchart as it is just the one that Sean posted, but with target device changed to 18F445.
Attachments
ProgRC5_1 for 18F4455.fcf
(20.82 KiB) Downloaded 491 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Steve
Matrix Staff
Posts: 3111
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 398 times
Contact:

Re: Programmable RC-5 Remote Control

Postby Steve » Fri Jan 07, 2011 7:58 am

The code for the "defines" section of the keypad component has been customized to include a load of definitions for the RC5, which might be causing some problems.
These users thanked the author Steve for the post:
medelec35 (Fri Jan 07, 2011 6:00 pm)
Rating: 5%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8615
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2480 times
Been thanked: 3564 times
Contact:

Re: Programmable RC-5 Remote Control

Postby medelec35 » Fri Jan 07, 2011 7:53 pm

Thanks Steve. I did not know the defines to the keypad was altered to be the same as defines in the PIC_Custom.c
So all I did was copy the common defines within PIC_Custom.c and paste in the keypad defines.
Now compiles OK.
Only warning is this:
Serious Warning: Possible sw stack corruption, function 'FCD_Custom0_RC5_Initialise_States' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Re LCD: It has to be connected to port A otherwise require patching not all default pins connections are available on port C
Program now runs, but in learn mode when press a key on the keypad e.g 1 then press remote, nothing happens. LCD keeps displaying Learn 1
I am using EB012 (as not got EB060) with no jumpers in A, B, C, 1 OR 2. got a wire connected from J6 RXIT to bit 6 (tried in bits 2 and 6 as well).
Any ideas please?
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.