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
, 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
cheers man, if you have any questions please ask