|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Decoding Differential Manchester Data.... |
Posted: Wed Feb 06, 2008 1:32 pm |
|
|
Hi All,
I'm trying to write a subroutine to decode a stream of 192 data bits encoded with Differential Manchester encoding. I've been going round-and-round trying to come up with an algorithm to do what I want, so I'd appreciate some help! Part of the problem is that I'm just having a bit of trouble getting my head around the protocol......
Anyway, the data stream contains 192 bits of data, with a bit interval of 1000us. Wikipedia seems to have a pretty good description of the protocol including some diagrams. Unfortunately, a search of the net has failed to provide any clues to how a decoder would be coded.
The source of the bit stream is a wireless receiver module. The output of the receiver is low when no signal is being received, and goes high as data is received.
Here is what I've got so far. It's looping OK, and filling my received data array, but the data I'm decoding is not correct
Code: |
void ReceiveRxData(void)
{
// This subroutine reads 192 bits of Differential Manchester encoded data. The bit interval is approx. 1000 uS.
// The data packet is made up of 32 bits of sync zeros, 128 bits of zero interleaved data, and 32 bits of CRC checksum.
int8 iIndex1;
int8 iIndex2;
short PrevValue = 0;
short RawRxData[191]; // 192 raw data bits with interleaved zeroes
// Here we have 192 iterations of the data capture and decode loop....
for ( iIndex1=0 ; iIndex1<192 ; iIndex1++ )
{
// Here we are at the mid-point of the bit interval, so we test for a lo or high signal, and wait for the next
// transition... It might be one bit interval (~500 us), or it might be two bit intervals (~1000 uS)
if (input(Rx_Data)) // Here we have a hi bit value
{
Rx_Get_Fall_Time();
if (Rx_Fall_Time < 600) // only one bit interval
{
RawRxData[iIndex1] = 0;
delay_us(520);
PrevValue = 1;
}
else // two bit intervals
{
RawRxData[iIndex1] = 1;
PrevValue = 0;
}
}
else // Here we have a lo bit value
{
Rx_Get_Rise_Time();
if (Rx_Rise_Time < 600) // only one bit interval
{
RawRxData[iIndex1] = 0;
delay_us(520);
PrevValue = 1;
}
else // two bit intervals
{
RawRxData[iIndex1] = 1;
PrevValue = 0;
}
}
}
// Here we blip the Rx LED to signal that we have got some data...
output_high(Rx_LED);
delay_ms(125);
output_low(Rx_LED);
delay_ms(125);
}
|
I'd appreciate it is someone could take a look at my code and offer some pointers!
Thanks,
Greg |
|
|
kolio
Joined: 06 Feb 2008 Posts: 26
|
|
Posted: Fri Feb 08, 2008 4:39 am |
|
|
Hi Greg,
Probably you have used this info source for your decoding routine:
http://en.wikipedia.org/wiki/Differential_Manchester_encoding
You may just read as an additional info this one too:
http://www.embedded.com/design/networking/205918953?pgno=5
1.There is a very good reason for those 32 0-oes bits in the preamble. You need to detect it, to synchronize bit beginning, bit end and the real bit period for every given message. Don't trust on ther stability of the transmitter's oscillator.
Raising a spare pin after 32 0-s and lowering it after 160 estimated bit periods, can give you good insight on the oscilloscope how good is the whole message synchronization.
2.It's better to adjust delay_us(520+variable) for each bit, depending how long you have wait for an edge occurence. Here a spare pin can also help a lot in debugging bit-decoding routine, which is represented in your source.
3.Bit-decoding routine seems to me a classic Manchester-decoding, rather than differential decoding. Althogh "PrevValue" is kept and is necessary for the differential signal, I couldn't see where is it really used.
4.Something not too important, but notice that the bit array is 191, while for() loop is 192, which may lead to writing outside the array.
Wish you luck,
Kolio |
|
|
|
|
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
|