PIC pin number and name

25
ISOLATED RFID GIFT CARD SYSTEM by Isaac Keunyoung Lim Shaofeng Sun ECE 445 Senior Design Project Spring 2010 Professor: Scott Carney TA: Tamer Rousan May 5th, 2010 Project No. 8 1

Transcript of PIC pin number and name

Page 1: PIC pin number and name

ISOLATED RFID GIFT CARD SYSTEM

by

Isaac Keunyoung LimShaofeng Sun

ECE 445Senior Design Project

Spring 2010Professor: Scott Carney

TA: Tamer RousanMay 5th, 2010Project No. 8

1

Page 2: PIC pin number and name

TABLE OF CONTENTS

1. INTRODUCTION.....................................................................................................................31.1 BACKGROUND...................................................................................................................31.2 OBJECTIVES........................................................................................................................31.3 SPECIFICATIONS................................................................................................................31.4 FEATURES...........................................................................................................................31.5 BLOCK DIAGRAM..............................................................................................................41.6 POWER..................................................................................................................................51.7 MICROCONTROLLER........................................................................................................51.8 PARALLAX RFID READER...............................................................................................51.9 4X4 GRAYHILL KEYPAD......................................................................................................51.10 PI-216 LCD DISPLAY.......................................................................................................51.11 SD CARD AND ET MMC/SD CARD SLOT....................................................................51.12 4MHZ CRYSTAL OSCILLATOR.....................................................................................5

2. DESIGN PROCEDURE............................................................................................................62.1 RFID READER DESIGN.....................................................................................................62.2 BPI-216 LCD DISPLAY & 4X4 GRAYHILL KEYPAD DESIGN.....................................72.3 VOLTAGE REGULATOR DESIGN....................................................................................82.4 CLOCK DESIGN................................................................................................................92.5 SD CARD & ET/MMC CARD SLOT DESIGN.................................................................92.6 PIC18LF4520 DESIGN.......................................................................................................102.7 PCB DESIGN......................................................................................................................11

3. DESIGN VERIFICATION.....................................................................................................123.1 BPI-216 LCD DISPLAY & KEYPAD VERIFICATION...................................................133.2 PARALLAX RFID READER VERIFICATION................................................................133.3 SD CARD & THE MCU (PIC18LF4520)...........................................................................13

4. COST……………………………………………………………………………….……..…144.1 PARTS…………………………………………………………………………..………..144.2 LABOR…………………………………………………………………………..….……15

5. CONCLUSION………………………………………………………………………...……155.1 ACCOMPLISHMENTS………………………………………………………….………155.2 UNCERTAINTIES…………………………………………………………………….…155.3 ETHICAL CONSIDERATIONS…………………………………………………………165.4 FUTURE WORK/ALTERNATIVES…………………………………………………….16

6. REFERENCES………………………………………………………………………………17

2

Page 3: PIC pin number and name

1. Introduction

1.1 Background

Gift and loyalty card services are incorporated in conventional credit card systems. While this enables merchants to conveniently use one machine to implement different features, it is extremely costly. For a fairly simple gift card service, merchants are required to pay monthly subscription fees to service providers in addition to paying for per-transaction fee. Altogether, merchants are forced to submit a significant portion of their gross revenue ranging anywhere from 4.5% to 8.7% for another source to store and edit clientele information. It is against this backdrop that the idea of Isolated RFID Gift Card System has been conceived of.

1.2 Objectives

The main objective is to enable merchants to utilize a gift card machine that does not require them to forfeit any of their profits. It is isolated, meaning that it does not require outside connection to servers that retain memory of all transactions. In fact, the machine itself is the service provider in that it stores memory and completes transactions. Furthermore, RFID cards will replace traditional magnetic stripe gift cards in order to increase the rate at which transactions take place.

1.3 Specifications

The Isolated RFID Gift Card System has the following specifications:

• Enclosure that is 7" x 5" or smaller

• 2 GB SD card storage enabling over 700,000,000 number of clients' data storage with credit up to $999.99 per client.

• RFID reader reading low-cost 125kHz transponder tags

• Transponder tags that contain 240 possible combinations for identification

