Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 04, 2016, 11:11:12 23:11


Login with username, password and session length


Pages: [1]
Print
Author Topic: How to decode Manchester stream bit.  (Read 5506 times)
0 Members and 1 Guest are viewing this topic.
chithanh04dt2
Junior Member
**
 Muted
Offline Offline

Posts: 63

Thank You
-Given: 97
-Receive: 9


« on: February 18, 2009, 04:34:54 04: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.
Logged

Sorry for my English.
Regard !
Parmin
Hero Member
*****
Offline Offline

Posts: 544

Thank You
-Given: 357
-Receive: 126


Very Wise (and grouchy) Old Man


« Reply #1 on: February 19, 2009, 12:38:54 00: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.

Logged

If I have said something that offends you, please let me know, so I can say it again later.
flyback
V.I.P
Junior Member
*****
Offline Offline

Posts: 74

Thank You
-Given: 53
-Receive: 28


« Reply #2 on: April 07, 2009, 10:17:42 22:17 »

you will find a very good example. with source code for PIC
http://www.winpicprog.co.uk/pic_tutorial12.htm
Logged
mris99
Junior Member
**
 Warned
Offline Offline

Posts: 38

Thank You
-Given: 7
-Receive: 16


« Reply #3 on: April 08, 2009, 11:26:45 23:26 »

Sample Code in C (unknown source):

Code:
//================================================================
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):

Code:
;***** 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
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC