MX010 - RC5 remote control

Forum to discuss articles which have been published in Matrix Multimedia's article zone. If you have any comments or questions regarding the articles please post them here.

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:

MX010 - RC5 remote control

Postby Sean » Fri Mar 26, 2010 2:56 pm

Article: http://www.matrixmultimedia.com/article.php?a=57

If you have any questions for the author or comments on the article, please post them below.

jadiflow
Flowcode v5 User
Posts: 249
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 16 times
Been thanked: 16 times
Contact:

Re: RC5 remote control

Postby jadiflow » Sat Mar 27, 2010 11:10 am

A very welcome addition! I've been using RC5 on a PIC from pre-flowcode days (assembly, anyone?).

A tip for the actual codes: even if the remote sends RC5 when selected for Philips TV, not all buttons then necessarily do. You may receive the numeric buttons but not all of the control buttons. For instance, if you want to use the volume up/dn, mute, menu etc buttons, and some don't seem to work, select the remote code which is common to both Philips TV and Loewe or Loewe Opta TV. With those remote codes, most function buttons DO emit RC5 as well.

jan didden
Linear Audio

Wim
Posts: 7
Joined: Sun Dec 20, 2009 5:49 pm
Contact:

Re: RC5 remote control

Postby Wim » Sun Mar 28, 2010 12:26 pm

I was just about to experiment with receiving RC5 infrared, so very pleased with this article. However I have Flowcode V3... And the JPG is a hard to read. Would it be possible to have save your .fcf in Flowcode V3?
Thanks in advance,
Wim

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: RC5 remote control

Postby Sean » Sun Mar 28, 2010 2:55 pm

I don't currently have a V3 compatible version of the full MIAC program, but here are some of the development programs.
The PIC version is for a PIC16F84A @ 4MHz (V3)
The AVR version is for an ATmega324P @ 20MHz (V4)

Both have interrupt service routines with an identical structure. The main differences are:

Timer setup - configuration, prescaler, etc
Interrupt control - initial active edge, toggling the active edge
Limit values - based on timer clock frequency

The main programs are very basic test routines outputting to a port or lcd.

Note: the IR receiver used for the MIAC project does not need the interface circuit when operated at 5V. The signal inversion is handled in the programs.

RC5_INT_3.fcf
(13.67 KiB) Downloaded 1277 times


RC5_INT_3.fcf_avr
(16.94 KiB) Downloaded 1011 times
These users thanked the author Sean for the post:
STibor (Tue Feb 18, 2014 9:29 pm)
Rating: 5%
 

Wim
Posts: 7
Joined: Sun Dec 20, 2009 5:49 pm
Contact:

Re: RC5 remote control

Postby Wim » Sun Mar 28, 2010 9:03 pm

Thanks a bunch! My intention is to write the final application in C, so the example for the PIC16F84A is great. As a matter of fact I have that PIC laying around, so I guess I start of with this flowcode example to start "playing". Again thanks! :!:

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: RC5 remote control

Postby fotios » Fri Aug 13, 2010 9:01 am

Hi
I tried this project in a P16F887 mounted on the EB006 board. The only modification that i did is the moving of the "Command Indication Output" from Port B1-5 to Port D0-7 in which i have connected the LED board. Of course, i did the different MCU setup needed for the P16F887 and i use a XTAL of 4MHz. The project is working correctly after the compiling. I tried it with a mini Philips universal TV remote control and with another one - a mini handset with just 4 buttons custom made from me arround a SAA3010, configured to transmit in address 16 (Audio Preamp) - both transmitting in RC5 of course. The IR receiver that i use is a Vishay TSOP34836. By anyway, the whole thing is working just fine and because the more pins available, i can see as well Commands of 6 bits like Program+ ( 20h ) and Program- ( 21h ).
The only problem that i have, is that the program it runs only with a USB plug (regardless if i have or not the FlowCode v4 running) comming from PC, inserted in the EB006 socket, i.e. the LED1 of EB006 board should be lit.
If i remove the USB plug then the program does not run, with other words the EB006 with the programmed P16F887 does not work as stand alone. As i told you, i tried the project with FC v4 although it is written for v3 and I know almost nothing from C language. I attach the modified *fcf project.
Any help will be appreciated. :P
Thanks!
Fotios
Attachments
RC5_INT_3_mod.fcf
(15.56 KiB) Downloaded 943 times
Best Regards FOTIS ANAGNOSTOU

