No part of this thises is allowed to be copied
1 King Saud University College of Engineering Department of electrical Engineering Design of a Microcontroller Circuit With USB for M2M Application using GSM Network Master Thesis By: Mohammed A. Al-Dalbehi Supervised by Professor: Mohammed Abu El-Ela Dr. Bandar Al-Mashary March 23, 2008
14 - Facility Managements :Building operators can use M2M to monitor their equipments operation such as energy machines - Medical Application : M2M can be used to collect data from remote diagnostic equipments in patients site ( i.e. Blood pressure ,weight) - Security : sensors can be used to generate alarms when needed And many applications can be found for this active technology M2M networks M2M can be used in many networks like WLAN,WWAN and others networks but the cellular networks ( GSM ,GPRS ) is preferred because of Wide area coverage and High reliability M2M development kits manufactures Today many companies like Ericsson, Nokia and Z world provide M2M kits which can support new networks available The developed Microcontroller circuit will be used with the Sony Ericsson GM47/GM48 module [1] available in the Electrical Engineering department Ericsson lab (see appendix A for its data sheet) Figure I: Sony Ericsson GM47/GM48 module
Chapter 4
Microcontroller with USB interface
4.1 Introduction
This chapter will discuss the most common available approaches to implement USB interface this may lead us to choose one of them to be interfaced with the PicoBlaze core selected in previous chapter.
4.2 Implementation of USB
The proposed solution to establish serial communication using USB protocol is to design a circuit that can handle this communication protocol and interfaced it to the Microcontroller. By looking for a suitable ways to achieve this task two approaches for USB protocol implementation were found:
1- Using a Single IC chip for RS232 to USB conversion with a given Microcontroller circuit equipped with a built-in UART.
2- Using a single chip parallel to USB conversion with any Microcontroller circuit, only one 8-bits port is needed.
But as extra work to improve the design we start thinking to develop a soft core for the USB protocol that can be integrated with a given Microcontroller core.
In this section each one of the above approaches will be explained in details and by the end of this chapter the chosen one will be applied.
4.2.1 USB Cores for FPGA
Any USB device should be able to have interface with any industry standard Microcontroller on one side and with any standard USB transceiver on the other side.
The core should implement all functionality required at physical (digital) layer and protocol layer of USB specification.
4.2.1.1 Physical Layer
This layer is responsible of:
- Synchronization (DPLL)
- NRZI decoding / encoding
- Bit stuffing /un stuffing
- Parallel to serial conversion
- serial to Parallel conversion
this layer is simply divided into a transmitter and receiver , the transmitter converts the data from Parallel to serial , stuff zero bits if needed then performs encoding process .The receiver performs decoding process, un-stuff zeros if needed then converts the data from serial to Parallel
4.2.1.2 Protocol layer
This layer is the layer responsible for understanding the host requests and doing the proper actions. To develop this layer all fields and packets which is descried in chapter 2 for USB must be generated.
Several trials had been done during this work to get a working core for this layer. No dedicated block diagrams for this layer were available. On the other hand most of the available free cores either those written in Verilog, System C or even in VHDL have limited operational descriptions. Several efforts were done to put them in operation but unfortunately they did not work. By contacting the owners of these cores, some of them did not answer at all, while others demanded high price for their help. Other approach was to contact companies that supply soft cores with full documents. The obtained prices for USB cores are very high and out of the budget of this work. Also, they asked for some justifications from the university that this core will not be used in industrial applications or for developing any commercial product.
From the above it was concluded that we have to address the hardware solution as proposed to implement the USB circuit, and in this case two choices, as regarding the Microcontroller interfacing, are available:
1- Serial Interfacing to Microcontroller
2- Parallel Interfacing to microcontroller.
Both of these techniques will be introduced and analyzed.
4.2.2 Serial Interfacing to Microcontroller
This technique is the commonly used by most of the designers. Most of the available off-shelf Microcontroller has built-in UART circuit. The RS 232 serial interface is a well known serial data link, understood by most of the designers and almost all serial interfaces for peripheral devices outside the physical layer of a given Data Terminal Equipments (DTE) are built using this interface [12]. So, the most straight forward solution from the IC,s manufacturing companies was to develop a single chip that converts between the RS232 and the USB physical and protocol layers. Typical example for this solution is that given by Maxim [13] that impalements USB interface with the PIC Microcontroller by using the FT 232BM as shown in Figure 4.1
Figure 4.1: Maxim implementation for the USB to Microcontroller through UART
Several other implementations are also available in literature. One disadvantage of this solution is the limitation of speed imposed by the maximum data rates supported by the RS232 serial data link [3]. The USB physical circuit can support higher data rates and this may be accomplished by going to parallel interfacing.
4.2.3 Parallel Interfacing to Microcontroller
Recently, introduced in the market some IC chips that work as USB peripheral controller with parallel interface such as the PDIUSBD12 from Philips semiconductor [14] and the FT245R from FDTI [15]. Since we have parallel interface (ports) in PicoBlaze Microcontroller Core that may provide high connection speed (compared to Serial) FT245R parallel to USB chip will be used (see appendix C for its data sheet). Figure 4.4 gives the block diagram of this circuit where we can identify the following blocks:
Figure 4.2: block diagram of the FT245R chip
4.3 Hardware verification of Microcontroller Core with USB interface
From the previous section it clearly that using a USB chip with Parallel Interfacing can be used and eliminate the speed restriction of using USB chip with serial interface. In chapter 3 a PicoBlaze core for Microcontroller was selected to be the used Microcontroller in this study
In order to test the PicoBlaze micro controller core with the USB chip FT245R an emulation testing board is needed. This board enables us to download the microcontroller code onto the FPGA chip, make all the possible connections with the FFT245R chip and provide USB standard socket. This board consists of four parts:
Part 1: FPGA test and development board containing the target FPGA chip with all the necessary hardware and software facilities that enable downloading, testing and verifying a given VHDL code.
NEXYSII board was chosen and supplied from Digilent Company [16], one of the most popular companies for manufacturing development boards. Its schematic diagram is given in appendix D, however, its Data sheet is not completed yet and it is under preparation figure 4.3 showing this board.
Figure 4.3: NEXYSII board
Part 2 : An extension board (FX2BB ) that can be attached to the board of part1 to allow adding more hardware components needed for system building .
Part 3: FT245R USB chip
Part 4: the Physical implementation of the USB B jack
A proposed test configuration is given in Figure 4.4
Figure 4.4: proposed block diagram for Microcontroller with USB
4.4 Experimental work
The block diagram given in Figure 4.4 is completely built in the laboratory and used to verify the hardware functionality of the proposed design. The test is divided into three steps:
Step1: testing the PicoBlaze VHDL code as written to impalement the Microcontroller on NEXYSII board
Step 2: Integrate the hardware built in step1 with the FT245R chip and prepare the USB physical connection.
Step 3: Writing the necessary VHDL codes to achieve the proposed solution to get Microcontroller with USB interface
Step 4: Testing the overall circuit by establishing a serial communication connection with the USB interface of any computer host using familiar communication package like Hyper Terminal under windows [26].
4.4.1 Hardware verification of PicoBlaze testing code
In section 3.3.5 one basic program to read switched and update LED’s accordingly for PicoBlaze Microcontroller core was simulated using Aldec tool, now we need to test this program in real signal environment. Since Xilinx FPGA will be used here, another tool from Xilinx (ISE 9.1) [11] is recommended for programming and downloading. This version was used during this study.
By synthesizing the codes in section 3.3.5 and downloading this code into the target FPGA on board NEXYSII the circuit may be experimentally tested .figure 4.5 shows that the code given in section 3.3.5 is verified experimentally and it is clear that the LEDs are reflecting the status of the switches
Figure 4.5: Hardware verification for PicoBlaze code
4.4.2 Integrating the FPGA board (NEXYSII) with (FT245R) USB Chip
Integration of the Microcontroller PicoBlaze core downloaded on the FPGA with the USB Chip (FT245R) needs the following steps:
1- Doing a correct assignment for the FPGA pins to handle the input output ports and other control pins, in this board version some pins assigned only for serial inputs/outputs, the proper pins should be used.
2- The pins which have been assigned are already connected to the extended board FX2BB connector, since NEXYSII is a new board and its datasheet is still under preparation, the schematic of the board and the layout should be used to trace the connection.
3- Wiring the connections of the extended board FX2BB to the USB chip FT245R.
Figure 4.6 shows on board connection of the system.
Figure 4.3: Microcontroller with USB on board
Figure 4.6: Microcontroller with USB on board
4.4.3 Assembly and VHDL codes for Microcontroller with USB
As can be seen in figure 4.5 the Hardware is completed and need to be tested, so the next step is to write an assembly code for PicoBlaze Microcontroller and VHDL code for all the system.
4.4.3.1 PicoBlaze assembly program for Microcontroller with USB
This program reads the status value of 8 switches in hex format. This value is then transferred to the attached PC through the built USB interface and displayed using the Hyper Terminal under windows as the ASCII equivalent of read HEX value. On the same time any character entered by the key board of the PC through the Hyper Terminal window will be displayed on the 8 LED display of the NEXYSII board. A reset function of all LED is also available.
This assembly program contains the following parts:
1- the definition of all constants in addition to the ASCII table
2- USB communication routines
This routines is the main part of the assembly program since it will handle the reading and writing from/to the USB chip.
a- Sending to USB
Microcontroller will transmit data to USB chip using this routine and at the beginning of this routine the program will read the control port then test the transmit buffer is it empty or full if empty the data port will be loaded by the data and the write to USB chip bit in the control port should be set send data to the USB chip and finally the control port should be rest to be ready.
b- Read from USB
In this routine the Microcontroller will read from the USB chip and this will be done by testing if there is a data in data buffer of the chip or not and read it if existing then reset the Zero flag to use it again in other process
3- the main program
This part will contain the sending menu text and waiting the input of the user to choose reading switches and update LED’s or reset the LED’s
4- reading Switches routine
To read switches value and send it to the USB chip to show it in the terminal program
5- Updating LED’s routines
To Update LED’s with the Value which the user interred
6- Text messages
These routines will send the text messages to the terminal such as menus and it will be done by sending character by character
For all the program (See appendix E)and this program will be converted to ROM VHDL code using PicoBlaze assembler which was provided by Xilinx and will be added to the VHDL code in next section to complete all VHDL codes that are needed to test the proposed solution
4.4.3.2 VHDL code for testing Microcontroller with USB interface
The next step is to complete the system VHDL code (see appendix F) and download it to on board FPGA
Figure 4.7 gives the block diagram of VHDL code
Figure 4.7: Block diagram of VHDL code
The top level code is contains of the following parts:
1- the tope level entity that representing the black block in figure 4.7 and assigning the input and output of the system as following
2- declaration of (KCPSM3) the PicoBlaze Microcontroller (see appendix J for the VHDL code for it )
3- declaration of the ROM
4- Signals used to connect KCPSM3 to program ROM and I/O logic
5- Signals used to connect KCPSM3 to USB/FIFO interface and LED’s/Switches
6- Switches, and LEDs connections and USB/FIFO control register connections
7- KCPSM3 input ports
8- KCPSM3 output ports
9- The FPGA will drive USB data bus all the time and need to be released when reading from USB chip
All these codes (the assembly code in ROM which explained in section 4.4.3.1 and the above Top VHDL code) are synthesized and downloaded to the FPGA on NEXYSII board