|
|
View previous topic :: View next topic |
Author |
Message |
chriss2000 Guest
|
Manchester Decoding |
Posted: Sat Jan 11, 2003 12:30 pm |
|
|
<font face="Courier New" size=-1>I've now written an Code to decode an RC5 Signal, but it doesn't work !The program uses a Timer wich starts with the first falling edge of the signal and if the timer reaches a specific value the pin_a0 is read. The Value is set so,that the code is scanned in the last half of the bits.
This is cause in the last halb of the bit it has the right value
Pleas help me
.scan..scan..scan...scan
...|.....|.....|.....|
___---___------___---___
,.1..,...1..,..0..,..0..,
#include <16f876.h>
#Device ICD=TRUE
#use delay(clock=4000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
int offset=1,count=0,abtast=1,newbit=0,ready=0;
void main()
{
set_tris_A(0xFF);
set_tris_B(0xFF);
set_tris_C(0x00);
enable_interrupts(global); enable_interrupts(int_ext); ext_int_edge(H_TO_L);
while(1)
{
while(ready=1)
{
count=get_timer0(); if(count+offset>Abtast)
{
newbit=input(Pin_A0);
If(newbit==0)
{
//Do Something }
if(newbit==1)
{
//Do Something
}
Abtast=Abtast+6,9453125;
}
}
ready=0;
}
}
#int_ext
isr()
{
setup_timer_0(RTCC_DIV_256|RTCC_Internal);
ready=1;
}</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 10618 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Manchester Decoding |
Posted: Sun Jan 12, 2003 9:52 pm |
|
|
:=I've now written an Code to decode an RC5 Signal, but it doesn't work !
I looked at your program with regard to C syntax.
I didn't try to analyze the design.
:=while(ready=1)
This line should be: while(ready == 1)
:=Abtast=Abtast+6,9453125;
Not sure what this line is doing, but it's not correct.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10636 |
|
|
chriss2000 Guest
|
Re: Manchester Decoding |
Posted: Mon Jan 13, 2003 3:53 am |
|
|
:=:=I've now written an Code to decode an RC5 Signal, but it doesn't work !
:=
:=I looked at your program with regard to C syntax.
:=I didn't try to analyze the design.
:=
:=:=while(ready=1)
:=This line should be: while(ready == 1)
:=
:=
:=:=Abtast=Abtast+6,9453125;
:=Not sure what this line is doing, but it's not correct.
Abtast=Abtast+6,9453125;
the value 6.9453125 counts up the timer
when the timer reaches the value 1 it has the time 250µs
6.9453125 is equal to 1.778ms and that is equivalent to one bit of rc5 code [a 1 or a 0)
___________________________
This message was ported from CCS's old forum
Original Post ID: 10643 |
|
|
chriss2000 Guest
|
Re: Manchester Decoding |
Posted: Mon Jan 13, 2003 3:55 am |
|
|
:=:=I've now written an Code to decode an RC5 Signal, but it doesn't work !
:=
:=I looked at your program with regard to C syntax.
:=I didn't try to analyze the design.
:=
:=:=while(ready=1)
:=This line should be: while(ready == 1)
:=
:=
:=:=Abtast=Abtast+6,9453125;
:=Not sure what this line is doing, but it's not correct.
Abtast=Abtast+6,9453125;
the value 6.9453125 counts up the timer
when the timer reaches the value 1 it has the time 250µs
6.9453125 is equal to 1.778ms and that is equivalent to one bit of rc5 code [a 1 or a 0)
___________________________
This message was ported from CCS's old forum
Original Post ID: 10644 |
|
|
Dale Botkin Guest
|
Re: Manchester Decoding |
Posted: Mon Jan 13, 2003 10:04 am |
|
|
:=6.9453125 is equal to 1.778ms and that is equivalent to one bit of rc5 code [a 1 or a 0)
Now figure out how many bits are required to represent that value in binary, and compare that number to the number of bits in the timer register, and you'll probably see the problem there.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10651 |
|
|
R.J.Hamlett Guest
|
Re: Manchester Decoding |
Posted: Mon Jan 13, 2003 10:13 am |
|
|
:=:=:=I've now written an Code to decode an RC5 Signal, but it doesn't work !
:=:=
:=:=I looked at your program with regard to C syntax.
:=:=I didn't try to analyze the design.
:=:=
:=:=:=while(ready=1)
:=:=This line should be: while(ready == 1)
:=:=
:=:=
:=:=:=Abtast=Abtast+6,9453125;
:=:=Not sure what this line is doing, but it's not correct.
:=
:=Abtast=Abtast+6,9453125;
:=the value 6.9453125 counts up the timer
:=when the timer reaches the value 1 it has the time 250µs
:=
:=6.9453125 is equal to 1.778ms and that is equivalent to one bit of rc5 code [a 1 or a 0)
This is foul code, and won't work as you expect. The first problem is that there is a ',' instead of a '.' as the decimal seperator. The second problem is that the declaration of the variable 'Abtast', is for an integer, so the addition will not give the expected result. You then have to ask what the point is of fractional arithmetic, when dealing with an integer 'count' value. Also the timer is being re-initialised on each falling edge, rather than just the first...
I would imagine, that you actually need to test the bit an interval inside the data, rather than on the 'edge'. The normal way to do this, is to just reset the counter (not re-initialise), and to wait for a specific number of counts from the starting point. Typically waiting for half a 'bit time' then reading the data, then waiting a full bit time from this point.
So:
1) In the edge detect interrupt, disable this interrupt source - disable_interrupts(INT_EXT); .
2) In the final loop of the main code, once the bits have all been read, clear the interrupt flag, and re-enable the interrupt for the next character.
3) You need to delay for 7112 cycles of the main clock, between the individual bits, and 3556 cycles between detecting the first edge, and actually reading the first bit. You can get quite close to these values, by using RTCC_DIV_8, and programming the counter 'up' to different starting values. Then reading the input bits on the interrupts. So if you set the RTCC counter to use:
setup_timer_0(RTCC_DIV_8|RTCC_Internal);
in the main code. Leave INT_RTCC disabled. Then in the edge interrupt routine, SET_TIMER_0(145) then clear the bit T0IF, enable INT_RTCC, and disable the edge interrupt. You should get a RTCC interrupt about 880uSec latter ((256-145)*4*8 clocks). In the RTCC routine, immediately set timer_0 to 34, and read the input bit. The next interrupt will be 1760uSec latter (plus the latency time of the interrupt, and handler), which should be pretty 'spot on' for your required pulse interval. When the last bit is read, disable the RTCC interrupt, clear the INTF bit, and re-enable the edge interrupt to get the next character.
The T0IF, and INTF handling, can be done with the following code:
#bit T0IF=0xB.2
#bit INTF=0xB.1
Then you can clear these with the commands:
TOIF=0;
INTF=0;
when needed.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 10652 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|