User avatar
Benj
Matrix Staff
Posts: 14786
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4750 times
Been thanked: 4358 times
Contact:

Re: RC5 remote control

Postby Benj » Mon Aug 16, 2010 3:11 pm

Hello Fotios,

Are you using a v7 EB006 multiprogrammer? If so then you may need to add a small mod to the board which was missed during our redesign of the board.

Basically the target chip effectivly starts to back power the unpowered USB PPP chip via its I/O and this can cause problems such as programms not running as expected when the USB cable is not present.

Please see here for the documented fix for the board.
viewtopic.php?f=2&t=6735&p=18070#p17799

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: RC5 remote control

Postby fotios » Tue Aug 17, 2010 6:28 am

Thanks Ben for information, you are very kind.
Anyway, i resolved my query the past weekend by inserting the programmed P16F887 (via EB006-v7) in another programming board, custom made from me which includes ICSP header, RJ45 socket, 40pin ZIF socket and D-Sub sockets for connecting the rest E-Blocks boards like LCD, LED, Switch etc. In mine board, the P16F887 worked just fine. I observed as well, that, when the USB plug removed from EB006 the LED1 is lit a little. From the above, i suspected for a small problem of EB006 but i was not sure for what is this. Now, after your explanation and by reading the posts of the thread in which you linked me, my query has been resolved. Personally i have not the need to unplug the USB connector in any case, so to the present i wil don't make any modification or any tricky USB powering-up of EB006v7 host mcu. There is no reason to get someone this as a design mistake, i think your thought is correct - for future upgrades - and the concrette problem is unimportant. I faced this problem by chance, with my other project in which i use again a P16F887 and a lot of E-blocks connected at EB006v7, it does not exists. The program it runs correctly, either with or without the USB plug connected.
Thanks a lot.
Fotios
Best Regards FOTIS ANAGNOSTOU

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: RC5 remote control

Postby fotios » Sun Aug 22, 2010 9:08 am

Hello to everyone who is reading this new post.
As i said in my previous posts, the project "RC5_INT_3" is working just fine using the EB006-v7 and a P16F887 programmed thru FC v4.3. I use the LED board connected in PORT D and the LCD board connected in PORT C, so as i can see the resulted output and the code of the command received.
OTOH, this project is addressed mainly for a demo of RC5 protocol. This code to bee fully operational so as it can manage a "real" device it needs enough additions and modifications. For example, in my case i need 6 commands for the remote control of my preamplifier. 1) STBY, 2) MUTE, 3) VOL+, 4) VOL-, 5) CH+ and 6) CH-. From those i have tried so far, the four from the six functions can be obtained relativelly easy. The difficulty is found in the VOL+ and VOL-. The STBY and MUTE commands have the sense of a toggle switch. E.g. if we press the MUTE button on the remote handset at once, the output MUTE must be turned ON constantly untill we press again the MUTE button to turn it OFF. The same for the STBY function. To select an INPUT is almost the same as well. If we press either the CH+ or CH- button at once or repeatedly or constantly the INPUT is changed forward or backward respectively, step by step. These 4 commands can be decoded easy from the MCU of receiver running the code "RC5_INT_3" modiffied with the addition of another one macro e.g. "Output" in which a variable "Command" (= RC5cmd) is processed to give the desired outputs which are represented from the LEDs connected in the PORT D. The issue is the functionality of VOL+ and VOL- commands. Both have the sense of a "Push to make" switch, i.e. if we press firmly the VOL+ button on the remote transmitter then the output VOL+ of the receiver MCU should be stay ON as long as the button is pressed, and should turn off only if the button is released. Unfortunatelly, this functionallity can not be obtained thru the "RC5_INT_3" code as it is writen. The reason it is that the variable "RC5cmd" is updated continuously with the data of the last command received, untill a different command code is received. Either thru the main loop or thru the execution of the macro "SignalEdge". Thus, although i tried a lot of modifications in timing and subroutines (decisions) inside the macro "Output", the result it is unsufficient. The LED which represents the VOL+ or VOL- output, it turns ON and OFF continuously which means that the corresponding output can not be constantly ON, following the state of the VOL+ or VOL- on IR transmitter handset.
Because i wish to understand the logic of the code, i keep always open besides the FlowCode the manual of BoostC C compiller and the manual of P16F887, and by the way i have learned enough things of the BoostC language. Of course, there are some "expressions" which are not explained in the manual, so i can suppose that are of C++.
I think that is better to give you an icon of what i try to build. To this, i attach the first part of my project which i have realized with the use of FlowCode icons exclusivelly. It is the "manual operation" part of my project and it works correctly by 99% in real mode. Of course, i am not sure that i did excess use of commands. Maybe some can be substituted from only one. Any comment and suggestion will be welcomed. The second part which i have to finish, so as my project will be complette, it is the Remote Control of the device. It must be noted that the SET and RST output commands used, are because the MCU it has to manage LATCHING TYPE RELAYS. I attach as well the recently modified "RC5_INT_3" code that i did. I have tried as well the other RC5 project "ir_test_cmd" which i found in this thread, but it is not so accurate in timing and it needs, likewise, enough mods to be really operational. For this reason i focused on "RC5_INT_3", because is very precise in RC5 receiving and decoding.
I know that it is time consumpting a set-up of E-blocks for testing either of the two *fcf projects. Neither can be simulated with FlowCode, because the Interrupts used.The hardware used also, in some cases does not fits exactly with ready E-blocks, e.g. the PORT B is shared between the Vishay TSOP34836 IR receiver and the 6 switches. I made a custom pcb for this purpose. In PORT E1 you have as well to mount a LED and the resistor to show the STBY mode. And so on. The next days, i will continue my effort to solve this problem of VOL+ and VOL- command. If you have any idea, PLEASE... HELP!
Thanks a lot for any assistance in my effort.
Fotios
Attachments
RC5_INT_3_mod.fcf
(25.55 KiB) Downloaded 864 times
EAL_PREAMP.fcf
(91.06 KiB) Downloaded 830 times
Best Regards FOTIS ANAGNOSTOU

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: RC5 remote control

