Hi all
The code in earlier posts works but produces some strange results and I'm sure it has to do with timing and the bit tests I'm doing.
I have been reading up on the RC5 code at this sitehttp://www.sbprojects.com/knowledge/ir/rc5.htm
I'm still not just not getting it right and would really appreciate some guidance from some kind soul here.
Here's how I understand it so far (I have put comments in the code too):
1.RC5 consists of 1.778ms pulses representing a bit
2.Each bit consists of two halves and either half of the time may be filled with a 36Khz burst.
If the burst occurs in the first half then a ZERO is represented.
If the burst occurs in the second half then a ONE is represented.
3.There are TWO(2) Start bits
4.The third bit is a "toggle" bit - which tells us the button is pressed.
Apparently it is up to the receiving device to 'sense' that the button is down/pressed.
So in order to get the received pulses checked and decoded the first step is decide on the method of capture right ?
I have chose to use a 12F629 and TSOP1736 IR receiver is on GPIO.2 for receiving the IR input (IRpin in the code)
The methods I have been seeing in the forums and on the web seem to use either PULSIN or a PIN state test.
I have chose the PIN state test because I still don't understand the PULSIN command (you can only read the manual and examples all over so many times) - the thing I don't get is the timing/numbers. the rising ,falling and duty cycle do make sense.
So I chose to use the state of the PIN method.
The pseudo code is as follows:
1.Monitor a PIN (GPIO.2) and wait for it to go LOW - this means the start of a pulse/bit.
2.We know that if the first half of the pulse/bit is LOW (889uS) then the next half should be HIGH (assuming this is indeed a start bit)
3.So a quick check would help --- the idea is to delay/wait for a duration of under 889uS and then check to see if the pulse/bit is still low)
If it is high then start over and keep waiting and checking for a pulse.
If it is low then wait for a short time and check the next half time already spent +889uS/2
4.if the next half is HIGH then we have the first start bit and it's time to check the second incoming start bit.
So back to square one and do it again for the second start bit.
5.After I have the 2 start bits , it's time to start collecting the rest of the bits into a word variable.
6.Once we have collected the bits, they need to be separated/masked/divided into the a DEVICE/ADDRESS and COMMAND portion
BITS 4 to 8 =ADDRESS code MSB first
BITS 9 to 14 = COMMAND code MSB first.
Well that's the order of things as I have it figured out so far.
Please find my code below (It's not complete yet as I first need to understand the filtering correctly and then will begin (and finally post) the bit grabbing section.
I have it running but the problem is my initial bit tests don't seem to work because when I press a button on any remote (RC5 and others) it activates a message on my screen.I only want to filter RC5 code.
What am I doing wrong ? :-(
Should I rather attempt to use PULSIN (If so, what figures should I be using)
Kind regards
Dennis
Code:' Philips RC5 IR decoder for 12F629 @ 4MHZ 'set for samsung TV on universal rae-1000 (or similar??) remote - TV1 -code 189 most buttons work define OSC 4 '4MHz DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1k -HELPS tuning the crystal for more accurate timing CMCON = 7 'TRISIO = %76543210 ' port GPIO 0=output and 1=input TRISIO = %00000100 ' GPIO.2 is an input all the rest are outputs 'OPTION_REG.7 = 0 ' Internal pull-ups = on 'debug defines DEFINE DEBUG_MODE 0 ' Debug sending INVERTED serial data DEFINE DEBUG_REG GPIO ' Debug Port = GPIO DEFINE DEBUG_BIT 0 ' Debug.bit = GPIO.0 DEFINE DEBUG_BAUD 2400 ' Default baud rate = 2400 'end of debug defines RC5 VAR WORD ' Holds 12-bit RC5 code Loopy VAR BYTE ' Loop variable IRpin VAR GPIO.2 ' RB.0 input pin reading data Startbit2 var bit 'holds first synch bits Startbit1 var bit 'holds synch bits Home: IF IRpin = 1 THEN Home ' Wait for low going pulse ' ' 'if not then continue to read the pulse ' 'RC5 has equal length pulses each ot 1.788ms 'first two bits are START BITS for RC5 one bit = 889uS X2half bits = 17880ms/bit '0 = burst in first half of bit time,1=burst in 'second half of bit time ' half half half half half half half half '________|||||||________||||||||_______|||||||________||||||| ' 889 889 889 889 'STARTbit1 Startbit2 Togglebit First data MSB '--------------|---------------|-------------|---------------| ...12 others ' Bits 4to8 Addr Bits 8to12 Command ' | '.......testfor|........testfor| ' HIGH HIGH ' 'send a message to serial port debug "got something YAY ",DEC Y,13,10 ' PAUSEUS 200 ' Short delay to waste some time and test if pulse is still low ' 'Some conditions IF IRpin = 1 and startbit1=0 THEN Home ' Must be noise so test again IF IRpin = 1 and startbit1=1 THEN getbits 'is startbit1=1 PAUSEUS 1350 ' Pause to read 2nd half of 1st bit period is it 1 or 0 ? ' ' 'send message to serial port Debug "looks like RC5 S1 bit..checking next bit" Startbit1=1 'set startbit to flag we got first start bit if IRpin = 1 and Startbit1 =0 then Startbit1 =1 ' test conditions I may use 'if IRpin=1 and Startbit1=1 and Startbit2=0 then Startbit2=1 'if startbit1=1 and startbit2=1 then goto getbits ' ' While IRpin=1:Wend ' go home when pin goes low again goto home
Bookmarks