Manchester decoding
tuki
Posts: 10
I was wondering if there was anyone than can help me out with a problem I am having. I built an RFID reader and now I have to decode the data from the tag. Attached is the data sheet for the tags I am using. From what I understand, the tag sends back it's information encoded in Manchester. Basically a transition from logic low to logic high is considered a binary 1 and a transition from logic high to logic low is considered a 0. The data sheet explains this in greater detail but that's the idea. I am going to be honest and admit that I am not very good at programming and I have never used the Propeller before.
I know what I have to do I just do not know how to translate it in code and since I have never used Spin my problem becomes that much worse. This is how my reader works:
When there is no tag near the antenna, the output is always high (between 5 and 6 volts). When the tag gets in the readers range, the output sends back 9 1's (so low to high nine times) and then the data, 64 bits in total including the initial ones, and it keeps resending the data as long as it is in the range. What I have to do is, once the data starts transmitting, read what state the output is in, either low or high (logic 0 or logic 1), whenever there is a rising edge on the clock.
Pretty simple I know but I don't know spin and I have to finish this project by next week or else i will not graduate. What I want for the program to do is wait until there is a falling edge in the input data and branch to a subroutine where every time there is a rising edge in the external clock the program saves the data, either logic low or high, 64 times since there are 64 bits of data being sent from the tag. After all 64 bits have been saved I would have to wait until the tag leaves the range at which point the input data goes back to high. If there's any way of checking for a pulse in one of the pins of the micro would be perfect for that.
If someone could help me out with this i would greatly appreciate it since i do not know any of the commands for the propeller or its capabilities. Thank you in advance.
Victor
Victor
I know what I have to do I just do not know how to translate it in code and since I have never used Spin my problem becomes that much worse. This is how my reader works:
When there is no tag near the antenna, the output is always high (between 5 and 6 volts). When the tag gets in the readers range, the output sends back 9 1's (so low to high nine times) and then the data, 64 bits in total including the initial ones, and it keeps resending the data as long as it is in the range. What I have to do is, once the data starts transmitting, read what state the output is in, either low or high (logic 0 or logic 1), whenever there is a rising edge on the clock.
Pretty simple I know but I don't know spin and I have to finish this project by next week or else i will not graduate. What I want for the program to do is wait until there is a falling edge in the input data and branch to a subroutine where every time there is a rising edge in the external clock the program saves the data, either logic low or high, 64 times since there are 64 bits of data being sent from the tag. After all 64 bits have been saved I would have to wait until the tag leaves the range at which point the input data goes back to high. If there's any way of checking for a pulse in one of the pins of the micro would be perfect for that.
If someone could help me out with this i would greatly appreciate it since i do not know any of the commands for the propeller or its capabilities. Thank you in advance.
Victor
Victor
pdf
133K
Comments
As·a 8bit data-byte is manchester-encoded to 16bits to make sure there are no 1 or 0 twice in a row.
A 256 entry lookup table would be fast, anyone have a source for such a table?
http://www.quickbuilder.co.uk/qb/articles/index.htm
Post Edited (tonyp12) : 5/16/2009 2:13:09 PM GMT
So you want to tell us that they only gave you one week for this project including learning a programming language? Hmmm ... not sure if I'll believe you. My guess is that you were to lazy to start earlier and now you want us to do your work.
I'd say ctra and ctrb are your friends for this task, together with waitpeq/waitpne. If you have a look at the signal, you can see that you simply have to detect the long pulse or the long pause for·switching from reading 1 to reading 0 (or from 0 to 1). If the pulse or the pause is short you simply repeat shifting in the same bit as before.
In the beginning we expect nine 1 bits to be send. So with each low edge, we·received an additional·1. We only measure the time that the signal is high, because if we find a longer high-time·we know that we received a 0 bit. Now with each low-high edge we received an additional 0. We masure the low-time and if it is longer we received a 1.
This pretty much looks like a·perfect usecase for a state machine.
Counter A would be setup as a POS detector, counter B as a NEG detector. This way, the hardware is taking care of measuring the time. You can find a nice Application note for Counters in the download-section called "AN001 - Propeller Counters". There you can also find code examples on how to setup the counters.
·
I honestly haven't been lazy. I tried to use another micro for my project but i could not get it to work. I think the micro was just to slow for what i wanted to do. A friend of mine recently lent me his propeller because he said it would be fast enough but he didn't show me how to use it and he left back home . I am honestly trying my best to do it by myself. Here's what I have so far but when I open the terminal, I am supposed to get the same data when the tag is in the readers range but when I pass the tag more than once I don't get the same data. Here's what I have so far:
Post Edited (tuki) : 5/17/2009 3:09:36 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My new unsecure propmod both 1x1 and full size arriving soon.
Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
My code
[noparse][[/noparse] /code ]
is equal to
Besides the fact that your code is ugl... it's only good if you have a 100% reliable signals. Once you get out of sync with the sender, it's totally lost. That's why I meantioned the state machine. You have different states
0 wait for start of transmission
1 receive bits and count 1s
2 receive bits
In state 0 you wait for a clock signal and read the input. We need a 1 to switch to state 1.
In state 1 you wait for a clock and read the input. If 0 go back to state 0 - if 1 count and if count equals 8 switch to state 2 ( the 9nth bit was read in state 0 )
In state 2 read the rest of the bits (counting them) if 55 bits received, go back to state 0
Further improvements could be to check the parity bits while reading. As soon as a transmission was wrong you can switch back to state 0
At least when transmisstion is complete you should check the parity bits to see if you got valid data.
Is Manchester code not a bitwise XOR of the data with a clock signal, if you have clock and data, could you not xor them again to get data?
If you don't have the clock, you can not even XOR it. Then you would use the method I showed in my first post - measuring the pulse and/or pause length.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My new unsecure propmod both 1x1 and full size arriving soon.
Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
Manchester coding encodes a 0 as a 0 to 1 transition and a 1 as a 1 to 0 transition. Or the other way, and yes, there are both standards out there. That seems simple enough. If you send a low into a transmitter, it will produce a nice square wave and if you send that for long enough you can lock onto the signal and use that as a clock. When you do lock on, you need to lock both the frequency and the phase. A 4046 is a good place to start, but it can be done in software too.
Now, this is the tricky bit - as the signal arrives, you will be guaranteed to get a transition at each transition point. But, depending on the data, you may or may not get a transition half way between those two points. For a byte of 01010101 it works fine, but for 11001100 it could be possible to lock onto a clock of half the frequency. So your PLL (or PLL software emulation) needs to be able to lock on and then cope with missing pulses. On a 4046, you can program the lock and capture ranges such that it has a preferred frequency of roughly the desired frequency. And then it helps if it can go +/-10% (say) but not capture at f/2 or f*2. Again, that is easy in software if you know the approximate frequency of the signal, which I think you would with RFID.
So you need send a Low into the transmitter (hopefully the RFID sends out some pulses to initialise), lock onto the 0 to 1 transition (or the 1 to 0?!), set a clock going, keep testing for transitions at that point (either L to H or H to L) and tweak the clock frequency every pulse. Once locked, you ignore transitions outside a capture range of +/-10% of where you expect one to be, so this will miss the transitions in between pulses (which will be there most of the time). Then you take the clock frequency, divide it by 4, wait 3/4 of the time your clock period, and sample the input at that time.
Finally, you need to recover from possible errors if the clock gets out of synch.
Not simple. I started with wikipedia, and then started drawing up diagrams for bytes like 00000000 and 11111111 and the tricky ones like 00110011 and 00001111. I'd have all that on a piece of paper before trying to turn it into code.
For code, locking onto the clock, I'd assume there is the initialisation square wave, look for a 0 to 1 transition, set a clock going, work out a clock period, then start looking for the next transition after 90% of that clock period has elapsed, and stop looking for it at 110%. So that narrows the capture range.
This discussion has code for the PicBasic Pro compiler. It is very similar in syntax to Spin, at least in general concepts.
I use PicBasic Pro for external chips that I use for offloading funtions from the Propeller via I2C and other protocols.
Small packages such as 8 pin DIPs are particularly easy to sprinkle around my designs.
Melanie has been a lifesaver - she fills the role of Mike Green and OBC.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
JMH
Post Edited (James Michael Huselton) : 5/18/2009 5:59:08 AM GMT
Method A - no clock available:
You measure pulse and pause times using counter a and counter b. The bits themselve have a defined bit-time or a transfer frequency so to say. This means you have a defined low-time and high-time for each bit. You start with nine 1 bits - always and these can not occur in the data section, as the parity bits will avoid that! Say we have the following bits to send resulting in bitstream below
· 1·· 1· ·1·· 1·· 1·· 1·· 1·· 1·· 1·· 1· ·0··0·· 0·· 1··0·· 0··0·· 1·· 1· ·1·· 1·· 0·· 1·· 1·· 1··0
01 01 01 01 01 01 01 01 01 01 10 10 10 01 10 10 10 01 01 01 01 10 01 01 01 10
So, we measure time of the first 1 an see that it's short, so we shift a 1
Same for the next·8 bits.
The 9th high-time is double as long. So we know that we received a 1 followed by a 0, so we shift·the one·into our receive buffer. And we switch mode: now we measure low-time.
With single low-times we keep on shifting 0 into the receive buffer, with a double low-time we swich mode back to reading 1s.
Method A2 ;o)
Another way came just into my mind ... you can use the serial interface. As the frequency is fixed you simply can take the 'bit' frequency of the manchester as baud-rate. De facto you would then sample half of the bitstream.
· 1·· 1· ·1·· 1·· 1·· 1·· 1·· 1·· 1·· 1· ·0··0·· 0·· 1··0·· 0··0·· 1·· 1· ·1·· 1·· 0·· 1·· 1·· 1··0
01 01 01 01 01 01 01 01 01 01 10 10 10 01 10 10 10 01 01 01 01 10 01 01 01 10
^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· sample points
At the speed of the RFID transmission this should be reliable. Only thing that needs to be changed in the Serial interface is that it has to receive 64 bits.
Method B - somehow the clock is also provided:
Then the bitstream of the previous example would look like that:
01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
01 01 01 01 01 01 01 01 01 01 10 10 10 01 10 10 10 01 01 01 01 10 01 01 01 10
· ^·· ^·· ^···^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^·· ^···^·· ^·· ^·· ^·· ^ sample points
·
With each clock=high we shift in the bit ... that's it.
This is one of the code examples extracted from the Picbasic Pro website replies:
encod_r:
For i=0 TO 7
IF mydata.0=0 Then
encoded.0[noparse][[/noparse]i*2]=0
encoded.0[noparse][[/noparse]i*2+1]=1
Else
encoded.0[noparse][[/noparse]i*2]=1
encoded.0[noparse][[/noparse]i*2+1]=0
EndIF
Next i
Return
Rec_r:
For i=0 TO 7
IF encoded.0[noparse][[/noparse]i*2]=0 Then
IF encoded.0[noparse][[/noparse]i*2+1]=1 Then
mydata.0=0
EndIF
Else
mydata.0=1
EndIF
Next
Return
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
JMH
Post Edited (James Michael Huselton) : 5/18/2009 7:27:57 AM GMT
In my opinion he has to provide the code and we can discuss about it. Giving him some starting-point ideas is sufficient at this point.
In addition, we don't even know the exact setup yet. Do we really have a clock or should we provide the clock because the coil is attached to the prop? What clock is it then, the clock send to the coil (which is 64 cycles per bit) or is it the bit-clock?
@tuki:
What do you think? What's the exact deadline? Do we have the whole week?
Post Edited (MagIO2) : 5/18/2009 8:09:51 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My new unsecure propmod both 1x1 and full size arriving soon.
Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
If the poster truly enjoys the challenge and thrill of intellectual discovery, then why was he asking this forum for help?
Tuki writes "I know what I have to do I just do not know how to translate it in code and since I have never used Spin my problem becomes that much worse."
So, I decided to give him the solution. He still has to translate the code into Spin or Assembly syntax.
This discussion has gotten gone on long enough for me. Time to move on to more interesting things...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
JMH
Post Edited (James Michael Huselton) : 5/18/2009 9:12:46 AM GMT
Finding the nine 1s is exactly what state 0 and 1 of the state-machine should do.
Plus, you will learn something.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
JMH