Postby fotios » Mon Aug 23, 2010 7:17 am

Good morning and have a nice week
I think i found a temporary solution for the VOL+ and VOL- commands. They work correctly now. There is only the need for small changes of the time of "Delays" used inside the two macros. Please, take a look in the new attached *fcf and tell me your opinion, and if there is a better way.
Thanks a lot
Fotios
Attachments
RC5_INT_3_mod.fcf
(25.87 KiB) Downloaded 811 times
Best Regards FOTIS ANAGNOSTOU

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: RC5 remote control

Postby Sean » Mon Aug 23, 2010 8:49 am

Hello,

You should be able to use the RC5update variable for your volume control. The handset will transmit the key value at regular intervals if a button is held down, so the program will detect multiple messages. The RC5update value is set to 1 in the interrupt handler each time an RC5 message is successfully received, and is cleared in the main program when it is detected. Your program should only respond to the address and command values each time RC5update is set.

The example program uses the decision icon - If RC5update - to detect the reception of a message and the requirement for an action.

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: RC5 remote control

Postby fotios » Fri Aug 27, 2010 7:42 pm

As i can see, you have download the un-completted file more times than the usefull one. I ask your forgiveness, because both files have the same title. With the second you can make a fully operational RC5 receiver, with real outputs ready for use. You can connect the LED board in PORT D of EB006 programmer which gives an optical indication of the output states obtained thru the decoding of RC5 signal received. With the LCD board connected in PORT C you can observe the code of command received, and when the variable "RC5update" is updated, a usefull thing to adjust exactly the time delays in the Main and SignalEdge macros because both are time critical. I attach again the correct file.
Greetings
Fotios
Attachments
RC5_INT_3_mod.fcf
(26.47 KiB) Downloaded 867 times
Best Regards FOTIS ANAGNOSTOU

soccermad
Posts: 19
Joined: Wed Feb 09, 2011 12:56 am
Has thanked: 2 times
Contact:

Re: MX010 - RC5 remote control

Postby soccermad » Thu Apr 28, 2011 3:33 am

i try to import this file to my flowcode avr v3 but i keep getting error codes. can anyone please help me

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: MX010 - RC5 remote control

Postby fotios » Thu Apr 28, 2011 7:20 am

soccermad wrote:i try to import this file to my flowcode avr v3 but i keep getting error codes. can anyone please help me