1.4 Features

The Isolated RFID Gift Card System has the following features:

• 2x16 BPI-216 LCD display

• 4x4 keypad for transaction assistance

• Close-range RFID reader for swift transaction

3

Page 4: PIC pin number and name

• 2 GB SD card

• SD card slot with two LEDs for assistance

• Four 125kHz transponder tags

1.5 Block Diagram

The PIC18LF4520 microcontroller unit (MCU) is at the heart of the system. All data between different components flow in and out of the MCU. Keypad sends signal to the MCU, which sends the enable command to the RFID reader to take in data from the RFID tag. Then, the MCU receives the RFID tag data and sends commands into the SD card in order to retrieve client data. Data is sent back to the MCU from the SD card for transaction to take place. Finally, the MCU sends in new data back to the SD card to save the new balance.

4

Page 5: PIC pin number and name

1.6 Power

RFID reader and the BPI-216 LCD display are connected to +5V DC power supply. The MCU and the SD card are powered to +3.3V using LP2951 voltage regulator to drop the voltage from +5V to +3.3V DC.

1.7 Microcontroller

The PIC18LF4520 MCU is the brain of the system. It processes information from various components and sends commands to the reader, the LCD, and the SD card.

1.8 Parallax RFID Reader

The RFID reader from Parallax is able to read RFID tags at very close range of less than 2.54 cm. This minimizes confusion in cases where there are other cards in the vicinity. When the MCU sends out active low signal to the reader it reads the assigned identification characters of each tags. It then sends the data in serial transmission back into the MCU for interpretation.

1.9 4x4 Grayhill Keypad

This simple keypad has parallel connection to the MCU through which it sends electrical signal for the MCU to interpret for processing.

1.10 BPI-216 LCD Display

This serial display interprets data that is sent from the MCU. The serial connection simplifies the circuit dramatically and opens up pins on the MCU for other uses.

1.11 SD Card and ET/MMCSD Card Slot

The 2 GB SD card is housed in the ET/MMCSD card slot. The SD card will retain all critical data i.e. client identification number and balance. The MCU sends commands to the SD card and the bi-directional port between the MCU and the SD card allows data transmission to take place between the two components. The ET/MMCSD card slot safely houses the SD card with all necessary components such as pull-up resistors and capacitors to protect the card from burning out.

1.12 4MHz Crystal Oscillator

The crystal oscillator is the clock of the system that enabled the MCU to be powered at +3.3V instead of +5V since it does not need to be powered from an outside source itself. This clock was used in conjunction with two 15 pF capacitors.

5

Page 6: PIC pin number and name

2. DESIGN PROCEDURE

2.1 RFID Reader Design

The close-range Parallax RFID reader is able to read transponder tags of 125 kHz and transmit data serially to the MCU at 2400 bps. Because the reader must be powered at +5V DC, the SOUT pin of the reader was connected to PIN_8 of the LP2951 voltage regulator in order to limit the active high voltage to +3.3V DC. The incoming serial data from the RFID reader comes into the MCU through PIN_C7 via PIN_1 of the voltage regulator. The reader, shown below in Figure 2.1 is connected to the voltage regulator instead of the MCU.

Figure 2.1 -- Parallax RFID Reader

The /ENABLE pin, which must be active low to enable the reader to take in data, is connected to PIN_A1 of the MCU. The MCU sends out the command through this port to enable the reader.

6

Page 7: PIC pin number and name

The reader sends 12-byte printable ASCII string into the MCU. The first byte is a start byte of 0x0A and it is followed by ten characters that represent a unique ID and a string terminator stop byte of 0x0D. Figure 2.2 below displays the way content flows from the reader.

Figure 2.2 -- RFID tag transmission

If the tag contains a valid ID of 0F0184F07A, the reader would send the following bytes to the MCU: 0x0A, 0x30, 0x46, 0x30, 0x31, 0x38, 0x34, 0x46, 0x30, 0x37, 0x41, 0x0D.

2.2 BPI-216 LCD Display & 4x4 Grayhill Keypad Design

There are five pins on the BPI-216 LCD Display of which only three are used. The VDD, GND, and SER pins are used for this system. Please refer to figure 2.3 below:

Figure 2.3 -- BPI-216 LCD Display Backside

SER pin is connected to PIN_D0 of the MCU. The MCU sends serial data to the BPI-216 to interpret and display on the screen. This simplified both the system integration and implementation. For the final system, BPS switch was brought down to 2400. It is important to note that the BPI-216 required one full second delay at start up in order to display correctly.

The eight pins of the 4x4 keypads represent four rows and four columns. Pins one through four are rows one through four, and pins five through eight are columns one through four. Pins one through four of the keypad are connected to PIN_B0 through PIN_B3 of the MCU. Pins five through eight of the keypad are connected to PIN_D1 through PIN_D4. Figure 2.4 shows how each keys on the keypad relate to the eight pins.

7

Page 8: PIC pin number and name

Figure 2.4 -- Keypad Table

The MCU has been designed to respond to the keypad in a very clever way. While three rows are set high, if one of the keys in the row that is low is pressed, this forces that row to go high as well with the corresponding column that has now been connected to it. In this case, the MCU assigns a char variable called pressed_key with the ASCII code of the corresponding key that has been pressed. Each process has a delay of 50 ms, which makes this process fast enough for the MCU to fluidly recognize the keys that are being pressed.

2.3 Voltage Regulator Design

The LP2951 voltage regulator brought down the +5V DC supply to +3.3V. This was a critical part in the design because of the SD card's inability to go beyond +3.6V. Because SD card contains such critical data, it was vital for the system to supply it with appropriate voltage during communication.

Two voltage regulators are being used in the system. One regulator is used to bring down the serial data transmission of the reader prior to sending it into the MCU. The other regulator is to power down the +5V DC power supply down to +3.3V, which powers the MCU and the SD card.

8

Page 9: PIC pin number and name

2.4 Clock Design

Initially, FOX 20MHz oscillator was used to clock the MCU; however, because the MCU had to be powered at +3.3V to flawlessly communicate with the SD card, 4MHz crystal oscillator was used instead. The two crystal oscillator pins are connected to PIN_A7 and PIN_A6 of the MCU. Furthermore, two 15 pF capacitors are used to connect each pins to ground. This configuration produced the most stable system upon integration.

2.5 SD Card & ET/MMC Card Slot Design

The SD card transmits data in two different modes: SD and SPI modes. It runs on SD mode by default, but when CS signal is set to be active high it runs on SPI mode. Figure 2.5 below displays pin assignments of the SD card during SPI mode:

Figure 2.5 -- SD Card in SPI

This system needed the SD card to be in SPI mode during data transmission with the MCU. Therefore, CS, DataIn, CLK, DataOut pins are connected to PIN_A0, PIN_C5, PIN_C3, and PIN_C4, respectively. VDD is connected to the LP2951 voltage regulator because it needs to be powered at +3.3V.

9

Page 10: PIC pin number and name

2.6 PIC18LF4520 Design

This LF variant of the PIC18 series has been chosen for its ability to be powered at lower voltage levels. This was a feature that made the communication between the MCU and the SD card more reliable. Furthermore, because it has a RAM space of 1536 bytes, the system could potentially implement a FAT system to organize files on the SD card if it proves to be beneficial in the future. There is no incentive to utilize this feature at the moment, however.

Fortunately, the MCU also has the RX, TX, SDO, and SDI pins separate from each other. With the exception of the TX pin, the other three pins are heavily used in the system, and if RX and SDO shared a single pin or the TX and SDI pins shared a single pin, the system could have had unwanted delays and reliability issues in the future. This was a major improvement from PIC18LF4550 that was chosen in the beginning.

The following pins have been used in the MCU: RA0, RA1, RA7, RA6, RC3, RD1, RD2, RD3, RD4, RC4, RC5, RC7, RB0, RB1, RB2, and RB3. Figure 2.6 below lists the role each pins play in the system:

PIC pin number and name

To Device Device pin number and name

36, RB3 4x4 Matrix Keypad 4

35, RB2 4x4 Matrix Keypad 3

34, RB1 4x4 Matrix Keypad 2

33, RB0 4x4 Matrix Keypad 1

27, RD4 4x4 Matrix Keypad 8

22, RD3 4x4 Matrix Keypad 7

21, RD2 4x4 Matrix Keypad 6

20, RD1 4x4 Matrix Keypad 5

2, RA0/AN0 ET MMC/SD Module 1, Chip Select

18, RC3/SCK/SCL ET MMC/SD Module 5, CLK

10

Page 11: PIC pin number and name

PIC pin number and name

To Device Device pin number and name

24, RC5/SD0 ET MMC/SD Module 2, Data In

23, RC4/SDI/SDA ET MMC/SD Module 7, Data Out

19, RD0 BPI-216 LCD Serial In

3, RA1 Parallax RFID Reader Enable

26, RC7/RX Parallax RFID Reader Serial Out

13, OSC1/CLKI/RA6 4MHz Oscillator XXXX

14, OSC2/CLKO/RA7 4MHz Oscillator XXXX

Figure 2.6 -- Pin Connections

2.7 PCB Design

4.4" x 3.3" PCB is able to directly connect to all components mentioned above. Figure 2.7 is the layout of the PCB design using Eagle and figure 2.8 is the actual PCB with all components attached to it. It has been designed with the intention of minimizing space while all components are able to directly connect to the board itself

11

Page 12: PIC pin number and name

Figure 2.7 -- PCB Board Schematic on Eagle

Figure 2.8 below shows the layout of the PCB board along with the aforementioned components in their respective places.

12

Page 13: PIC pin number and name

Figure 2.8 -- Final System on PCB Board

3. Design Verification

Each individual components of the system had to be tested for reliability prior to integrating them into a one working system. Upon integrating the components, the most important testing took place where the communication between the MCU and the SD card was tested to retrieve, save, and delete data sufficiently at a reasonable rate.

3.1 BPI-216 LCD Display & Keypad Verification

The BPI-216 LCD display was initially running at 9400 baud with the MCU clocked at 20 MHz. With proper software for key recognition running on the MCU, the BPI-216 had to reliably

13

Page 14: PIC pin number and name

display each key pressed on the keypad. It requires at least 750 milliseconds to initialize and be ready to receive data, but under the manufacturer’s recommended settings mentioned above, tests revealed that it is unresponsive. Upon numerous debugging efforts, the display responded to the MCU when delaying the commands by 1000 milliseconds. However, it was largely displaying distorted characters. When the BPI-216 was configured to run at 2400 baud, it began to display characters correctly.

The keypad was responsive, but at the 100 ms delay between each key stroke there was noticeable delay in how quickly characters came out on the screen. Upon further testing the most efficient and effective delay was found to be 50 ms. Under this configuratin, the keypad, the MCU, and the BPI-216 worked flawlessly without any noticeable lag.

3.2 Parallax RFID Reader Verificaiton

The RFID reader was initially configured to run at 2400 baud with the MCU clock running at 20 MHz with FOX oscillator. However, upon realizing that the MCU needed to be powered at +3.3V for reliability issues in communicating with the SD card, a crystal oscillator had to be used instead. When the MCU used the 20 MHz variant, the reader was not able to read the full ten bytes of the unique ID characters. Upon further testing, it was found that the only clock speed that worked with the crystal oscillator was 4 MHz due to unidentifiable reasons. The 4 MHz variant worked seamlessly and did not have any negative impact on the system.

3.3 SD Card & the MCU (PIC18LF4520)

Extensive analysis and design consideration led to the belief that utilizing the FAT file system on the SD card would not yield any noticeable benefits for the end user. Instead, it would waste a tremendous amount of space on the memory card as 512 bytes of blocks would have to be reserved per client in order to use 15 bytes. The remaining 497 bytes would have to go to waste under the rules of the FAT file system. Therefore, the decision was made to allocate data on the SD card starting with the byte address of 0x0001 until the last usable byte address. Ten bytes of unique ID are followed by five bytes that represent the balance that is associated with the ID. The subsequent 15 byte addresses would be that of another client's data and so on.

Tests revealed that the MCU and the SD card communicated well. The MCU was able to send commands to save, retrieve, and delete data from the SD card. However, a problem arose when the power was shut off and turned back on. The system crashed when the MCU sent a delete command. Furthermore, it was not able to consistently relocate saved data. The engineering solution to this problem was to update an int variable called mem_counter to keep track of the last byte address of the used byte spaces in order to prevent the system from searching through the entire 2 gigabytes of byte addresses.

14

Page 15: PIC pin number and name

With the system running the way it has been designed, extensive tests were run to test for reliability. Having purchased ten additional RFID tags, 16 total tags were utilized to take up space on the SD card. The system was operating for a total of 96 hours with power shut downs performed every 24 hours. Total of 60 operations with 16 RFID tags were run throughout the day at every 24 hour interval. Figure 3.1 is a table with the figures to show the results of the test:

Testing Log

Day 1 Day 2 Day 3 Day4

60 operations 60 operations 60 operations 60 operations

16 add account30 transactions14 delete account

14 add account30 transactions16 delete account

16 add account44 transactions

60 transactions

Power off Power off Power off Power off

Figure 3.1 -- Reliability Test Run

The 96 hour test yielded favorable results. There were no noticeable lags or irregularities during transactions, and the components did not appear to be under any significant stress. No components were overheating, and without having been told that the system has been running for 96 hours straight, no one would have guessed that it has been under such stress. With the SD card being able endure more than 100,000 write/erase cycles, the user does not have to be concerned about the reliability of the system.

4. COST

4.1 Parts

Figure 4.1 is displays the cost involved in producing the system. The total cost for parts came out to be $145.44, which is a highly competitive price point.

15

Page 16: PIC pin number and name

Figure 4.1 – Parts & Labor

4.2 Labor

Figure 4.1 also displays the number of hours it took to plan, design, and construct this product. The total labor cost for the system came out to be $9,600. This led to the grant total cost of the project to be $9,745.44.

5. CONCLUSION

5.1 Accomplishments

The Isolated RFID Gift Card System (IRGS) was a success. The goal of the project was to implement a system that is able to use external memory to retain client information for future transactions via RFID card and reader. This was accomplished sucessfully using the components listed above, and this enables the machine owner to implement a gift card system for the fraction of the price of the conventional gift card machines.

5.2 Uncertainties

Without having yet integrated a secondary SD card into the system, it is not completely fool proof. If an unexpected error that has not been detected during the 96 hour test trial arises, there is no security back up at the moment to replace the information that is saved on the main SD card. Hence, an additional MCU and a secondary SD card need to be integrated into the system to enhance security.

16

Page 17: PIC pin number and name

5.3 Ethical Considerations

During the design process, the only ethical consideration was paying dues for utilizing the FAT file system. However, it proved beneficial for all parties involved in the project to discontinue its use.

5.4 Future Work / Alternatives

Secondary MCU and SD card will be added for backup to copy all data from the main SD card. If it proves more beneficial, USB flash drive might be used instead of the SD card. Furthermore, online database for backup security might be a possible option in the near future.

17

Page 18: PIC pin number and name

6. REFERENCES

[1] C Compiler Reference Manual. Custom Computer Services Inc. July 2001.

[2] ADVANCED PIC MICROCONTROLLER projects in C - From USB to SIGBEE with the PIC 18F Series. Dogan Ibrahim.

[3] Programming 8-bit PIC Microcontrollers in C with interactive hardware simulation. Martin P. Bates.

[4] PIC18F2420/2520/4420/4520 data sheet 2004, MICROCHIP.

[5] Microchip AN1045(SD card). Peter Reen, Microchip Technology Inc.

[6] MMC/SD memory card FAT16/FAT32 Driver Technical Manual. embedded-code.com.

[7] SanDisk. Secure Digital Card Product Manual Version 1.9 Document No. 80-13-00169. Dec. 2003.

[8] RFID card reader, Serial(#28140). www.parallax.com

[9] Conductive Rubber Keypads series 96. Grayhill

[10] BPI-216 SERIAL LCD MODULES user’s manual v1.2. Scott Edwards Electronics, Inc.

18

Page 19: PIC pin number and name

19