ERG 4910B - Thesis II, 2005-2006 RFID: Data Acquisition Author: Lee Kin Bong Student I.D.: 02657852 Supervisor: Professor K.K. Cheng Associate Examiner: Professor S.P. Wong A project report presented to the Chinese University of Hong Kong in partial fulfilment of the Degree of Bachelor of Engineering Department of Electronic Engineering The Chinese University of Hong Kong April, 2006
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
ERG 4910B - Thesis II, 2005-2006
RFID: Data Acquisition
Author: Lee Kin Bong
Student I.D.: 02657852
Supervisor: Professor K.K. Cheng
Associate Examiner: Professor S.P. Wong
A project report presented to the Chinese University of Hong Kong
in partial fulfilment of the Degree of Bachelor of Engineering
Department of Electronic Engineering The Chinese University of Hong Kong
April, 2006
2
Abstract:
RFID, Radio Frequency Identification, is a popular technology nowadays. It will
replace the traditional bar codes soon as it have advantages on large information–carrying
capacity, physically strong, able to recognize from a distance. Most importance is it can
be completely automatic if we can solve the collision problem between tags. This can
save manpower and prevent man-made mistakes if we can achieve that.
In this project, my main job is to build up an anti-collision system between the tags and
the reader. The collision problems are due to all the tags in the environment reply and
send their own serial number to the reader. Therefore, the reader has to classify the serial
number step by step. I have successfully built up the anti-collision arbitration system on
reader side by binary tree method with the aids of the Manchester coding.
3
Acknowledgements
Special thanks to my supervisor, Professor Michael Cheng Kwok Keung (B.Sc., Ph.D.
(London), Sr.MIEEE, MIEE, CEng (IEE)), for his useful advice and support on my
project, “RFID: Data Acquisition”.
4
Content
ABSTRACT: 2
ACKNOWLEDGEMENTS 3
CONTENT 4
INTRODUCTION 6
Forward Link Encoding 9 Pulse Interval Encoding --- Type A 9 Manchester Coding --- Type B 10
Return Link Encoding 11 FM0 --- Type A and B 11
Collision Arbitration 12 ALOHA procedure --- Type A 12 Binary Tree --- Type B 12
Error Detection 13
CRC Procedure --- Type A and B 13
THEORY 15
Hardware 15 Microcontroller 16 Reset Circuit 16 Oscillator Circuit 17 Traffic control Circiut 17 Power Supply Circuit 18 RS-232 interface conversion circuit 19 Circuit Design 20 Component List 21
Software 22
Programming Principle 22
Program Flow 29 1) Reader Program 29 2) Tag Program 31
Serial Communication 32
5
EXPERIMENTAL PROCEDURE AND RESULT 40
Phase 1 --- Reader Program 41
Phase 2 --- Tag Program 45
Phase 3 --- The Anti-Collision System 47
DISCUSSION AND CONCLUSION 57
COST SUMMARY 59
REFERENCE 60
PROGRAM SOURCE CODE 61
The reader program: 61
Tag Program: 68
PHOTO OF CIRCUIT 75
APPENDIX 76
6
Introduction
Radio Frequency Identification (RFID) Systems fall into two basic categories. The
categories are broadly determined by how the tags powered, which in turn reflects the
average transponder price. The transponder categories are:
• Active RFID tags backscatter modulation (battery on board) [cost EU 10 – 40]
• Passive RFID tags backscatter modulation (RF powered) [cost less than EU 2.50]
My project is focus on the passive RFID, which is cheaper but comparably with a
shorter transmitting distance than active one. But with the backscattering technique, it can
still typically achieve 3m transmitting length, which are suitable for most of application.
Also, because of the cost and the size, passive RFID have a potential to replace the bar
code in the future.
Radar can be considered as the technology precursor to RFID. They are both using the
phenomenon of RF reflection. The radar use the time difference between the signal sent
and reflected back to calculate the distance from an object. For RFID, the reflected signal
carries importance information to the reader (e.g. the serial number of the product). This
technique is using the method of backscattering.[1]
7
Like WLAN card, we need to define the standard for the RFID to assure the
communication is universal. There are many standards for RFID, but the common use is
the ISO18000 (Information technology -- Radio frequency identification for item
management). ISO18000 divide into six parts:
ISO18000-1: Reference architecture and definition of parameters to be standardized
ISO18000-2: Parameters for air interface communications below 135 kHz
ISO18000-3: Parameters for air interface communications at 13,56 MHz
ISO18000-4: Parameters for air interface communications at 2,45 GHz
ISO18000-6: Parameters for air interface communications at 860 MHz to 960 MHz
ISO18000-7: Parameters for active air interface communications at 433 MHz
My project follows some of the requirements in ISO18000-6. According to
ISO18000-6, the RFID in to two types: Type A and Type B [2]
Table 1.1 – Comparison of Type A and Type B [2]
8
Figure 1.1 - Interrogator architecture [2]
Figure 1.2 — Type A tag architecture [2] Figure 1.3— Type B tag architecture [2]
For the protocol of reader, there is some points importance:
1) Forward Link Encoding
2) Return Link Encoding
3) Collision arbitration
4) Error Detection
9
Forward Link Encoding
Pulse Interval Encoding --- Type A
Because this coding has the short pulse duration, it can give continuous power
supply. As a result, it is mainly use in Reader to Transponder.
Original Data Signal Sent
Logic 0 A pulse of duration 2t before next pulse
Logic 1 A pulse of duration t before next pulse
Table 1.2a --- Logic table of Pulse Interval code
Figure 1.4a --- Pulse symbol represent different logic
10
Manchester Coding --- Type B
The Machester code is often used for data transmisson from the transponder to the
reader based upon load modulation using a subcarrier. [3] The princple of signal coding is
stated at below table:
Value Sent
Logic 0 0 to 1 (upward transition at bit centre)
Logic 1 1 to 0 (downward transition at bit centre)
Table 1.2b --- Logic table of Manchester code
For example:
Figure 1.4b --- Encoding of 11011000100 in Manchester code
11
Return Link Encoding
FM0 --- Type A and B
FM0 is usually used for the signal receiving. The level is inverted at the start of every bit
period, so that the bit pulse can be more easily reconstructed in the receiver if necessary.
The princple of signal coding is stated at below table:
Value Sent
Logic 0 Changing pulse(“1 to 0” or “0 to 1”)
Logic 1 Constant Pulse
Table 1.3 --- Logic Table for FM0
For example:
Figure 1.5 --- Encoding of 10110001 in FM0
12
Collision Arbitration
ALOHA procedure --- Type A
This is method using the technique of Carrier Sense Multiple Access. The procedure is
used exclusively with read-only transponders, which generally have to transfer only a
small amount of data (serial numbers), this data being sent to the reader in a cyclical
sequence. The data transmission time represents only a fraction of the repetition time, so
there are relatively long pause between transmissions. Furthermore, the repetition times
for the individual transponders differ slightly. There is therefore a certain probability that
two transponders can transmit their data packets at different times and the data packets
will not collide with one another.
Binary Tree --- Type B
The binary tree method uses the principle of tree diagram to filter out the binary serial
number step by step until no collision occurs. I will discuss it later on page 22.
Diagram 1.6 – tree diagram
13
Error Detection
CRC Procedure --- Type A and B
CRC (cyclic redundancy check) procedure was originally used in disk drives, and can
generate a checksum that is reliable enough even for large data quantities. However, it is
also excellently suited for error recognition in data transfer via wire-bound (telephone) or
wireless interface (radio RFID) [3].
The principle of CRC is base on polynomial division. First we need to define the CRC
checksum, which is calculated by the division of a polynomial
We can consider the binary number as polynomial, e.g.
10011 = X^4 + 0^3 + 0^2 + X^1 + X^0
= X^4 + X^1 +1
Let: M - k bits long, F - It is n bits long (n<k)
T - It is k+n bits long P - A pattern of n+1 bits
First we convert all of them to polynomial, and let
T = M*x^n + F
If we divide M*x^n with P, M*x^n/P = Q +R/P
We let the remainder R as F, T = M*x^n +R
T/P = M*x^n/P +R/P = Q + R/P + R/P = Q +(R+R)/P
As binary number added to itself in a modulo 2 field is zero, therefore: T/P = Q no
remainder
14
We can consider:
- M as Original Frame ,
- F as CRC checksum value
- T as Resulting Frame to transmit
- P as generator polynomial
The principle of CRC is to check whether T is divided by P
We have to pre-define the generator polynomial before the system can communicate:
#include <stdio.h> #include <math.h> #include <regx51.h> void putc(char c); void demanch(); void uart(unsigned short int a); void manch(unsigned short int manch_in); unsigned short int b[8], c[16]; unsigned short int a; int i, j=15, col, col_b, rec_data, rec_data_temp=0; unsigned short int bytedata[2]={0,0}; unsigned short int byte_rec=0; unsigned short int end=0; void main() { unsigned short int con_sig=0xFF; int x, y, z; while(1) { P0_0=0; /*open transmission to tags*/ P0_1=1; byte_rec=0; rec_data=0; SCON = 0x50; /*uart in mode 1 (8 bit), REN=1*/ TMOD = 0x20; /* Timer 1 in mode 2*/ TH1 = 0xA0; /*300 Bds at 11.059MHz*/ TL1 = 0xA0; /*300 Bds at 11.059MHz*/ ES = 1; /*Enable serial interrupt*/ EA =1; /*Enable global interrupt*/ TR1 = 1; /*Timer 1 run*/
62
/*continue sending the request signal until reply*/ while((bytedata[0]==0&&bytedata[1]==0)||(bytedata[0]==1&&bytedata[1]==1)) { putc(0xFF); /*Request command*/ manch(con_sig); /*Request Number*/ for(x=0; x<300; x++) /*wait 0.3 second*/ for(y=0; y<10;y++) for(z=0; z<120; z++); } demanch(); /*Manchester Decode*/ if (col==1) /*If collision occur*/ { switch(col_b) /*Setting the request number for specific collision*/ { case 7: con_sig=0x7F; break; case 6: con_sig=0x3F; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 5: con_sig=0x1F; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 4: con_sig=0x0F; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break;
63
case 3: con_sig=0x07; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 2: con_sig=0x03; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 1: con_sig=0x01; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; case 0: con_sig=0; for (i=7; i>col_b; i--) con_sig=con_sig + (int)(b[i]*pow(2, i)); break; default: con_sig=0xFF; } } else /*if no collision occur*/ { rec_data_temp=rec_data; con_sig=0xFF; byte_rec=0; rec_data=0; putc(0xF0); /*send the SELECT signal*/ manch(rec_data_temp); for(x=0; x<300; x++) /*delay 0.3 seconds*/ for(y=0; y<10; y++) for(z=0; z<120; z++); demanch();
64
/*send to computer if the serial number received is same as before*/ if (rec_data_temp==rec_data) { P0_0=1; P0_1=0; putc(rec_data); } } } } void putc(char c) /*send 8bit number through UART*/ { SBUF=c; while(!TI); TI=0; } void demanch() /*Manchester Decoding*/ { j=15; rec_data=0; col=0; col_b=0; for (i=15; i>=8; i--) { c[i] = (int)(bytedata[0]/pow(2, (i-8))); bytedata[0] = bytedata[0]%(int)(pow(2, (i-8))); } for (i=7; i>=0; i--) { c[i] = (int)(bytedata[1]/pow(2, i)); bytedata[1] = bytedata[1]%(int)(pow(2, i)); }
65
for (i=7; i>=0; i--) { if (c[j]==1) { if (c[j-1]==0) { b[i]=1; j=j-2; } else /*collision occur*/ { col=1; col_b=i; break; } } else { if (c[j-1]==1) { b[i]=0; j=j-2; } else /*collision occur*/ { col=1; col_b=i; break; } } } if (col==0) { for (i=7; i>=0; i--) rec_data = rec_data + (int)(b[i]*pow(2, i)); } bytedata[0]=0; bytedata[1]=0; }
66
void manch(unsigned short int manch_in) /*Manchester Coing*/ { j=15; for (i=7; i>=0; i--) { b[i] = (int)(manch_in/pow(2, i)); manch_in = manch_in%(int)(pow(2, i)); } for (i=7; i>=0; i--) { if (b[i]==1) { c[j]=1; c[j-1]=0; j=j-2; } else { c[j]=0; c[j-1]=1; j=j-2; } } a=0; for (j=15; j>=0; j--) { a=a+c[j]*(pow(2, j)); } uart(a); }
67
void uart(unsigned short int a) /*send 16bits signal through UART*/ { SBUF = (a>>8); while(TI!=1); TI = 0; SBUF = a; while(TI!=1); TI = 0; } void getc(void) interrupt 4 using 1 /*receive 16bits data through UART*/ { if(RI) { if(byte_rec>=1) { end=1; } bytedata[byte_rec]=SBUF; byte_rec++; RI=0; } }
68
Tag Program:
#include <stdio.h> #include <math.h> #include <regx51.h> void demanch(); void uart(unsigned short int a); void manch(unsigned short int manch_in); void putc(char c); int b[8], i, j=15, k, c[16]; int col, col_b; int rec_data; int bytedata[3]=(0,0,0); int byte_rec=0; int end=0; void main() { unsigned short int sn=0xCB; /*set the serial number*/ int mode=1; P0_0=1; /*open the transmission*/ SCON=0x50; /*UART in mode 1 (8 bit), REN=1*/ TMOD=0x20; /*Timer 1 in mode 2*/ TH1=0xA0; /*300 Bds at 11.059MHz*/ TL1=0xA0; /*300 Bds at 11.059MHz*/ ES=1; /*Enable serial interrupt*/ EA=1; /*Enable global interrupt*/ TR1=1; /*Timer 1 run*/ while (mode==1) { do{ }while(end==0); /*Wait Command*/ P0_0=1; /*open the transmission*/
69
if (bytedata[0]==0xF0) /*if SELECT command received*/ { demanch(); if (sn==rec_data) { P0_0=1; manch(sn); P0_0=0; mode=2; /*enter mode 2, not response to SEL and REQ command*/ }
else /*if the serial number received before and after the SEL signal sent not the same, set the transmission close.
{ P0_0=0; manch(sn); P0_0=1; } bytedata[3]=(0,0,0); byte_rec=0; end=0; } else if (bytedata[0]==0xFF) /*if REQUEST command received*/ { demanch(); if(sn<=rec_data) /*for the case serial number small then the REQ signal,
reply*/ { P0_0=1; manch(sn); } else /*for the case serial number larger then the REQ signal,
reply*/ P0_0=0; /*close the transmission*/ bytedata[3]=(0,0,0); byte_rec=0; end=0; } }
70
while(mode==2) /*After receiving the select signal*/ { do{ }while(end==0); if (bytedata[0]==0xFF) /*if received a request signal, close the transmission,
don’t disturb the other*/ { demanch(); if(sn<=rec_data) { P0_0=0; manch(sn); } else P0_0=0; bytedata[3]=(0,0,0); byte_rec=0; end=0; } } } void putc(char c) { SBUF =c; while(!TI); TI = 0; }