Hello soccermad
(soccermad: do you mean mad with football?)
First of all, the attached *fcf file it is applicable on PIC16F887 MCUs. For AVRs, you must change the configuration bits of the attached *fcf file.
Second, i started the use of flowcode from version 4.0 and then. I don't know if *fcf files obtained with late flowcode versions, are compatible with previous versions like v3. For this issue, we need the advice of a more expertised person.
I have ready and tested a new *fcf file, with corrections on "Delays". In the new file, i also added an extra subroutine for the RC5 address decoding - setup, managed by the program. No need for external hardware (like jumpers etc). I have in my mind to upload the whole project here in Matrix User Forums some months ago, but i had never the time for this. For a quick view, take a look here: http://www.eal.gr/MICROS.htm
Regards
Fotios
Best Regards FOTIS ANAGNOSTOU

User avatar
Benj
Matrix Staff
Posts: 14786
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4750 times
Been thanked: 4358 times
Contact:

Re: MX010 - RC5 remote control

Postby Benj » Thu Apr 28, 2011 11:49 am

Hello,

What about the v3 AVR file from Seans post?

viewtopic.php?f=36&t=7246#p18069

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: MX010 - RC5 remote control

Postby fotios » Thu Apr 28, 2011 6:37 pm

Benj wrote:Hello,

What about the v3 AVR file from Seans post?

viewtopic.php?f=36&t=7246#p18069


Thanks Ben for the informations
I have not any experience with Flowcode v3. I bought Flowcode v4.0 before one year, and immediately i did a downloadable upgrade to the latest version 4.3 from Matrix Multimedia Support site. The issue is, which file "soccermad" wants. Sean's file is ready for use with e.g. a MIAC device for experiments, mine is for use with a real world device like an audio preamplifier (or everything compatible to it). In my *fcf file i have just included the macro "SignalEdge" from Sean's file for decoding RC5 remotely received codes. This macro is just, say, a 15% of the whole program. The rest of program (that i have obtained after 2 months of work and with the help of some very kind members of this forum) is very big and well focused on the demands of a Hi-Fi audio preamplifier. If this is the case of "soccermad", then - i think - the only solution is someone who has both v3 and v4. You could have running simultaneously v3 and v4 on a PC, and copy - paste commands from mine *fcf file to a new *fcf file created on Flowcode v3. In the last file, the device must be changed and configured to the AVR that uses "soccermad". I don't know, and i have never seen how flowcode v3 opens *fcf files developed and compiled with Flowcode v4. In any case, i am available to offer my help (i gave already the *asm file in 2 - 3 members of "diyAudio forum") the project is free to everyone asking it, is not secret.
Fotios
Best Regards FOTIS ANAGNOSTOU

soccermad
Posts: 19
Joined: Wed Feb 09, 2011 12:56 am
Has thanked: 2 times
Contact:

Re: MX010 - RC5 remote control

Postby soccermad » Mon May 02, 2011 4:10 am

your help would be gratefully appreciated. i am an amateur but i have managed to create a working program but now need a remote control in order to achieve my aim. I need the remote control to have 7 buttons which will act in place of the switch board. Is that possible do you think?

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: MX010 - RC5 remote control

Postby fotios » Mon May 02, 2011 9:21 am

soccermad wrote:your help would be gratefully appreciated. i am an amateur but i have managed to create a working program but now need a remote control in order to achieve my aim. I need the remote control to have 7 buttons which will act in place of the switch board. Is that possible do you think?

So, you need just the RC5 remote control decoding macro. I could suppose that you have a Philips RC5 compatible TV handset, with a lot of buttons, of which you need just the 7. Therefore you need 7 outputs of your AVR mcu to manage relays, lamps, leds etc. If this is your case, then the thing is very simple. You could use the numerical keys 1 to 7 of TV handset:
key 1 = command 1d - 01h
key 2 = command 2d - 02h
------
key 7 = command 7d - 07h
If your application is not secret, you can upload your *fcf file here so as we can modify it for you.
Regards
Fotios
Best Regards FOTIS ANAGNOSTOU

soccermad
Posts: 19
Joined: Wed Feb 09, 2011 12:56 am
Has thanked: 2 times
Contact:

Re: MX010 - RC5 remote control

Postby soccermad » Mon May 02, 2011 4:39 pm

