Title: How to decode Manchester stream bit.
Post by: chithanh04dt2 on February 18, 2009, 03:34:54 03:34
Hello, i'm a student and buiding final project for graduation. It's about RFID reader, I have a problem with decoding Manchester . Could you tell me how to decoding Manchester use PIC, please.
Title: Re: How to decode Manchester stream bit.
Post by: Parmin on February 18, 2009, 11:38:54 23:38
A manchester code sends data as changes in the data line. The beauty of this coding is you can extract the bit rate by measuring the pulses time.
A change from high to low could be read as a 0 where as a low to high could be read as a 1.
so if your original data is 0100 1100 the data to be sent are 10011010 01011010
Original data ---> data to send 0 --> 10 1 --> 01 0 --> 10 0 --> 10
etc.
Decoding the data? just read every second bit of the data and you got the original stuff.
Title: Re: How to decode Manchester stream bit.
Post by: flyback on April 07, 2009, 09:17:42 21:17
you will find a very good example. with source code for PIC http://www.winpicprog.co.uk/pic_tutorial12.htm
Title: Re: How to decode Manchester stream bit.
Post by: mris99 on April 08, 2009, 10:26:45 22:26
Sample Code in C (unknown source): //================================================================ int16 man_encode(int unenc) { //================================================================ int odd_byte,even_byte,temp;
odd_byte=unenc&0xAA; temp=(~unenc&0xAA)>>1; odd_byte=odd_byte|temp;
even_byte=unenc&0x55; temp=(~unenc&0x55)<<1; even_byte=even_byte|temp; return((int16)odd_byte<<8)|even_byte; }
//================================================================ int man_decode(int16 enc) { //================================================================ int odd_byte,even_byte;
odd_byte=(int)(enc>>8); if((odd_byte&0xAA)^((~odd_byte&0x55)<<1)) { receive_error=1; return(0); } else odd_byte&=0xAA; even_byte=(int)enc; if((even_byte&0x55)^((~even_byte&0xAA)>>1)) { receive_error=1; return(0); } else even_byte&=0x55; receive_error=0; return(odd_byte|even_byte); }
And the same in PIC16 assembly (by me): ;***** man_encode ********************************************************* ;* manchester encode ;* Input : unenc ; byte to encode ;* Output: manch16 ; coded word ;* Clock : ? ;************************************************************************** man_encode movf unenc,w ; odd_byte=unenc&0xAA; andlw 0AAh movwf odd_byte
comf unenc,w ; temp=(~unenc&0xAA)>>1; andlw 0AAh movwf TEMP clrc rrf TEMP,f movf TEMP,w ; odd_byte=odd_byte|temp; iorwf odd_byte,f
movf unenc,w ; even_byte=unenc&0x55; andlw 055h movwf even_byte
comf unenc,w ; temp=(~unenc&0x55)<<1; andlw 055h movwf TEMP clrc rlf TEMP,f movf TEMP,w ; even_byte=even_byte|temp; iorwf even_byte,f return
;***** man_decode ********************************************************* ;* manchester decode ;* Input : manch16 ; coded word ;* Output: unenc ; decoded byte ;* Clock : ? ;************************************************************************** man_decode comf odd_byte,w ; TEMP = (~odd_byte&0x55)<<1) andlw 055h movwf TEMP clrc rlf TEMP,f
movf odd_byte,w ; W = (odd_byte&0xAA) andlw 0AAh
xorwf TEMP,w ; W = (odd_byte&0xAA)^(~odd_byte&0x55)<<1)
jz md_input_ok1 ; if((odd_byte&0xAA)^((~odd_byte&0x55)<<1)) {
movlw 1 ; receive_error=1; movwf receive_error
clrf unenc ; return(0); return ; }
md_input_ok1 movlw 0AAh ; else odd_byte&=0xAA; andwf odd_byte,f
comf even_byte,w ; TEMP = (~even_byte&0xAA)>>1) andlw 0AAh movwf TEMP clrc rrf TEMP,f
movf even_byte,w ; W = (even_byte&0x55) andlw 055h
xorwf TEMP,w ; W = (even_byte&0x55)^((~even_byte&0xAA)>>1)
jz md_input_ok2 ; if((even_byte&0x55)^((~even_byte&0xAA)>>1)) {
movlw 1 ; receive_error=1; movwf receive_error
clrf unenc ; return(0); return ; }
md_input_ok2 movlw 055h ; else even_byte&=0x55; andwf even_byte,f
clrf receive_error ; receive_error=0;
movf odd_byte,w ; return(odd_byte|even_byte); iorwf even_byte,w movwf unenc
return
|