RC5 compo problem on P18F4520

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

User avatar
fotios
Posts: 436
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 100 times
Been thanked: 113 times
Contact:

RC5 compo problem on P18F4520

Postby fotios » Fri Sep 06, 2013 11:14 am

Hello
The attached trial RC5 component fcf does not work by no way when compiled in a P18F4520. I have tried everything. I've tried the same fcf on a P16F887 and works just fine so the problem lies somewhere in P18F4520 configuration? Please don't try it on simulator, it could be checked only on actual hardware i.e. EB006 programmer, RC5 IR receiver e-block and a LED e-block connected at port C.
Any help will be appreciated.
Attachments
Phil.fcf
(19.54 KiB) Downloaded 189 times
Best Regards FOTIS ANAGNOSTOU

User avatar
fotios
Posts: 436
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 100 times
Been thanked: 113 times
Contact:

Re: RC5 compo problem on P18F4520

Postby fotios » Fri Sep 06, 2013 8:22 pm

I think the problem is the different registers used to configure the TMR0 module. In P16 the TMR0 is configured via the OPTION REGISTER while in P18 via the INTCON register (option register exists only in P16: option_reg). Another one difference is that in P18 INTCON register the Timer0 Overflow Interrupt Flag is named TMR0IF while in P16 OPTION register is named T0IF.
BTW, not so much worry for everyone needs more program memory for his application, there is the new P16F1939, with 16KWords program memory,fully compatible with RC5 component (i've tried it with succes on actual hardware using the P16F1937) with small changes on osccon and option_reg. Attached is the related fcf.
Attachments
Phil_16F1937.fcf
(19.06 KiB) Downloaded 184 times
These users thanked the author fotios for the post:
Benj (Fri Sep 06, 2013 10:03 pm)
Rating: 5%
 
Best Regards FOTIS ANAGNOSTOU

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

Re: RC5 compo problem on P18F4520

Postby Benj » Fri Sep 06, 2013 10:04 pm

Cheers Fotios,

I will have a look into this issue first thing Monday and see if we can get it resolved for you. I've had a quick go and managed to replicate the bug on an ECIO so it should be fairly easy for me to get it right.

User avatar
fotios
Posts: 436
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 100 times
Been thanked: 113 times
Contact:

Re: RC5 compo problem on P18F4520

Postby fotios » Sat Sep 07, 2013 6:38 am

Cheers friend :D
Thanks for the help although i will resolve my problem with program memory size with this baby: PIC16F1939. :D It has the same size like P18F4520 and 16 level deep hardware stack! Wow!
BTW P18F4520 presents problem like the new P18F45K22 to print on LCD display (if you remember from my other post before 1 month).
Best Regards FOTIS ANAGNOSTOU

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: RC5 compo problem on P18F4520

Postby brandonb » Sun Sep 08, 2013 1:05 am

hey fotios, if you want to create your own rc5 receive with full error checking, here is the code
rc5 with error detect.fcf
(27.17 KiB) Downloaded 205 times

and here is my c code on it incase you wanted to impliment the function

Code: Select all

//----------------------- RC5 REMOTE CONTROL RECEIVE DATA --------------------------------

//--RC5--RECEIVE--GLOBAL--VARIBLES---------|
char _wait_counter=0;//--------------------|  times 2.1 ms delay
char _pass_count=0;//----------------------|  first pass is wait,second pass is bit reads
char _get_bits_counter=0;//----------------|  counter for bit reads
unsigned int _get_bits=0;//----------------|  odd bits data shifts into this variable
unsigned int _communication_mask=0;//------|  even bits error mask shifts into this
char _odd_or_even=0;//---------------------|  toggles if even or odd bits are present
unsigned int _rc5_data=0;//----------------|  buffer1 for 16bit rc5 data
char _data_ready=0;//----------------------|  tells when valid message is in buffer
char _toggle=0;//--------------------------|  actual toggle data
char _address=0;//-------------------------|  actual address data
char _command=0;//-------------------------|  actual command data
unsigned int _rc5_inbox=0;//---------------|  buffer2 for rc5 data

/*
   setup for osc 32Mhz,tmr2 runs two speeds, 10k for wait timer,1124.859hz for bit reads,
   TEST BITS ARE:
   A5 = duation of b0 int
   A3 = bit delay 2.1 ms
   A5 = bit read rate and time out
   
   clearbit(ansela,3);
   clearbit(ansela,4);
   clearbit(ansela,5);
   clearbit(trisa,3);
   clearbit(trisa,4);
   clearbit(trisa,5);
   clearbit(lata,3);
   clearbit(lata,4);
   clearbit(lata,5);
 */

void rc5rx_init(){
//set up b0_int,falling edge
  clearbit(anselb,0);// clear analog on pin b0
  setbit(trisb,0);// make trisb0 input pin
  clearbit(option_reg,intedg);//set as falling edge
  setbit(intcon,inte);//enable int interrupt
//set up timer 2,default off
  setbit(pie1,tmr2ie);//Enables the Timer2 to PR2 match interrupt
  t2con=123; pr2=255; // disabled but set up at lowest frequency
  setbit(intcon,peie);// enable peripherial interrupts
  setbit(intcon,gie);// enable global interrupts
  clearbit(pir1,tmr2if);// clears timer2 interrupt flag
  delay_ms(250);
}
void b0_int_isr(void){
  //setbit(lata,5);//debug test
  _wait_counter=0;
  _pass_count=0;
  t2con=28; pr2=199;//tmr2 10khz
  //clearbit(lata,5);//debug test
}
void tmr2_isr(void)
{
  if(_pass_count)
   {
    //setbit(lata,4);//debug test
     if(_get_bits_counter>23)
      {
        if(_get_bits_counter==26)
         {
           clearbit(t2con,2);
           clearbit(intcon,intf);
           setbit(intcon,inte);
           clearbit(intcon,intf);
         }
      }
     else
      {
        if((testbit(portb,0))
         {
           if(_odd_or_even) setbit(_communication_mask,0);
           else setbit(_get_bits,0);
         }
        if(_odd_or_even)
         {
           if(_get_bits_counter==23)
            {
               _communication_mask=~_communication_mask;
               _communication_mask=_communication_mask & 4095;
              if(_get_bits==_communication_mask)
               {
                  _rc5_data=_get_bits;
                  _data_ready=1;
               }
            }
           else
            {
               _communication_mask=_communication_mask<<1;
            }
         }
        else
         {
           if(_get_bits_counter<22) _get_bits=_get_bits<<1;
         }
          togglebit(_odd_or_even,0);
      }
    _get_bits_counter++;
    //clearbit(lata,4);//debug test
   }
  else
   {
     //setbit(lata,3);//debug test
     clearbit(intcon,inte);
     if(_wait_counter==21)
      {
        _get_bits_counter=0;
        _get_bits=0;
        _pass_count=1;
        _communication_mask=0;
        _odd_or_even=0;
        t2con=53;  pr2=253;//1124.859hz
        //clearbit(lata,3);//debug test
      }
    _wait_counter++;
   }
}
char rc5checkrx(void)
{
   if(_data_ready)
   {
     _data_ready=0;
     _rc5_inbox=_rc5_data;
     _toggle = (_rc5_inbox & 2048) >> 11;
     _address = (_rc5_inbox & 1984) >> 6;
     _command = _rc5_inbox & 63;
     return 1;
   }
   else return 0;
}
void interrupt()
{
  if ((pir1 & 2) && (pie1 & 2))
  {
    tmr2_isr();//jump to macro
    clearbit(pir1,tmr2if);//clear flag
  }
  if((intcon & 16) && (intcon & 2))
  {
    b0_int_isr();//jump to macro
    clearbit(intcon,intf);//clear flag
  }
}
Last edited by brandonb on Thu Sep 12, 2013 7:39 pm, edited 1 time in total.
These users thanked the author brandonb for the post (total 3):
Kenrix2 (Sun Sep 08, 2013 4:52 am) • medelec35 (Sun Sep 08, 2013 8:02 am) • fotios (Sun Sep 08, 2013 4:25 pm)
Rating: 15%
 

User avatar
fotios
Posts: 436
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 100 times
Been thanked: 113 times
Contact:

Re: RC5 compo problem on P18F4520

Postby fotios » Sun Sep 08, 2013 7:20 pm

Hi Brandon
Thanks friend for the wonderfull C-code and congrats for your work. Nevertheless, it looks to be writen for P16 micros because there are some registers like the OPTION REGISTER which is not included in P18 micros, as well some others with different name e.g. in P18 "intcon.INT0IE" is that which enables the INT0 interrupt. I don't know if is applicable on P18 unless you have tried it.
Anyway, P18 are really very complex. I've tried the early RC5_INT_3 fcf developed by Sean King and i stuck in the equation "tmr0 = 116;" because the P18 TMR0 module is defined by two registers, TMR0L and TMR0H. There is not simple TMR0 register.
OTOH, FlowCode component works perfectly on any P16 but we had the problem of the lot of other tasks and the small program memory of 8Kb max that is resolved as Microchip launched two new P16 micros with 16Kb program memory. One of them is the P16F1939.
Thank you so much again.
Best Regards FOTIS ANAGNOSTOU

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: RC5 compo problem on P18F4520

Postby brandonb » Sun Sep 08, 2013 8:17 pm

hey fotios, about two years ago you inspired me to keep trying as i didn't understand anything about coding at the time, wanted to say thanks, it has given me more joy than you could imagine to :D, if i had one of those chips i could impliment it for you, yes the 1939 is an awesome chip, its my favorite, i made a board for it a while back that i sent to a couple members as gifts,
you shouldn't have any problem implimenting that flowchart or c code on that chip becuase it has a int0,and tmr2,
here is another way of thinking about rc5:
you actually have 28 bits in a message not 14, and there are 12 bits of it that are actually data, those bits are 1 bit for toggle, 5 bits for address, 6 bits for command,
the rx idles high from the receiver, when a 38khz signal is present the decoder passes it though to the b0 int pin,
how to look at the data in my way of thinking:
the rc5 signal is gonna go down, up, down, then send the useful 24 bit sequence, so when the negative edge b0 interrupt occurs, it runs the isr for intB0, which turns the tmr2 on at 10k, when timer2 isr gets accessed it clears the enable bit for the intB0 interrupt turning it off, the timer2 is now in delay mode, it is delaying 2.1 milliseconds from the time the interrupt was triggered, then after it times out by using a count++ routine, it changes the tmr2 interrupt speed to 1124.859 hz which is the speed to read at which the individual 28 bits get passed at,
so what im doing with this is the tmr2 is a two part timer, the first section(21 pulse) after the b0 enables it acts as a delay so when i enable the second part of the timer i can start reading the center of the bits at the bits rate starting on the toggle bit,
when start reading bits at toggle at this point every odd bit number is data, and every even bit number is the opposite of the previous bit, this is your error check, in the tmr2 isr i toggle a variable to shift the message into a variable and the error check to shift into another variable, after all the bits are received based on time, i allow the tmr2 to generate a couple extra pulses as a timer out feature so the b0int doesn't get enabled during the end of the message, then i disable tmr2, and re enable intB0 interrupt to restart the process for the next message
to error check, since the odd bits are data starting at toggle first bit, and the even bits are the opposite of the data all you have to do is take the error bits flip like this error = ~ error, then cut the bits off at the end since you just flipped it by ANDing it with what would be 12 bits worth of data which is 4095, so error = error & 4095, at this point if the message is a valid rc5 message the error will now be the same as the message becuase of the bit math we did on it, then just compair,
if data == error, then store the 16 bit data into another variiable,
in the c code i used a function rc5checkrx( ); what this does is when you call it it puts the first 16 bit rc5 buffer variable into another 16 bit buffer variable then it decodes by picking off the toggle, address and command bits by performing AND masking with this equasion from calling this function from the main loop,( flowchart is slightly different on this part)

Code: Select all

char rc5checkrx(void)
{
   if(_data_ready)
   {
     _data_ready=0;
     _rc5_inbox=_rc5_data;
     _toggle = (_rc5_inbox & 2048) >> 11;
     _address = (_rc5_inbox & 1984) >> 6;
     _command = _rc5_inbox & 63;
     return 1;
   }
  else return 0;
}

if data is ready it returns a 1, if not the function returns a zero, you would then use it like this
message_status =rc5checkrx();
then you can write
if(message_status==1) // do your rc5 code
hopefully that made sense as its the best way i can explain it,
but yea if you need i can change the flowchart for the 18f chip if you like,
also did you see my tmr2 calculator that makes the job a cake walk to get the best tmr2 frequency for projects like this, i have it adjusted to return back a 64:1 prescaler value for the 1939 chip since it supports this, to disable 64:1 perscaler since most chips don't support it, you'll see a loop that says something like:
"to return flowcode values set to 3", just change that loop to 3 and it will only give you values that flowcode supports since only the 16f 1800 and 1900 chips support this awesome prescaler value, which adds 4096 more combinations to the tmr2 interrupt, which in total is 16384 tmr2 combo's
here it is, i think you'll like it
REDUCED TMR2 CALCULATOR.fcf
(47.54 KiB) Downloaded 201 times

cheers man, if you have any questions please ask
Last edited by brandonb on Thu Sep 12, 2013 11:17 pm, edited 1 time in total.
These users thanked the author brandonb for the post (total 2):
fotios (Sun Sep 08, 2013 8:32 pm) • medelec35 (Sun Sep 08, 2013 9:15 pm)
Rating: 10%
 

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: RC5 compo problem on P18F4520

Postby brandonb » Sun Sep 08, 2013 8:47 pm

i wanted to go alittle further with this:
here is a picture of rc5 message and how i read it
fotios rc5 explain.jpg
fotios rc5 explain.jpg (64.12 KiB) Viewed 6607 times

here is a logic analyzer caputure with notes, im commanding outputs to check timing,
top is rc5 after decoder at b0 pin
next is duration of intB0 interrupt
next is duration of first part of tmr2 which is the 2.1 ms delay period using the timer
next is the moment and duration that it takes to process the rc5 data and error bits, following the timer it takes to process the and how many timeout bits there are past the message before intB0 is re eanabled again
scope capture of debug bits.jpg
scope capture of debug bits.jpg (37.44 KiB) Viewed 6607 times
These users thanked the author brandonb for the post (total 2):
fotios (Sun Sep 08, 2013 9:04 pm) • medelec35 (Sun Sep 08, 2013 9:15 pm)
Rating: 10%
 

User avatar
fotios
Posts: 436
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 100 times
Been thanked: 113 times
Contact:

Re: RC5 compo problem on P18F4520

Postby fotios » Sun Sep 08, 2013 9:37 pm

Amazing work Brand! You have been expert. Personally i was allways based on the "State Machine" developed by Sean King years ago but your approach is completelly different, you have developed your own RC5 decoding software from the scratch and that is magnificient. Unfortunatelly i haven't time to go deeper in your code, i have to finish 2 audio projects of which the one is very difficult as i have to include on it a USB2.0 full speed asynchronous audio interface (based on XMOS mcu) plus a SPDIF interface to drive a DAC in non oversampling mode and to design from the zero a modern true symmetrical power amplifier of 2 X 250 Wrms. For that reason i am looking for ready and tested solutions regarding digital-remote control. Oh my God! My customer will buy and send me this week the development boards of XMOS USB2.0 Audio... Oh my God!
These users thanked the author fotios for the post:
brandonb (Sun Sep 08, 2013 10:01 pm)
Rating: 5%
 
Best Regards FOTIS ANAGNOSTOU

User avatar
Jan Lichtenbelt
Posts: 794
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 262 times
Contact:

Re: RC5 compo problem on P18F4520

Postby Jan Lichtenbelt » Fri Nov 22, 2013 9:08 pm

I tried the Fotios flowcode to test the RC5. I bought a separate IR receiver (TSOP31236) and connected it to pin B0 in the same way as used on the EB060 board (ouptut of IR receiver contected to resistance of 10k to 5V and connected to a diode and 1k2 resistance to the input pin).

I have three transitters all TV (Sony, Humax and Panasonic). All three gave different period times respectively 1330, 1200 and 888 usec. I expected the last one to work correctly. However only the Humax transmitter shows and address of 31 and command of 63, for any button pushed.

What to do for an correct working of the RC5 with flowcode?

Jan Lichtenbelt

User avatar
fotios
Posts: 436
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 100 times
Been thanked: 113 times
Contact:

Re: RC5 compo problem on P18F4520

Postby fotios » Sat Nov 23, 2013 12:43 pm

Jan i think you need a fully RC5 compatible remote control handset. It is not only the period, it is also the transmition protocol structure. An RC5 transmiter transmits: 2 start bits for AGC of receiver, 1 toggle bit, 5 address bits and 6 command bits.
There are enough compatible handsets on e-bay in very low price. Please try a research.
The other option is to.... build one by alone. Here the link:http://www.matrixmultimedia.com/mmforums/viewtopic.php?f=3&t=10637
Good luck!

Fotis
These users thanked the author fotios for the post:
Jan Lichtenbelt (Sat Nov 23, 2013 9:20 pm)
Rating: 5%
 
Best Regards FOTIS ANAGNOSTOU