fotios wrote:
soccermad wrote:your help would be gratefully appreciated. i am an amateur but i have managed to create a working program but now need a remote control in order to achieve my aim. I need the remote control to have 7 buttons which will act in place of the switch board. Is that possible do you think?

So, you need just the RC5 remote control decoding macro. I could suppose that you have a Philips RC5 compatible TV handset, with a lot of buttons, of which you need just the 7. Therefore you need 7 outputs of your AVR mcu to manage relays, lamps, leds etc. If this is your case, then the thing is very simple. You could use the numerical keys 1 to 7 of TV handset:
key 1 = command 1d - 01h
key 2 = command 2d - 02h
------
key 7 = command 7d - 07h
If your application is not secret, you can upload your *fcf file here so as we can modify it for you.
Regards
Fotios


yeah thats basiclly all i need and also would i just attach the RC5 board in place of the switches board has i am currently using all ports A,B,C & D
Attachments
WORKING_TIMER_TEMP.fcf_avr
(23.99 KiB) Downloaded 751 times

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: MX010 - RC5 remote control

Postby fotios » Mon May 02, 2011 10:08 pm

Ooops! I forgot that i can't open the attached file, because my Flowcode is for PICs and not for AVRs. I think that i can edit a flowchart (is same either for PIC or AVR, the only changed by Flowcode is the device seting menu and configuration bits) which i could upload in pictures. Your AVR is an Atmega324, right? It is similar to PIC that i use. I need some info to help you: a) which IR receiver IC are you using? b) in which port of atmega324 is connected the IR receiver? You must connect IR receiver at the mcu pin in which is allocated the Main External Interrupt. For example, in all PICs that i know main external interrupt is allocated in port RB.0 (From those i have seen in ATmega 324 datasheet, this pin might be PD.2 - INT0)
The thing starts to get some complex - against my first estimation; although the additional "macro" for decoding RC5 commands, is simple in your case. In Sean's file "RC5_INT_3.fcf_avr" there should be (like in "RC5_INT_3.fcf" for PICs) a variable "RC5cmd" inside the main program loop and after the Decision "If RC5update". Variable "RC5cmd" gets the RC5 received command value thru the "SignalEdge" macro. Inside the sub-loop there is a calculation box "Command = RC5cmd". You could edit a new macro named e.g. "Output", and insert a "Call Macro Output" box after the calculation box "Command = RC5cmd". Open the macro "Output" and edit a sub-routine consisted from 7 Calculation boxes and 6 Decisions. Example:
If Command = 1 ? --> YES (branch) --> 1->D0 (Set Port D.0) --> END (exit from macro) or NO (branch) --> If Command = 2 ? --> YES (branch) --> 0->D.0 (Clear Port D.0) --> 1->D.1 (Set Port D.1) --> END (exit from macro)
And so on.
As i told you, your case is simple because you don't need the use of "VOL+" and "VOL-" keys (RC5 commands 16d and 17d respectively). In the latter case, the synchronization of receiver and transmiter is some critical. I spent enough time to find the correct Delay time inside the main Loop (100ms for the story; with 110ms Delay, i had repeated breaks on the rotation of volume potentiometer motor).
I don't know how much i can help you with the above.
Maybe Benj :) could help us a little?
Best Regards FOTIS ANAGNOSTOU

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: MX010 - RC5 remote control

Postby fotios » Tue May 03, 2011 11:41 am

Here is a picture that shows the modified main program loop.
Attachments
RC5_INT3_main.jpg
RC5_INT3_main.jpg (116.17 KiB) Viewed 30799 times
Best Regards FOTIS ANAGNOSTOU

soccermad
Posts: 19
Joined: Wed Feb 09, 2011 12:56 am
Has thanked: 2 times
Contact:

Re: MX010 - RC5 remote control

Postby soccermad » Sun May 08, 2011 1:58 pm

fotios wrote:Here is a picture that shows the modified main program loop.


so where would i insert the output function boxes for the interaction for the switch board

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: MX010 - RC5 remote control

Postby fotios » Wed May 11, 2011 7:50 am

