UART (VHDL) && VGA (Verilog)
UART (VHDL) && VGA (Verilog)
Saurabh Shukla
Table of Contents:
CHAPTER 1: Introduction ................................................................................................................. 6 1. Organization ............................................................................................................................ 6 1.1: Samtel Group Companies ................................................................................................. 6 1.2: Objectives: ............................................................................................................................ 9 1.2.1: UART: ............................................................................................................................. 9 1.2.2: VGA: ............................................................................................................................. 10 CHAPTER 2: Literature Review ...................................................................................................... 11 2.1: FPGA: .................................................................................................................................. 11 2.1.1: Introduction:................................................................................................................ 11 2.1.2: Key Components and Features: .................................................................................. 11 2.1.3: Fast, Asynchronous SRAM: .......................................................................................... 13 2.1.4: Four Digit, Seven Segment LED Display: ................................................................ 15 2.1.5: Switches and LEDs: .......................................................................................................... 17 2.1.5.1: Slide Switches: .......................................................................................................... 17 2.1.5.2: Push Button Switches: .............................................................................................. 18 2.1.5.3: LEDs: ......................................................................................................................... 18 2.1.6: VGA Port: ..................................................................................................................... 19 2.1.7: PS/2 Mouse/Keyboard Port:........................................................................................ 20 2.1.7: RS 232 Port: .............................................................................................................. 21 2.1.8: Clock Sources:.............................................................................................................. 22 2.2: Hyper Terminal: .................................................................................................................. 23 2.2.1: Protocols Supported: ................................................................................................... 23 2.3: VHDL: .................................................................................................................................. 29
Page 1
Saurabh Shukla
2.3.1: Entity: .......................................................................................................................... 29 2.3.2: Architecture:................................................................................................................ 29 2.3.3: Configuration: .............................................................................................................. 29 2.3.4: Package:....................................................................................................................... 29 2.3.5: Driver: .......................................................................................................................... 29 2.3.6: Bus: .............................................................................................................................. 29 2.3.7: Attribute: ..................................................................................................................... 29 2.3.8: Generic: ....................................................................................................................... 29 2.3.9: Process:........................................................................................................................ 29 2.3.10: Logical Operators: ..................................................................................................... 29 2.3.11: Data Type: ................................................................................................................. 30 2.3.12: Operator: ................................................................................................................... 31 2.3.13: Process and sequential statements:.......................................................................... 31 2.3.13: Sequential If statement: ......................................................................................... 32 2.3.14: Signals: ....................................................................................................................... 32 2.3.15: Attributes: ................................................................................................................. 32 2.3.16: Value Attributes: ....................................................................................................... 33 2.3.17: Function Attributes: .................................................................................................. 33 2.3.18: Constants: .................................................................................................................. 33 2.3.19: Constant declaration: ................................................................................................ 33 2.3.20: Entity Ports and Mode:.............................................................................................. 33 2.3.21: Enumerated Types:.................................................................................................... 33 2.3.22: Recipe coding of state machines: .............................................................................. 34 2.3.23: Hierarchy: .................................................................................................................. 34 2.3.24: Port Map:................................................................................................................... 34 2.3.25: User defined Arrays: .................................................................................................. 34
Page 2
Saurabh Shukla
2.4: Verilog: ............................................................................................................................... 35 2.4.1:Abstraction Level of Verilog: ........................................................................................ 35 2.4.2: Gate and Switch delays: .............................................................................................. 36 2.4.3: Identifiers: ................................................................................................................... 37 2.4.4: Data Types: .................................................................................................................. 37 2.4.5: String: .......................................................................................................................... 38 2.4.6: Operators: ................................................................................................................... 38 2.4.7: Procedural Blocks: ....................................................................................................... 39 2.4.8: Blocking Assignment: .................................................................................................. 39 2.4.9: Non Blocking Assignment: ........................................................................................ 39 2.4.10: Conditional Statement if else: ................................................................................ 40 2.4.11: Case Statement: ........................................................................................................ 40 2.4.12: Loop Statements: ...................................................................................................... 40 2.4.13: Continuous Assignment statements: ........................................................................ 41 2.4.14: Propagation Delay : ................................................................................................... 41 2.4.15: Task : .......................................................................................................................... 42 2.4.16: Function: .................................................................................................................... 42 2.4.17: $display:..................................................................................................................... 42 2.4.18: $monitor: ................................................................................................................... 42 2.4.19: $Strobe: ..................................................................................................................... 42 2.4.20: $time : ....................................................................................................................... 43 2.4.21: $Stime:....................................................................................................................... 43 2.4.22: $realtime: .................................................................................................................. 43 2.4.23: $reset:........................................................................................................................ 43 2.4.24: $stop: ......................................................................................................................... 43 2.4.25: $finish: ....................................................................................................................... 43
Page 3
Saurabh Shukla
2.4.26: $random: ................................................................................................................... 43 2.4.27: Initializing Memories: ................................................................................................ 43 2.5: Xilinx ISE Design Suite 13.1: ................................................................................................ 45 2.5.1: Getting started: ........................................................................................................... 45 2.5.2: Create a New Project:.................................................................................................. 45 2.5.3: Create an HDL Source: ................................................................................................. 46 2.5.4: Design Simulation: ....................................................................................................... 47 Chapter 3: Research Methodology/Experimental Setup: ............................................................. 53 3.1: UART: .................................................................................................................................. 53 3.1.1:Introduction.................................................................................................................. 53 3.1.2: Pin diagram of the UART: ............................................................................................ 54 3.1.3: Pin description of the UART: ....................................................................................... 54 3.1.4: Block Diagram of UART:.............................................................................................. 55 3.1.5: Functional Description of UART: ................................................................................. 55 3.1.6: Baud rate generator for Receiver ................................................................................ 56 3.1.7: FSM of Baud rate generator: ....................................................................................... 56 3.1.8: Functional Description of FSM in each state: .............................................................. 57 3.1.9: Baud rate generator for transmitter .......................................................................... 58 3.1.10: FSM of baud rate generator for Transmitter: ........................................................... 58 3.1.11: Functional Description of FSM in each state: ........................................................... 59 3.1.12: UART Receiver sub system: ....................................................................................... 60 3.1.13: Transmitter sub system. ............................................................................................ 63 3.1.14: asynchronous FIFO Interface circuit .......................................................................... 65 3.2: VGA: .................................................................................................................................... 69 3.2.1: VGA Synchronization: .................................................................................................. 69 3.2.2: Horizontal Synchronization: ........................................................................................ 71
Page 4
Saurabh Shukla
3.2.4: Timing Calculation of VGA synchronization signals:.................................................... 74 3.2.5: Overview Of the pixel Generation circuit: ................................................................... 75 3.3: Conclusion and scope for future work. .............................................................................. 79 3.4: Bibliography:....................................................................................................................... 79 3.5: Appendices ......................................................................................................................... 80 3.5.1: VHDL CODE OF UART: .................................................................................................. 80 3.5.2: Verilog CODE OF VGA: ................................................................................................ 93 3.6: RESULT .............................................................................................................................. 119 3.6.1: RTL Schematic View ................................................................................................... 119 3.6.2: Simulated behavioral result ...................................................................................... 125 3.6.3: Result of VGA............................................................................................................. 129 3.6.3.1: Result of Pong Game: ............................................................................................. 129 3.7: ACRONYMS: ...................................................................................................................... 131
Page 5
Saurabh Shukla
CHAPTER 1: Introduction
1. Organization
Samtel Group's journey began in 1973, with a vision to create a world-class organization. Today, Samtel Group is Indias largest integrated manufacturer of a wide range of displays for television, avionics, industrial, medical and professional applications, TV glass, components for displays, machinery and engineering services. The group employs 6000 people in nine world-class factories and has an annual turnover of Rs 12 billion (USD 300M) Samtel Group has strong design and development skills and is a dependable player with excellent technological capabilities and a long-term commitment to the display industry. Its products are known for ruggedness and reliability and conform to the latest relevant quality standards. The group has excellent relationships with suppliers of key components and the ability to design new products as well as set up hi-tech manufacturing facilities. Samtel has registered many patents for developments in display technology and also developed its own technology for automation.
Page 6
Saurabh Shukla
Page 7
Saurabh Shukla
Page 8
Saurabh Shukla
1.2: Objectives:
1.2.1: UART: UART receiver / Transmitter have data bits, stop bits scalable. Baud
generator has its baud rate divisor scalable. Interface circuit (FIFO) its depth scalable. Tested in Spartan 3 starter kit board (FPGA). This Project focuses on the design of high speed UART. The project describing the behavior of UART circuit using VHDL. In the result and simulation part, in the baud rate generator part, UART receiver, UART transmitter. VHDL synthesis is for high reliability systems. UART baud rate of 19200, using 50 MHz system clock rate. The simulated waveforms in this Project have proven the reliability of the VHDL implementation to describe the characteristics and the architecture of the design UART with baud rate generator. UART provide serial asynchronous receiver data synchronization, parallel- to serial and serial to parallel data conversion for both the transmitter and receiver sections. These functions are necessary for converting the serial data stream into parallel data that is required with digital systems. Synchronization for the serial data stream is accomplished by adding start and stop bit to the transmit data to form a data character. UART include a transmitter and receiver. The transmitter is essentially a special shift register that loads data in parallel and then shifts it out bit by bit at specific rate. UART Receiver, on the other hand, shifts in data bit by bit and then reassembles the data. The serial line is high when it is idle. UART transmission starts with a start bit, which is low, followed by data bits and an optional parity bit and ends with stop bits, which is high. The LSB of the data word is transmitted first. No clock information is conveyed through the serial line. Before the transmission starts, the transmitter and receiver must agree on a set of parameters in advance, which include the baud rate. Baud rate , number of bits per second which is 19200.
Page 9
Saurabh Shukla
1.2.2: VGA:
Video Graphics Array is widely supported by PC graphics Hardware and monitors. Basic eight color 640 by 480 resolution interface for CRT monitors. Tested in Spartan- 3 starter kit board(FPGA). The VGA port has five active signal, including the horizontal and vertical synchronization signal. Three video signal for the Red, Green, blue. one horizontal synchronization signal and one vertical synchronization signal. A video signal is an analog signal and the video controller uses a digital to analog converter to convert the digital output to the desired analog level. It is physically connected to a 15 pin D subminiature connector. If a video signal is represented by a N bit word, it can be converted to 2^N analog levels. The three video signals can generate 2^3N different colors. This is also known as 3N bit color since a color is defined by 3N bits. In the S3 board, a 1 bit word is used for each video signal, this leads to only eight (i.e. , 2^3) possible colors. If we use the same 1 bit signal to drive the video signals, they become either 000 or 111 and the monitor functions as a black and white monochrome monitor.
Red (R)
0 0 0 0 1 1 1 1
Green(G)
0 0 1 1 0 0 1 1
Blue(B)
0 1 0 1 0 1 0 1
Resulting color
Black Blue Green Cyan Red Magenta Yellow White
Page 10
Saurabh Shukla
2.1.1: Introduction:
The Xilinx Spartan 3 starter kit provides a low cost, easy to use development and evaluation plat form for Spartan 3 FPGA designs.
Page 11
Saurabh Shukla
16) FPGA configuration mode selected via jumper settings. 17) Push button switch to force FPGA reconfiguration. 18) LED include when FPGA is successfully configured. 19) & 20) & 21) three 40 pin expansion connection ports to extend and enhance the Spartan - 3 starter kit board. 22) JTAG port for low cost download cable. 23) Diligent JTAG download / debugging cable connects to PC parallel port. 24) JTAG download / debug port compatible with the Xilinx parallel cable IV and multi pro desktop tool. 25) AC power adapter input for include international unregulated + 5 v power supply. 26) Power on indicator LED. 27) On board 3.3v regulator. 28) On board 2.5v regulator. 29) On board 1.2v regulator.
Page 12
Saurabh Shukla
FPGA Pin L3 K5 K3 J3 J4 H4 H3 G5 E4 E3 F4
Page 13
Saurabh Shukla
A6 A5 A4 A3 A2 A1 A0
F3 G4 L4 M3 M4 N3 L5
23 24 14 12 10 8 6
External SRAM Control Signal Connections to Spartan 3 FPGA: OE# WE# Output Enable Write Enable.
FPGA Pin K4 G3
Page 14
Saurabh Shukla
Segment A B C D E F G DP
FPGA Pin E14 G13 N15 P15 R16 F13 N16 P16
Digit Enable (Anode control) Signal: Anode Control FPGA Pin AN3 E13 AN2 F14 AN1 G14 AN0 D14
Page 15
Saurabh Shukla
A 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0
b 0 0 0 0 0 1 1 0 0 0 0 1 1 0 1 1
c 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 1
d 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1
e 0 1 0 1 1 1 0 1 0 1 0 0 0 0 0 0
f 0 1 1 1 0 0 0 1 0 0 0 0 0 1 0 0
G 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0
0 1 2 3 4 5 6 7 8 9 A b C D E F
Page 16
Saurabh Shukla
The LED control signals are time multiplexed to display data on all four characters. Present the value to be displayed on the segment control inputs and select the specified character by driving the associated anode control signal LOW. Through persistence of vision, the human brain perceives that all four characters appear simultaneously, similar to the way the brain perceives a TV display. This scanning technique reduces the number of I/O pins required for the four characters. If an FPGA pin were dedicated for each individual segment, then 32 pins are required to drive four 7segment LED characters. The scanning technique reduces the required I/O down to 12 pins. The drawback to this approach is that the FPGA logic must continuously scan data out to the displays a small price to save 20 additional I/O pins.
SW7 K13
SW6 K14
SW5 J13
SW4 J14
SW3 H13
SW2 H14
SW1 G12
SW0 F12
When in the UP or ON position, a switch connects the FPGA pin to Vcco, a logic High. When DOWN or in the OFF position, the switch connects the FPGA pin to ground, logic LOW. The switches typically exhibit about 2 ms of mechanical bounce and there is no active denouncing circuitry, although such circuitry could easily be added to the FPGA design programmed on the board.
Page 17
Saurabh Shukla
Pressing a push button generates a logic high on the associated FPGA pin. Again, there is no active debouncing circuitry on the push button.
2.1.5.3: LEDs:
The Spartan 3 starter kit board has eight individual surface mount LEDs located above the push button switches. The LEDs are labeled LED7 through LED0. LED Connections To The Spartan 3 FPGA: LED LD7 LD6 LD5 LD4 LD3 LD2 LD1 LD0 FPGA Pin P11 P12 N12 P13 N14 L12 P14 K12
Page 18
Saurabh Shukla
Each color line has a series resistor to provide 3 bit color with one bit each for Red, Green, Blue. The series resistor uses the 75 ohm VGA cable termination to ensure that the color signal remain in the VGA specified 0 V to 0.7 V range. 3 Bit Display Color Codes:
Red
0 0 0 0 1 1 1 1
Green
0 0 1 1 0 0 1 1
Blue
0 1 0 1 0 1 0 1
Resulting Color
Black Blue Green Cyan Red Magenta Yellow White
Page 19
Saurabh Shukla
Signal
Data Reserved GND Voltage Supply CLK Reserved
FPGA Pin
M15 ------GND ------M16 -------
Both a PC mouse and keyboard use the two wire PS/2 serial bus to communicate with a host device, the Spartan 3 FPGA in this case. The PS/2 bus includes both clock and data. Both a mouse and keyboard drive the bus with identical signal timings and both use 11 bit words that include a start, stop and add parity bit. However, the data packets are organized differently for a mouse and key board. Keyboard interface allows bidirectional data transfers so the host device can illuminate state LEDs on the keyboard. The clock and data signals are only driven when data transfers occur and otherwise they are held in the idle state at logic high. The timing define signal requirements for mouse to host communications and bidirectional keyboard communications. The keyboard uses open collector drivers so that either the keyboard or the host can drive the two wire bus. If the host never sends data to the keyboard, then the host use simple input pins. A PS/2 style keyboard uses scan codes to communicate key press data. Nearly all keyboards in use today are PS/2 style. Each key has a single unique scan code that is sent whenever the corresponding key is pressed. If the key is pressed and held the keyboard repeatedly send the scan code every 100 ms or so. When a key is released, the keyboard sends a F0 key up code, followed by the scan code of the released key. The key - board sends the same scan code, regardless if a key has different shift and non shift characters and regardless whether the shift key is pressed or not. The host determines which character is intended.
Page 20
Saurabh Shukla
A mouse generates a clock and data signal when moved, otherwise these signals remain high indicating the idle state. Each time the mouse is moved, the mouse send three 11 bit words to the host. Each of the 11- bit words contains a 0 start bit, followed by 8 data bits, fallowed by odd parity bit, and terminated with a 1 stop bit. Each data transmission contains 33 total bits, where bits 0, 11 and 22 are 0 start bits and bits 10, 21 and 32 are 1 stop bits. A PS/2 mouse employs a relative coordinate system where in moving the mouse to the right generates a positive value in the x field and moving to the left generates a negative value in the y field and moving down represents a negative value. The XS and YS bits in the status byte define the sign of each value, where a 1 indicates a negative value.
Page 21
Saurabh Shukla
An auxiliary Rs 232 serial channel from the maxim device is available on two 0.1 inch stake pins, indicated as J1 in the schematic. The J1 stake pins are in the lower left corner of the board, to the right of the DB9 serial connector, below the maxim RS 232 voltage translator and to the left of the individual LEDs. The transmitter output from the maxim device driver the bottom stake pin while the receiver input connects to the top stake pin.
2.1.8: Clock Sources:
The Spartan 3 starter kit board has a dedicated 50 Mhz series clock oscillator source and an optional socket for another clock oscillator source. The 50 Mhz clock oscillator is mounted on the bottom side of the board, indicated. Use the 50 Mhz clock frequency as is or derive other frequencies using the FPGAs digital clock managers (DCMS).
Oscillator Source
50 MHz Socket
FPGA Pin
T9 D9
Page 22
Saurabh Shukla
2.2.1.1: Display:
Minitel, Viewdata, VT100, VT52.
2.2.1.1.1: Minitel:
The minitel is videotext online service accessible through the telephone line and is considered one of the worlds most successful pre-world wide web online services. It was launched in france in 1982 by the PTT(Poste telephone Telecommunications).
Page 23
Saurabh Shukla
From it early days, user could make online purchases, make train reservations, check stock prices, search the telephone directory. Have a mail box and chat in a similar way to that now made possible by the internet.
Page 24
Saurabh Shukla
2.2.1.1.2: Viewdata:
viewdata is a videotext implementation. It is a type of information retrieval service in which a subscriber can access a remote data base via a common carrier channel, receive requested data on a video display over a separate channel. Samuel fedida was credited as inventor of the system. The access, request and reception are usually via common carrier broadcast channels. This is in contrast with Tele text.
Viewdata Graphics used in the experimental phone directory of Post office telecommunications in 1977. The image is a graphical representation of the post office/ British Telecom research laboratories in Suffolk, England. Note the tecontinue rather than the correct # Te continue, showing a common rendering error.
2.2.1.1.3: VT100:
It was introduced in August 1987, following its predecessor, the VT52 and communicated with its host system over serial lone using the ASCII character set and control sequences standardized by ANSI. The VT100 was also the first digital mass market terminal to in corporate Graphic rendition as well as a selectable 80 or 132 column display.
Page 25
Saurabh Shukla
All setup of the VT100 was accomplished using interactive displays presented on the screen, the setup data was stored in non volatile memory within the terminal. The VT100 also introduced an additional character set that allowed the drawing of on screen forms.
2.2.1.1.4: VT52:
The VT52 was a CRT base computer terminal produced by digital equipment corporation introduced in September 1975. It provided a screen of 24 rows and 80 columns of text and supported all 95 ASCII characters as well as 32 graphics characters.
It supported asynchronous communication at baud rates up to 9600 bits per second and did not require any fill characters. The terminal also introduced a separate function keypad that allowed gold key editing.
2.2.1.2.1: ASCII:
Windows 1252 also known as ANSI, other types of extended ASCII, often just called ASCII. All 128 ASCII characters, including non printable characters. The 95 ASCII graphic characters are numbered from 20 hex to 7Ehex (decimal 32 to 126). The space character is considered a non printing graphic.
Page 26
Saurabh Shukla
The American standard code for information interchange is a character encoding scheme originally based on the English alphabet. ASCII code represent text in computers, communications equipment and other devices that use text. Most modern character encoding schemes are based on ASCII, though they support may more characters ASCII does.
2.2.1.2.2: Kermit:
Kermit a computer file transfer, management protocol and a set of communications software tools primarily used in the early years of personal computing in the 1980s. it provides a consistent approach to file transfer, terminal emulation, script programming and character set conversion across many different computer hardware and OS platforms.
The Kermit protocol supports text and binary file transfers on both full duplex and half duplex 8 bit and 7 bit serial connections in a system and medium - independent fashion and is implemented on hundreds of different computer and operating system platforms.
2.2.1.2.3: XMODEM:
XMODEM is a simple file transfer protocol developed as a quick hack by ward Christensen for use in his 1977 modem. ASM terminal program. XMODEM become extremely popular in the early bulletin board system market, largely because it was so simple to implement. It was also fairly inefficient and as modem speeds increased this problem led to the development of number of modified versions of XMODEM to improve performance or address other problems with the protocol. XMODEM like most file transfer protocols, breaks up the original data into a series of Packets that are sent to the receiver, along with additional allowing the receiver to determine whether that packet was correctly received.
MCIS, Manipal University Page 27
Saurabh Shukla
2.2.1.2.4: YMODEM :
It is a protocol for file transfer used between modems. YMODEM was developed by check Forsberg as the success or XMODEM and MODEM 7 and was first implemented in his CP/M YAM program. It was for molly given the name YMODEM in 1985 by word Christensen. The original YMODEM was essentially the same as XMODEM except that at sent the files name, size and time stamp in a regular XMODEM block, block 0, before actually transferring the file. Sending the file size solved XMODEMs problem of super flours padding at the end of the file.
2.2.1.2.5: ZMODEM:
It is a file transfer protocol developed by chuck Forsberg in 1986, in a project funded by telnet in order to improve file transfers on their X.225 network. In addition to dramatically improved performance compared to older protocols, ZMODEM also offered restorable transfers auto start by the sender, an expanded 32 bit CRC and control character quoting, allowing it to be used on networks that might eat control characters. ZMODEM become extremely proper on board systems in the early 1990, displacing earlier protocols such as XMODEM.
Page 28
Saurabh Shukla
2.3: VHDL:
2.3.1: Entity:
Entity is a most basic building block in a design.
2.3.2: Architecture:
Architecture describes the behavior of the entity.
2.3.3: Configuration:
A configuration can be considered like a parts list for a design. It describes which behave to use for each entity, much like a parts to use for each part in the design.
2.3.4: Package:
Package is a collection of commonly used data types and subprograms used in a design.
2.3.5: Driver:
This is a source on a signal. If a signal is driven by two sources, then when both sources are active, the signal will have two drivers.
2.3.6: Bus:
Bus is a special kind of signal that may have its drivers turned off.
2.3.7: Attribute:
Attribute that are attached to objects or predefined data about objects.
2.3.8: Generic:
A generic is term for a parameter that passes information to an entity. If an entity is a gate level model with a rise and a fall delay values for the rise and fall delay could be passed into the entity with generics.
2.3.9: Process:
Process is the basic unit of execution in VHDL. All operations that are performed in a simulation are broken into single or multiple processes.
Page 29
Saurabh Shukla
Page 30
Saurabh Shukla
2.3.12: Operator:
Page 31
Saurabh Shukla
2.3.14: Signals:
Signal behave like wire. Signal can be local to an architecture. Signal have no mode. Signal must have type. Signal carry information between process. Syntax: architecture sig of show is signal_name1, signal_name2 : type. OR Signal signal_name1; signal signal_name2; begin
2.3.15: Attributes:
Provide additional information about many VHDL objects. It can be assigned to most objects including signals, variables, architectures and entities. Many attributes are predefined by VHDL, however user defined attributes are also allowed. VHDL pre- defines five of attributes, dependent on the return value type which can be: value, function, signal, type, range.
Page 32
Saurabh Shukla
2.3.18: Constants:
Useful for look up tables, -- Holding circuit parameters, -- ROM functions. Most be declared before they can be used. Constants can be declared in entity, architecture, process, procedure, package or function.
Page 33
Saurabh Shukla
2.3.23: Hierarchy:
Page 34
Saurabh Shukla
2.4: Verilog:
Verilog is a hardware description language (HDL). HDL is used to describe a digital system for example, a network switch, a microprocessor or a memory or simple flip flop. Verilog is case sensitive. All verilog keywords are lower case. Identifier are name used to given an object, such as a register or a function or a module, a name so that it can referenced from other places in a description. Design Styles: . Bottom up Design . Top down Design
Page 35
Saurabh Shukla
Page 36
Saurabh Shukla
2.4.3: Identifiers:
Identifiers must start begin with an alphabetic character or the underscore character(_). Identifiers may contain (a z, A Z, _ , $). Identifier can be long up to 1024 character.
2.4.4.1: Nets:
Represents structural connections between components.
2.4.4.2: Registers:
Represent variable used to store data.
Page 37
Saurabh Shukla
2.4.5: String: A string is a sequence of characters enclosed by double quotes and all
contained on signal line. One eight bit ASCII value representing one character. No extra bits are required to hold a termination character. \n \t \\ \ \ddd %% New line character. Tab character. Back slash (\) character. Double quote () character. A character specified in 1 3 octal digits. Percent (%) character.
2.4.6: Operators:
Page 38
Saurabh Shukla
2.4.7.1: Initial:
Initial blocks execute only once at time zero.
2.4.7.2: Always:
Always blocks loop to execute over and over again, in other words as name means, it executes always. Always blocks waits for the event, here positive edge of clock, where as initial block without waiting just executed all the statements within begin and end statement. If a procedure block contain more than one statement, those statement must be enclosed within: a) Sequential begin end Block. b) Parallel Fork join Block.
Page 39
Saurabh Shukla
2.4.12.1: Forever:
Forever statement executes continually, the loop never ends. Narmally we use forever statement in initial blocks. Syntax : forever <Statement>. If no timing construct is present in the forever statement, simulation could hang.
2.4.12.2: Repeat:
The repeat loop executes statement fixed <number> of times. Syntax: repeat <Number> <Statement>.
2.4.12.3: While:
The while loop executes as long as an evaluates as true. Syntax : while ().
2.4.12.4: For:
Syntax: for (initial assignment; expression; step assignment); Note : i ++ does not have in verilog. i = i + 1 in verilog.
Page 40
Saurabh Shukla
Saurabh Shukla
Syntax: a = # 10 2.{intra assignment}. Modeling combo logic with continuous assignments, whenever any signal changes on the right hand side, the entire right hand side is re evaluated and the result is assigned to the left hand side.
2.4.15: Task :
Task are used in all programming languages, generally known as procedures or sub routines. Task are defined in the module in which they are used. It is possible to define task in separate file and use compile directive include to include the task in the file which instantiates the task. Task can include timing delays, like posedge, negedge, #delay and wait. Task can have any number of I/P and output. The variables declared within the task are local to that task. Task can take, drive and source global variables, when no local variables are used. Task can call another task or function. Task can be used for modeling both combinational and sequential logic. Task begin with keyword task and ends with keyword task. Local variables are declared after I/P and O/P declaration.
2.4.16: Function:
Function is same as task, with very little difference, like function can not drive more then one output, can not contain delays. Function can not include timing delays, like posedge, negedge, #delay. Function executed in zero time delay. Function can have any number of I/P but only one output. Function can call other functions, but can not call task.
2.4.17: $display:
Display once every time they are executed.
2.4.18: $monitor:
Display every time, one of its parameters changes.
2.4.19: $Strobe:
Display the parameters at the very end of the current simulation time unit rather than exactly where it is executed.
Page 42
Saurabh Shukla
2.4.20: $time :
Return the current simulation time as a 64 bit.
2.4.21: $Stime:
Return the current simulation time as a 32 bit.
2.4.22: $realtime:
Return the current simulation time a real number.
2.4.23: $reset:
It resets the simulation back to time 0.
2.4.24: $stop:
Halts the simulator and puts it in the interactive mode, where user can enter commands.
2.4.25: $finish:
exits the simulator back to the operating system.
2.4.26: $random:
it generates a random integer every time it is called. Note : %d %h %b %c %s %5d decimal hexadecimal binary character string gives exactly 5 spaces for the number.
Page 43
Saurabh Shukla
2.4.27.1: $redmemb:
It is used for binary representations of memory content.
2.4.27.2: $readmemh:
it is used for hex representation of memory content.
Page 44
Saurabh Shukla
Enter or Browse to allocation (directory path) for the new project. A tutorial subdirectory is created automatically. Verify that HDL is selected from the Top Level source type list click Next Fill in the properties in the table as shown below:
Product category Family Device Package Speed Grade Top Level Source Synthesis Tool Simulator Preferred Language
All Spartan 3 XC3S200 FT256 -4 HDL XST (VHDL/Verilog) ISE simulator (VHDL/Verilog) VHDL/Verilog
. Click Next.
Page 45
Saurabh Shukla
2.5.3.1: Creating a VHDL /Verilog Source: . Click the New Source button in the New Project Wizard.
. Select VHDL module/Verilog module. . Type the file name. . Verify that the Add to Project check box is selected. . Click Next. . Click Finish.
2.5.3.2: Checking the Syntax of the design source: . Verify that Synthesis/Implementation is selected from the drop down list in the
sources window.
. Select the design source in the sources window to display the related processes in the
processes window.
. Click the + next to the synthesize XST process to expand the process group. . Double Click the check syntax process. . Close the HDL file.
Page 46
Saurabh Shukla
2.5.4.1: Verifying Functionality using Behavioral Simulation: . Select the design HDL file in the sources window.
. Create a new test bench source by selecting project New Source.
. In the New Source wizard, select test bench waveform as the source type and type design_TB in the file name field. . Click Next. . The associated source page shows that you are associating the test bench wave form with the source file design. Click Next. . The summary page shows that the source will be added to the project and it displays the source directory, type and name. Click Finish. . The requirements for this design are the following: a) The counter must operate correctly with an input clock frequency = 25MHz. b) The direction input will be valid 10ns before the resing edge of clock. c) The output must be valid 10ns after the rising edge of clock. . Fill in the field in the initialize timing dialog box with the following information. a) Clock High Time : 20ns. b) Clock Low Time : 20ns. c) Input Setup Time : 10ns. d) Output valid Delay : 10ns. e) Offset : on f) Global Signals : GSR (FPGA). g) Initial Length of Test Bench : 1500ns. . Click Finish to complete the timing initialization.
Page 47
Saurabh Shukla
Page 48
Saurabh Shukla
Page 49
Saurabh Shukla
Page 50
Saurabh Shukla
Page 51
Saurabh Shukla
L) Assign New configuration file dialog box appears to assign a configuration file to the XC3s200 device in the JTAG chain. M) If you get a warning message. Click ok. N) Select bypass to skip any remaining devices. O) Right click on the XC3s200 device image and select program. P) Click OK. Q) Close iMPACT without saving.
Page 52
Saurabh Shukla
3.1.1:Introduction
An UART (universal asynchronous receiver/transmitter) is responsible for performing the main task in serial communications with computers. The device changes incoming parallel information to serial data which can be sent on a communication line. UART is circuit that sends parallel data through a serial line. UART are frequently used in conjunction with the electronic industries alliance RS-232 standard, ethic specifies the electrical, mechanical, functional and procedural characteristics of two data communication equipment. Because the voltage level defined in RS-232 is different from that of FPGA input/output, a voltage converter chip is needed between a serial port and an FPGAs input/output pins. The S3 board has RS232 port with the standard nine- pin connector. The board contains the necessary voltage converter chip and configures the various RS- 232s control signals to automatically generate acknowledgment for the PCs serial port. A standard straight through serial cable can be used to connect the S3 board and PCs serial port. The S3 board basically handles the RS- 232 standard and we only need to concentrate on the design of the UART circuit.
Page 53
Saurabh Shukla
LED_OUT[7:0] CLK
Rx
Tx
DESCRIPTION
operating clock signal is used for one bit input signal is used for one bit out signal is used for 8 bit data bus for display on FPGA
Page 54
Saurabh Shukla
Page 55
Saurabh Shukla
Page 56
Saurabh Shukla
State S1: here also count is input for state S1. When count > 81 and count < 163 then baud set to be high. When count = 163 then it goes to next state S0.
Initial value of count set to be 0. Each and every posedge clock(clk) the comparator checks or we can say compare the count value and register value. If count value equal to register value then comparator generate high signal which is 1. If count value not equal to register value then comparator generate low signal which is 0. If comparator generate high signal then count become 0. If comparator generate low signal then count get incremented by one in each and every posedge clock(clk).
Page 57
Saurabh Shukla
Page 58
Saurabh Shukla
State S1: here also count is input for state S1. When count > 7 and count <= 15 then baud set to be high. When count > 15 then it goes to next state S0.
Initial value of count set to be 0. Each and every posedge clock(baud_clk) the comparator checks or we can say compare the count value and register value. If count value equal to register value then comparator generate high signal which is 1. If count value not equal to register value then comparator generate low signal which is 0. If comparator generate high signal then count become 0. If comparator genrate low signal then count get incremented by one in each and every posedge clock(baud_clk).
Page 59
Saurabh Shukla
3.1.12.1: Oversampling:
The most commonly used sampling rate is 16 times the baud rate, which means that each serial bit is sampled 16 times. Assume that the communication uses N data bits and M stop bits. a) Wait until the incoming signal becomes low which is 0. The begging of the start bit and then start the sampling tick counter. b) When the counter reaches 7, the incoming signal reaches the middle point of the start bit. Clear the counter to 0 and reset it. c) When the counter reaches 15 the incoming signal reaches the middle point of the 1st bit. Retrieve its value, shift it into a register and restart the counter. d) Repeat step 3 N-1 more times to retrieve the remaining data bits. e) Repeat stop 3 M more time to obtain the stop bits.
Page 60
Saurabh Shukla
Page 61
Saurabh Shukla
State S2: here count2 is input for state S2. When count2 >= 0 and count2 < 15, then count2 get incremented by one with each posedge clk. when count2 = 15, then it goes to next state S3.
State S3: here Num is input for state S3.Num signal used to indicate position of data bit. When num >= 0 and num < 8, then it goes to next state S2. Corsponding to num value the data bit shifted in the 8 bit register. When num = 8, then it goes to next state S4. State S4: here count3 is input for state S4. When count3 >= 0 and count < 15,then num set to be 0 and count3 get incremented by one with each posedge clk. When count3 = 15, then it goes to next state S5. State S5: here byte_done1 is input for state S5. When byte _done = low, then byte_done set to be high and 8 bit data bus Assign to data_out. When byte_done = high, then it goes to next state S0.
Page 62
Saurabh Shukla
Page 63
Saurabh Shukla
Each and every clock (Tx_baud_clk) comparator compare the Flag signal and register. If Flag signal equal to register then comparator output will be high which is 1. If Flag signal not equal to register then comparator output will be Low. If comparator output is high then count will get incremented by one in each and every Tx_baud_clk. If comparator output is low then count will become 0.
Page 64
Saurabh Shukla
Page 65
Saurabh Shukla
Page 66
Saurabh Shukla
Page 67
Saurabh Shukla
Each and every clock (Tx_baud_clk) comparator compare the Flag Count signal and register. If Flag Count signal equal to register then comparator output will be high which is 1. If Flag Count signal not equal to register then comparator output will be Low. If comparator output is high then count will get incremented by one in each and every Tx_baud_clk. If comparator output is low then count will become 0. Another comparator is used to compare the count value and register value. If register value is equal to count then comparator output will be high and count set to be 0. If register value is not equal to count value then comparator output will be low and count will get incremented by one in each and every posedge clock(Tx_baud_clk).
Page 68
Saurabh Shukla
3.2: VGA:
A video controller generates the synchronization signals and outputs data pixel serially. It contains a synchronization circuit, labeled VGA_Sync, a pixel generation circuit. The VGA_Sync circuit generates timing and synchronization signals. The Hsync and Vsync signal are connected to the VGA port to control the horizontal and vertical scans of the monitor. Two signals are decoded from the internal counters, whose outputs are the pixel_x and pixel_y signals.the pixel_x and pixel_y signal indicate the relative positions of the scans and essentially specify the location of the current pixel. The VGA_sync also generates the video_on signal to indicate whether to enable or disable the display. The pixel generation circuit generates the three vido signal, which are collectively referred to as the RGB signal. A color value is obtained according to the current cording to the current coordinates of the pixel (the pixel_x and pixel_y signal) and the external control and data signals.
Page 69
Saurabh Shukla
Page 70
Saurabh Shukla
3.2.2.1:Display: Region where the pixels are actually display on the screen. The length
of this region is 640 pixels.
3.2.2.2: Retrace: Region in which the electron beams return to the left edge. The video
signal should be disabled (i. e. , black), and the length of this region is 96 pixels.
3.2.2.3: Right border: Region that forms the right border of the display region. It is
also known as the front porch (i. e. , porch before retrace). The video signal should be disabled and the length of the region is 16 pixels.
3.2.2.4: Left border: Region that forms the left border of the display region. It is also
know as the back porch (i. e. , porch after retrace). The video signal should be disabled and the length of this region is 48 pixels. The hsync signal can be obtained by a special mod 800 counter and a decoding circuit. Start the counting from the beginning of the display region. This allows us to use the counter. This allows us to use the counter output as the horizontal (X- axis) coordinate. This output constitutes the pixel x signal. The hsync signal goes low when the counters output is between 656 and 751. CRT monitor should be block in the right and left borders and during retrace. We use the h_video_on signal to indicate whether the current horizontal coordinate is in the displayable region. It is asserted only when the pixel count is smaller than 640.
Page 71
Saurabh Shukla
Page 72
Saurabh Shukla
3.2.2.6.1: Display: Region where the horizontal lines are actually displayed on the
screen. The of this region is 480 lines.
3.2.2.6.2: Retrace: Region that the electron beams to the top of the screen. The vido
signal should be disabled and the length of this region is 2 lines.
3.2.2.6.3: Bottom Border: Region that forms the bottom border of the display region. It
is also known as the front porch (i. e. , porch before retrace). The video signal should be disabled and the length of this region is 10 lines.
3.2.2.6.4: Top Border: Region that forms the top border of the display region. It video
signal should be disabled and the length of this region is 33 lines.
Page 73
Saurabh Shukla
The S parameter specifies how fast the screen should be refreshed. For a human eye, the refresh rate must be at least 30 screens per second to make to monitor usually has a much higher rate, such as the 60 screens per second specification above. The pixel rate can be calculated by the three parameters : Pixel Rate = P * L * S = 25 M Pixels/Second.
Page 74
Saurabh Shukla
3.2.5.3: Object Mapped Scheme: The video display can be very simple and
contains only a few objects. Instead of wasting memory to store a mostly blank screen we can generate these objects using simple object generation circuit. Which is called as object mapped scheme. The three schemes can be mixed together to generate a full screen. Bit mapped scheme to generate the background. Object mapped schemed scheme to produce the main objects. We can also use a bit mapped scheme for one portion of a screen and tile mapped text for another part of the screen.
Page 75
Saurabh Shukla
Page 76
Saurabh Shukla
Page 77
Saurabh Shukla
Page 78
Saurabh Shukla
3.4: Bibliography:
1. Hand book of FPGA Prototyping by VHDL Examples, by Pong P. chu. 2. Hand book of VHDL Programming by Example (Fourth edition), by Dougles L. Perry. 3. PPT of VHDL by Avent Spees Way Design Workshop. 4. www.applied VHDL.com
Page 79
Saurabh Shukla
3.5: Appendices
-- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all;
entity topcode is Port ( Rx : in STD_LOGIC; Tx : out STD_LOGIC; clk : in STD_LOGIC; LED_OUT : out STD_LOGIC_VECTOR (7 downto 0)); end topcode; architecture Behavioral of topcode is signal D,din : std_logic_vector(7 downto 0) := (others => '0'); signal xr,xt,z,T : std_logic := '0'; component Rxbaud is Port ( clk : in STD_LOGIC; baud : out STD_LOGIC); end component;
Page 80
Saurabh Shukla
component Rxcode is Port ( Rx : in STD_LOGIC; data_out : out STD_LOGIC_VECTOR (7 downto 0); baud_clk : in STD_LOGIC ; byte_done : out std_logic); end component; component Txbaud is Port ( baud_clk : in STD_LOGIC; baud : out STD_LOGIC); end component; component Txcodefull is Port ( data_in_enable : in STD_LOGIC; data_in : in STD_LOGIC_VECTOR (7 downto 0); Tx : out STD_LOGIC; baud_clk : in STD_LOGIC); end component; component loopcode is Port ( Tx_baud_clk : in STD_LOGIC; Rx_baud_clk : in std_logic; data_in : in STD_LOGIC_VECTOR (7 downto 0); data_out : out STD_LOGIC_vector(7 downto 0); data_in_enable : in STD_LOGIC; data_out_enable : out STD_LOGIC); end component; begin Rx_baud_program : Rxbaud Port map( clk => clk, baud => xr); Rx_program : Rxcode port map(Rx => Rx, data_out => D, baud_clk => xr, byte_done => z); Tx_baud_program : Txbaud port map(baud_clk => xr, baud => xt); Tx_program : Txcodefull port map(data_in_enable => T, data_in => din, Tx => Tx, baud_clk => xt); Loopprogram : loopcode port map(Tx_baud_clk => xt, Rx_baud_clk => xr, data_in => D, data_out => din, data_in_enable => z, data_out_enable => T ); LED_OUT <= din; end Behavioral;
Page 81
Saurabh Shukla
------- Company: -- Engineer: --- Create Date: 03:29:41 11/18/2011 -- Design Name: -- Module Name: RXbaud - Behavioral -- Project Name: -- Target Devices: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: ---------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all;
entity RXbaud is Port ( clk : in STD_LOGIC; baud : out STD_LOGIC); end RXbaud; architecture Behavioral of RXbaud is type shukla1 is(s0,s1,s2); signal Nx_state,Pr_state : shukla1; signal count :integer range 0 to 163 := 0; begin process(Pr_state,count) begin case Pr_state is when s0 => if((count >= 0) and (count <= 81))then Nx_state <= s0; else Nx_state <= s1; end if; when s1 => if((count >81) and (count < 163))then Nx_state <= s1; else Nx_state <= s0; end if; when others => Nx_state <= s0; end case;
Page 82
Saurabh Shukla
end process; process(clk) begin if(clk' event and clk ='1')then Pr_state <= Nx_state; case Nx_state is when s0 => baud <= '1'; when s1 => baud <= '0'; when others => baud <= '1'; end case; end if; end process; process(clk,count) begin if(clk' event and clk = '1')then count <= count + 1; else count <= count; end if; if(count = 163 )then count <= 0; end if; end process; end Behavioral;
Page 83
Saurabh Shukla
-- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all;
entity Rxcode is Port ( Rx : in STD_LOGIC; data_out : out STD_LOGIC_VECTOR (7 downto 0); baud_clk : in STD_LOGIC ; byte_done : out std_logic); end Rxcode; architecture Behavioral of Rxcode is type shukla is(s0,s1,s2,s3,s4,s5); signal Pr_state, Nx_state : shukla; signal count1, count2,count3 : integer range 0 to 15 := 0; signal num : integer range 0 to 8 := 0; signal byte_done1 : std_logic := '0'; signal data : std_logic_vector (7 downto 0) := (others => '0'); begin process(Pr_state,Rx,count1,count2,count3,num,byte_done1) begin case Pr_state is when s0 => if(Rx = '0')then Nx_state <= s1; else
Page 84
Saurabh Shukla
Nx_state <= s0; end if; when s1 => if(count1 = 7 )then Nx_state <= s2; else Nx_state <= s1; end if; when s2 => if(count2 = 15)then Nx_state <= s3; else Nx_state <= s2; end if; when s3 => if(num = 8)then Nx_state <= s4; else Nx_state <= s2; end if; when s4 => if(count3 = 15 ) then Nx_state <= s5; else Nx_state <= s4; end if; when s5 => if(byte_done1 = '1')then Nx_state <= s0; else Nx_state <= s5; end if; when others => Nx_state <= s0; end case; end process; process (baud_clk) begin if(baud_clk' event and baud_clk = '1')then Pr_state <= Nx_state; case Nx_state is when s0 => count1 <= 0; byte_done1 <= '0'; byte_done <= '0';
Page 85
Saurabh Shukla
num <= 0; count3 <= count3 + 1; when s5 => byte_done1 <= '1'; byte_done <= '1'; data_out <= data; when others => byte_done <= '0'; end case; end if; end process; end Behavioral;
-- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all;
entity Txbaud is Port ( baud_clk : in STD_LOGIC; baud : out STD_LOGIC); end Txbaud; architecture Behavioral of Txbaud is type shukla is(s0,s1,s2,s3); signal Nx_state,Pr_state : shukla; signal count : integer range 0 to 16 := 0; begin
Page 86
Saurabh Shukla
process(Pr_state,count) begin case Pr_state is when s0 => if((count >= 0) and (count <= 7))then Nx_state <= s0; else Nx_state <= s1; end if; when s1 => if((count >= 7)and (count <= 15))then Nx_state <= s1; else Nx_state <= s0; end if; when others => Nx_state <= s0; end case; end process; process(baud_clk) begin if(baud_clk' event and baud_clk ='1')then Pr_state <= Nx_state; case Nx_state is when s0 => baud <= '1'; when s1 => baud <= '0'; when others => baud <= '1'; end case; end if; end process; process(baud_clk,count) begin if(baud_clk' event and baud_clk = '1')then count <= count + 1; else count <= count; end if; if(count = 16 )then count <= 0; end if; end process; end Behavioral;
Page 87
Saurabh Shukla
-- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all;
entity Txcodefull is Port ( data_in_enable : in STD_LOGIC; data_in : in STD_LOGIC_VECTOR (7 downto 0); Tx : out STD_LOGIC; baud_clk : in STD_LOGIC); end Txcodefull; architecture Behavioral of Txcodefull is type shukla is(s0,s1,s2,s3,s4,s5,s6); signal Nx_state,Pr_state : shukla; signal count : integer range 0 to 8 := 0; signal flage : std_logic := '0'; signal data : std_logic_vector (7 downto 0) := (others => '0'); begin process(Pr_state,data_in_enable,count,data_in) begin case Pr_state is when s0 => if(data_in_enable = '1')then data <= data_in; Tx <= '0'; Nx_state <= s2; else Tx <= '1';
Page 88
Saurabh Shukla
Nx_state <= s0; end if; when s2 => if(count = 8)then Tx <= '1'; flage <= '0'; Nx_state <= s0; else flage <= '1'; Tx <= data(count); Nx_state <= s2; end if; when others => Nx_state <= s0; Tx <= '1'; flage <= '0'; end case; end process; process(baud_clk) begin if(baud_clk' event and baud_clk = '1')then Pr_state <= Nx_state; end if; end process; process(baud_clk,flage) begin if(baud_clk' event and baud_clk = '1')then if(flage = '1')then count <= count + 1; end if; if(flage = '0')then count <= 0; end if; end if; end process; end Behavioral;
Page 89
Saurabh Shukla
-- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all;
entity loopcode is Port ( Tx_baud_clk : in STD_LOGIC; Rx_baud_clk : in std_logic; data_in : in STD_LOGIC_VECTOR (7 downto 0); data_out : out STD_LOGIC_vector(7 downto 0); data_in_enable : in STD_LOGIC; data_out_enable : out STD_LOGIC); end loopcode; architecture Behavioral of loopcode is type shukla is(s0,s1,s2,s3,s4); signal Rx_Nx_state,Rx_Pr_state : shukla; type shukla1 is(p0,p1,p2,p3,p4); signal Tx_Nx_state,Tx_Pr_state : shukla1; type saurabh is array(0 to 7) of std_logic_vector(7 downto 0); signal memory : saurabh; signal wr_addr,rd_addr : std_logic_vector(2 downto 0) := (others => '0'); signal count : integer range 0 to 8 := 0; signal wr_done,rd_done,flage,flagecount : std_logic := '0'; begin process(Rx_Pr_state,data_in_enable,wr_done) begin case Rx_Pr_state is when s0 =>
Page 90
Saurabh Shukla
if(data_in_enable = '1')then Rx_Nx_state <= s1; else Rx_Nx_state <= s0; end if; when s1 => if(wr_done = '1')then Rx_Nx_state <= s0; else Rx_Nx_state <= s1; end if; when others => Rx_Nx_state <= s0; end case; end process; process(Rx_baud_clk) begin if(Rx_baud_clk' event and Rx_baud_clk = '1')then Rx_Pr_state <= Rx_Nx_state; case Rx_Nx_state is when s0 => wr_done <= '0'; when s1 => memory(conv_integer(wr_addr)) <= data_in; wr_addr <= wr_addr + '1'; wr_done <= '1'; flage <= '1'; when others => wr_done <= '0'; flage <= '0'; end case; end if; end process; process(Tx_Pr_state,flage,rd_done,count) begin case Tx_Pr_state is when p0 => if(flage = '1')then Tx_Nx_state <= p1; else Tx_Nx_state <= p0; end if; when p1 => if(rd_done = '1')then Tx_Nx_state <= p2; else Tx_Nx_state <= p1; end if; when p2 => if(count = 8)then Tx_Nx_state <= p0; else Tx_Nx_state <= p2; end if; when others => Tx_Nx_state <= p0;
Page 91
Saurabh Shukla
end case; end process; process(Tx_baud_clk) begin if(Tx_baud_clk' event and Tx_baud_clk = '1')then Tx_Pr_state <= Tx_Nx_state; case Tx_Nx_state is when p0 => rd_done <= '0'; flagecount <= '0'; when p1 => if(rd_addr(2 downto 0) /= wr_addr(2downto 0))then data_out <= memory(conv_integer(rd_addr)); rd_addr <= rd_addr + '1'; rd_done <= '1'; data_out_enable <= '1'; flagecount <= '1'; end if; when p2 => rd_done <= '0'; data_out_enable <= '0'; when others => rd_done <= '0'; flagecount <= '0'; end case; end if; end process; process(Tx_baud_clk,flagecount,count) begin if(flagecount = '1')then if(Tx_baud_clk' event and Tx_baud_clk = '1')then count <= count + 1; if(count = 8)then count <= 0; end if; end if; end if; end process; end Behavioral;
Page 92
Saurabh Shukla
Page 93
Saurabh Shukla
Page 94
Saurabh Shukla
end else begin Nx_state = S0; end end default: begin Nx_state = S0; end endcase end always@(posedge clk_in or posedge Rst) begin if(Rst) begin count = 0; Pr_state = S0; end else begin Pr_state = Nx_state; case(Nx_state) S0: begin if((count >= 0) && (count < 1)) begin clk_out = 1; count = count + 1; end end S1: begin if((count >= 1) && (count < 2)) begin clk_out = 0; count = count + 1; end if(count > 1) begin count = 0; end end default: begin count = 0; end endcase end end endmodule
Page 95
Saurabh Shukla
`timescale 1ns / 1ps ///////////////////////////////////////////////////////////////////////////// ///// // Company: // Engineer: // // Create Date: 10:31:23 01/10/2012 // Design Name: // Module Name: VGA_V_synch_clk // Project Name: // Target Devices: // Tool versions: // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // ///////////////////////////////////////////////////////////////////////////// ///// module VGA_V_synch_clk(Rst,clk_in,clk_out); parameter S0 = 2'b00; parameter S1 = 2'b01; parameter S2 = 2'b10; parameter S3 = 2'b11; output clk_out; input clk_in; input Rst; reg clk_out; reg [1:0]Nx_state; reg [1:0]Pr_state; integer count; always@(Pr_state or count) begin Nx_state = S0; case(Pr_state) S0: begin if((count >= 0) && (count <= 399)) begin Nx_state = S0; end else begin Nx_state = S1; end end S1: begin if((count >= 400) && (count <= 799))
Page 96
Saurabh Shukla
begin Nx_state = S1; end else begin Nx_state = S0; end end default: begin Nx_state = S0; end endcase end always@(posedge clk_in or posedge Rst) begin if(Rst) begin clk_out = 0; count = 0; Pr_state = S0; end else begin Pr_state = Nx_state; case(Nx_state) S0: begin if((count >= 0) && (count <= 399)) begin clk_out = 1; count = count + 1; end end S1: begin if((count >= 400) && (count <= 799)) begin clk_out = 0; count = count + 1; end if(count > 799) begin count = 0; end end default: begin count = 0; end endcase end end endmodule
Page 97
Saurabh Shukla
Page 98
Saurabh Shukla
else begin Nx_state = S0; end end default: begin Nx_state = S0; end endcase end always@(posedge clk or posedge Rst) begin if(Rst) begin video_on = 0; Pr_state = S0; end else begin Pr_state = Nx_state; case(Nx_state) S0: begin video_on = 1; end S1: begin video_on = 0; end default: begin video_on = 0; end endcase end end endmodule
Page 99
Saurabh Shukla
Page 100
Saurabh Shukla
begin if((count >= 640) && (count <= 655)) begin Nx_state = S1; end else begin Nx_state = S2; end end S2: begin if((count >= 656) && (count <= 751)) begin Nx_state = S2; end else begin Nx_state = S3; end end S3: begin if((count >= 752) && (count <= 799)) begin Nx_state = S3; end else begin Nx_state = S0; end end default: begin Nx_state = S0; end endcase end always@(posedge clk or posedge Rst) begin if(Rst) begin count = 0; Pr_state = S0; end else begin Pr_state = Nx_state; case(Nx_state) S0: begin if((count >= 0) && (count <= 639)) begin H_video_on = 1; H_synch = 1; Pixel_x = count;
Page 101
Saurabh Shukla
count = count + 1; end end S1: begin if((count >= 640) && (count <= 655)) begin H_video_on = 0; H_synch = 1; Pixel_x = count; count = count + 1; end end S2: begin if((count >= 656) && (count <= 751)) begin H_video_on = 0; H_synch = 0; Pixel_x = count; count = count + 1; end end S3: begin if((count >= 752) && (count <= 799)) begin H_video_on = 0; H_synch = 1; Pixel_x = count; count = count + 1; end if(count > 799) begin count = 0; end end default: begin count = 0; end endcase end end endmodule
Page 102
Saurabh Shukla
Page 103
Saurabh Shukla
begin if((count >= 480) && (count <= 489)) begin Nx_state = S1; end else begin Nx_state = S2; end end S2: begin if((count >= 490) && (count <= 491)) begin Nx_state = S2; end else begin Nx_state = S3; end end S3: begin if((count >= 492) && (count <= 524)) begin Nx_state = S3; end else begin Nx_state = S0; end end default: begin Nx_state = S0; end endcase end always@(posedge clk or posedge Rst) begin if(Rst) begin count = 0; Pr_state = S0; end else begin Pr_state = Nx_state; case(Nx_state) S0: begin if((count >= 0) && (count <= 479)) begin V_video_on = 1; V_synch = 1; Pixel_y = count;
Page 104
Saurabh Shukla
count = count + 1; end end S1: begin if((count >= 480) && (count <= 489)) begin V_video_on = 0; V_synch = 1; Pixel_y = count; count = count + 1; end end S2: begin if((count >= 490) && (count <= 491)) begin V_video_on = 0; V_synch = 0; Pixel_y = count; count = count + 1; end end S3: begin if((count >= 492) && (count <= 524)) begin V_video_on = 0; V_synch = 1; Pixel_y = count; count = count + 1; end if(count > 524) begin count = 0; end end default: begin count = 0; end endcase end end endmodule
Page 105
Saurabh Shukla
Page 106
Saurabh Shukla
Nx_state = S1; end else begin Nx_state = S2; end end S2: begin if(obj3) begin Nx_state = S2; end else begin Nx_state = S0; end end default: begin Nx_state = S0; end endcase end always@(posedge clk or posedge Rst) begin if(Rst) begin Pr_state = S0; end else begin Pr_state = Nx_state; case(Nx_state) S0: begin if(obj1) begin RGB = 3'b001; end else begin RGB = 3'b000; end end S1: begin if(obj2) begin RGB = 3'b010; end else begin RGB = 3'b000; end end S2:
Page 107
Saurabh Shukla
begin if(obj3) begin RGB = 3'b100; end else begin RGB = 3'b000; end end default: begin RGB = 3'b000; end endcase end end endmodule
Page 108
Saurabh Shukla
input [9:0]Pixel_x; input [9:0]Pixel_y; reg object1; reg object2; reg object3; reg [1:0]Nx_state; reg [1:0]Pr_state; always@(Pr_state or Pixel_x or Pixel_y or video_on) begin Nx_state = S0; object1 = 1; object2 = 0; object3 = 0; case(Pr_state) S0: begin if((Pixel_x >= 32) && (Pixel_x <= 35) && (video_on)) begin object1 = 1; object2 = 0; object3 = 0; Nx_state = S0; end else begin object1 = 0; object2 = 0; object3 = 0; Nx_state = S1; end end S1: begin if((Pixel_x >= 200) && (Pixel_x <= 205) && (Pixel_y >= 104) && (Pixel_y <= 175) && (video_on)) begin object1 = 0; object2 = 1; object3 = 0; Nx_state = S1; end else begin object1 = 0; object2 = 0; object3 = 0; Nx_state = S2; end end S2: begin if((Pixel_x >= 300) && (Pixel_x <= 350) && (Pixel_y >= 190) && (Pixel_y <= 210) && (video_on)) begin object1 = 0; object2 = 0; object3 = 1;
Page 109
Saurabh Shukla
Nx_state = S2; end else begin object1 = 0; object2 = 0; object3 = 0; Nx_state = S0; end end default: begin object1 = 0; object2 = 0; object3 = 0; Nx_state = S0; end endcase end always@(posedge clk or posedge Rst) begin if(Rst) begin Pr_state = S0; end else begin Pr_state = Nx_state; end end endmodule
Page 110
Saurabh Shukla
Page 111
Saurabh Shukla
end S1: begin if(obj2) begin RGB = 3'b010; Nx_state = S1; end else begin RGB = 3'b000; Nx_state = S2; end end S2: begin if(obj3) begin RGB = 3'b011; Nx_state = S2; end else begin RGB = 3'b000; Nx_state = S3; end end S3: begin if(obj4) begin RGB = 3'b100; Nx_state = S3; end else begin RGB = 3'b000; Nx_state = S4; end end S4: begin if(obj5) begin RGB = 3'b101; Nx_state = S4; end else begin RGB = 3'b000; Nx_state = S5; end end S5: begin if(obj6) begin
Page 112
Saurabh Shukla
RGB = 3'b110; Nx_state = S5; end else begin RGB = 3'b000; Nx_state = S6; end end S6: begin if(obj7) begin RGB = 3'b111; Nx_state = S6; end else begin RGB = 3'b000; Nx_state = S7; end end S7: begin if(obj8) begin RGB = 3'b101; Nx_state = S7; end else begin RGB = 3'b000; Nx_state = S0; end end default: begin RGB = 3'b000; Nx_state = S0; end endcase end always@(posedge clk or posedge Rst) begin if(Rst) begin Pr_state = S0; end else begin Pr_state = Nx_state; end end endmodule
Page 113
Saurabh Shukla
Page 114
Saurabh Shukla
obj8 = 0; Nx_state = S0; end else begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S1; end end S1: begin if((Pixel_x >= 80) && (Pixel_x <= 159) && (video_on)) begin obj1 = 0; obj2 = 1; obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S1; end else begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S2; end end S2: begin if((Pixel_x >= 160) && (Pixel_x <= 239) && (video_on)) begin obj1 = 0; obj2 = 0; obj3 = 1; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S2; end else
Page 115
Saurabh Shukla
begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S3; end end S3: begin if((Pixel_x >= 240) && (Pixel_x <= 319) && (video_on)) begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 1; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S3; end else begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S4; end end S4: begin if((Pixel_x >= 320) && (Pixel_x <= 399) && (video_on)) begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 1; obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S4; end else begin obj1 = 0; obj2 = 0;
Page 116
Saurabh Shukla
obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S5; end end S5: begin if((Pixel_x >= 400) && (Pixel_x <= 479) && (video_on)) begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 1; obj7 = 0; obj8 = 0; Nx_state = S5; end else begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S6; end end S6: begin if((Pixel_x >= 480) && (Pixel_x <= 559) && (video_on)) begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 1; obj8 = 0; Nx_state = S6; end else begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 0;
Page 117
Saurabh Shukla
obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S7; end end S7: begin if((Pixel_x >= 560) && (Pixel_x <= 639) && (video_on)) begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 1; Nx_state = S7; end else begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 0; Nx_state = S0; end end default: begin obj1 = 0; obj2 = 0; obj3 = 0; obj4 = 0; obj5 = 0; obj6 = 0; obj7 = 0; obj8 = 0; end endcase end always@(posedge clk or posedge Rst) begin if(Rst) begin Pr_state = S0; end else begin Pr_state = Nx_state; end end
Page 118
Saurabh Shukla
Page 119
Saurabh Shukla
Page 120
Saurabh Shukla
Page 121
Saurabh Shukla
Page 122
Saurabh Shukla
Page 123
Saurabh Shukla
Page 124
Saurabh Shukla
Page 125
Saurabh Shukla
Page 126
Saurabh Shukla
Page 127
Saurabh Shukla
Page 128
Saurabh Shukla
Page 129
Saurabh Shukla
Page 130
Saurabh Shukla
3.7: ACRONYMS:
1: CLK = 2: baud = 3: Tx = CLOCK mode count
Transmitter
4: Rx = Receiver 5: LED_OUT = FPGA LED 6: baud_clk = mode count CLOCK 7: Tx_baud_clk = Transmitter mode count CLOCK(Transmitter baud CLOCK) 8: Rx_baud_clk = Receiver mode count CLOCK(Receiver baud CLOCK) 9: rd_addrs = read address used in FIFO memory 10: wr_addrs = write address used in FIFO memory
Page 131