Let's suppose the following scenario: The 7 outputs that you need, are allocated in PORT A of mcu, from PA.1 - PA.7. And that, when button "1" on remote control handset is pressed, it must turn on PA.1 and turn off PA.7. In the same way, when button "2" is pressed it must turn on PA.2 and turn off the previous output PA.1. So, when button "3" is pressed it must turn on PA.3 and turn off PA.2. And so on. You can modify it, if you want e.g. when button "1" is pressed must turn on PA.1 and turn off all the rest outputs PA.2 - PA.7. Now, you have to open the menu "Macro" on the taskbar and to select "New". In the screen that will open, give the name "OUTPUT" by typing it in the corresponding box. You have to click on "OK" and imediatelly the table of the new macro "OUTPUT" will opens. There are just two icons, "BEGIN" and "END". Inside these two icons, you have to develop a new flowchart.
In the first picture you can see the flowchart of the "OUTPUT" macro developed accordingly to the supposed scenario , while in the second you can see the flowchart of the "Main" macro. You must keep the "Decision" icons as they are on the flowchart of "OUTPUT" macro. You could modify the "Output" icons according to your application, e.g. change Port A with the Port "X" that you use as output in your actual project.
Regards
Fotios
Attachments
RC5_INT3_OUT.jpg
(251.92 KiB) Downloaded 20627 times
RC5_INT3_main.jpg
(154.94 KiB) Downloaded 20627 times
Best Regards FOTIS ANAGNOSTOU

soccermad
Posts: 19
Joined: Wed Feb 09, 2011 12:56 am
Has thanked: 2 times
Contact:

Re: MX010 - RC5 remote control

Postby soccermad » Sat May 21, 2011 2:46 pm

fotios wrote:Let's suppose the following scenario: The 7 outputs that you need, are allocated in PORT A of mcu, from PA.1 - PA.7. And that, when button "1" on remote control handset is pressed, it must turn on PA.1 and turn off PA.7. In the same way, when button "2" is pressed it must turn on PA.2 and turn off the previous output PA.1. So, when button "3" is pressed it must turn on PA.3 and turn off PA.2. And so on. You can modify it, if you want e.g. when button "1" is pressed must turn on PA.1 and turn off all the rest outputs PA.2 - PA.7. Now, you have to open the menu "Macro" on the taskbar and to select "New". In the screen that will open, give the name "OUTPUT" by typing it in the corresponding box. You have to click on "OK" and imediatelly the table of the new macro "OUTPUT" will opens. There are just two icons, "BEGIN" and "END". Inside these two icons, you have to develop a new flowchart.
In the first picture you can see the flowchart of the "OUTPUT" macro developed accordingly to the supposed scenario , while in the second you can see the flowchart of the "Main" macro. You must keep the "Decision" icons as they are on the flowchart of "OUTPUT" macro. You could modify the "Output" icons according to your application, e.g. change Port A with the Port "X" that you use as output in your actual project.
Regards
Fotios


thank you so much for your help but i am finding it hard to incoparte my switch board controls to the remote control flowcode

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: MX010 - RC5 remote control

Postby fotios » Wed May 25, 2011 10:31 pm

Hi soccermad.
You have confused me a bit. Now I can perceive that except remote control you also need "local" control thru 7 switches mounted on the pcb of your project. I have developed 3 Flowcharts presented in the pictures, which I will explain you step by step.
Instead interrupt, (so as the code can be applicable in any microcontroller either PIC or Atmel etc.) we use an extra loop inside the main loop for scanning if any and which of the 7 "local" switches (NOT those of the remote control handset!) is pressed. Let's suppose again that the 7 switches are connected from Port D.1 up to Port D.7 of your microcontroller. When a switch is pressed, applies a logic "1" (or +5V) at the corresponding input. Outputs remain connected from Port A.1 to Port A.7 as in the example of previous post. First of all we have to create 2 new macros and 2 new variables. You may do this:
1) Open menu "Macro" --> "New" --> type on the box the Name of the new macro: MANUAL --> click OK. Open again menu "Macro" --> "New" --> type on the box the Name of the new macro: SCANswitch --> click OK.
2) Open menu "Edit" --> "Variables" --> "Add new variable" --> type on the box the Name of the new variable: switch.
3) Do the same and create the second variable: MANupdate.
Look now at the Flowchart of macro Main on the first picture:
1. Enable INT interrupt: this command enables the external interrupt source (IR receiver) to cause an interrupt in the main program loop “Loop while 1” when receives a command from the remote control handset. When occurs, it stops the main loop and calls the macro "SignalEdge" that decodes the RC5 code received.
2. Loop "While 1": this is the main program loop and is executed continuously because we gave the value “1 = TRUE” at the start of loop. It stops only when the previously explained interrupt occurs.
3. Call Macro "MANUAL": the first step of the main loop is to change the program flow into the macro "MANUAL". Look please at the second picture the title and the structure of this macro. After the icon "BEGIN" there is an "INPUT" icon which defines Port D as input. After this, there is a "Calculation" icon: "switch = switch AND 0xFE". What means that? We make a logical AND operation between the hex number "0xFE" and the variable "switch". Hex "0xFE" is equal to binary "11111110". You may remember that we have connected the 7 switches from Port D.1 up to D.7. The last "0" of the binary number excludes from the Calculation (that is what called MASK) the Port D.0. Variable "switch" corresponds to the data register of Port D. If no one switch has been pressed, the binary number that contained in the data register of Port D is “0000000x”, thus the result of the calculation is "0" or FALSE. If any switch has been pressed the result will be different from "0" or TRUE. I hope you know few things about Boolean algebra. The result of this calculation updates the data of variable "switch". After this, it follows a "Decision" icon "If switch is TRUE?”. If no one switch has been pressed, then the variable "switch" = 0 = FALSE and thus the decision turns the program flow in the "No" branch. Then it writes a "0" (or Clear MANupdate Flag) in the variable "MANupdate". If any switch has been pressed, variable "switch" = 1 = TRUE and the program turns in the "Yes" branch, where it writes a "1" (or Set MANupdate flag) in the variable "MANupdate".
4. In either way, the program returns to the main loop (See again at the first picture) where it has to pass thru the Decision icon "If MANupdate is TRUE?”. If any switch has been pressed, then the variable "switch" = TRUE --> variable "MANupdate" = TRUE, so the program turns in the "Yes" branch of the decision "If MANupdate?”. In the flow of “Yes” branch there is a delay icon “Delay 500ms”. Later, during the test of program in your actual hardware you can delete this Delay or to modify it according to instance.
5. Loop “Until MANupdate is TRUE”: You have to create this sub-loop. The test if the condition of loop “MANupdate is TRUE” is fulfilled (i.e. a switch has been pressed) is placed at the end of the loop. This means that even if the switch is held down, the loop will be terminated and the program returns in the start of the Main loop. With other words, if a switch is pressed this sub-loop is executed at once and it calls each time the macro “SCANswitch”. We have seen that in the macro “MANUAL” is detected if a switch was pressed. In the macro “SCANswitch” is detected which switch exactly was pressed. Look at the 3rd picture: In the beginning of macro, is placed an “Input” icon that defines Port D as input for the 7 switches. After it, are arranged 7 “Decision” icons. Each icon corresponds to one switch. Each switch when is pressed, it writes in the Port D register a unique binary number:
Switch D1 = 00000010 b = 0x02 hex
Switch D2 = 00000100 b = 0x04 hex
Switch D3 = 00001000 b = 0x08 hex
Switch D4 = 00010000 b = 0x10 hex
Switch D5 = 00100000 b = 0x20 hex
Switch D6 = 01000000 b = 0x40 hex
Switch D7 = 10000000 b = 0x80 hex

According to the switch pressed, the corresponding “Decision” icon it turns the program flow at its “Yes” branch. Then, the program activates one output and deactivates another one, exactly like in the macro “OUTPUT” which is presented in my previous post.
You should be careful about the “Delay” of 500ms placed before the “Decision” icon “If RC5update is TRUE?". The 14 bits of RC5 code are transmitted in repeated and predetermined intervals, so the correct response of the program to decode the RC5 command received – for that is the macro “SignalEdge” - is time critical. According to your application, you could change this delay to e.g. 200ms. You will find this during the test of the complete program on your actual project.
I hope the above will help you a little better now.
Fotios
Attachments
soccermad MAIN.jpg
(170.99 KiB) Downloaded 20403 times
soccermad MANUAL.jpg
soccermad MANUAL.jpg (104.03 KiB) Viewed 30496 times
soccermad SCANswitch.jpg
(223 KiB) Downloaded 20403 times
These users thanked the author fotios for the post:
Benj (Thu May 26, 2011 10:52 am)
Rating: 5%
 
Best Regards FOTIS ANAGNOSTOU