Академический Документы
Профессиональный Документы
Культура Документы
(Accredited by NBA)
an
Lab, email=janakiraman.n@klnce.
edu, c=IN
Date: 2010.01.13 12:03:52 +05'30'
COMPILED BY
Introduction
Xilinx Tools is a suite of software tools used for the design of digital circuits
implemented using Xilinx Field Programmable Gate Array (FPGA) or Complex
Programmable Logic Device (CPLD). The design procedure consists of (a) design entry, (b)
compilation and implementation of the design, (c) functional simulation and (d) testing and
verification. Digital designs can be entered in various ways using the above CAD tools: using
a schematic entry tool, using a hardware description language (HDL) – Verilog or VHDL or a
combination of both.
The CAD tools enable you to design combinational and sequential circuits starting
with Verilog HDL design specifications. The steps of this design procedure are listed below:
A Verilog input file in the Xilinx software environment consists of the following segments:
• Header: module name, list of input and output ports.
• Declarations: input and output ports, registers and wires.
• Logic Descriptions: equations, state machines and logic functions.
• End: endmodule
All your designs for this lab must be specified in the above Verilog input format. Note that
the state diagram segment does not exist for combinational logic designs.
1
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
VLSI Design Flow for FPGA:
• DESIGN ENTRY
• SIMULATION
• SYNTHESIS
• IMPLEMENTATION
• DEVICE PROGRAMMING
2
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
2. Opening a project
Select File->New Project to create a new project. This will bring up a new project window
on the desktop. Fill up the necessary entries as follows:
3
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Example: If the project name were “or_gate”, enter “or_gate” as the project name and then
click “Next”.
• For each of the properties given below, click on the ‘value’ area and select from the list
of values that appear.
o Device Family: Family of the FPGA/CPLD used. In this laboratory we will
be using the Spartan3 FPGA’s.
o Device: The number of the actual device. For this lab you may enter
XC3S400 (this can be found on the attached prototyping board)
o Package: The type of package with the number of pins. The Spartan FPGA
used in this lab is packaged in PQ208 package.
o Speed Grade: The Speed grade is “-4”.
o Synthesis Tool: XST [VHDL/Verilog]
o Simulator: The tool used to simulate and verify the functionality of the
design. ISE simulator is integrated in the Xilinx ISE. Hence choose “ISE
Simulator” as the simulator.
o Then click on NEXT to save the entries.
4
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
All project files such as schematics, netlists, Verilog files, VHDL files, etc., will be
stored in a subdirectory with the project name. A project can only have one top level HDL
source file (or schematic). Modules can be added to the project to create a modular,
hierarchical design. In order to open an existing project in Xilinx Tools, select File->Open
Project to show the list of projects on the machine.
Choose the project you want and click OK.
First we will enter a design using a structural or RTL description using the Verilog
HDL. You can create a Verilog HDL input file (.v file) using the HDL Editor available in the
Xilinx ISE Tools (or any text editor).
If adding an already existing source file (.v file) to the project, in the project Navigator
window, select Project -> Add Copy Source and browse through the disk for the source file.
If creating a new source file, in the Project Navigator window, select Project -> New
Source. A window pops up. (Note: “Add to project” option is selected by default. If you do
not select it then you will have to add the new source file to the project manually.)
5
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Select Verilog Module and in the “File Name:” area, enter the name of the Verilog
source file you are going to create. Also make sure that the option Add to project is selected
so that the source need not be added to the project again. Then click on Next to accept the
entries. This pops up the following window:
6
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
In the Port Name column, enter the names of all input and output pins and specify the
Direction accordingly. A Vector/Bus can be defined by entering appropriate bit numbers in
the MSB/LSB columns.
Then click on Next to get a window showing all the new source information. If any
changes are to be made, just click on Back to go back and make changes. If everything is
acceptable, click on Finish to continue.
Once you click on Finish, the source file will be displayed in the sources window in
the Project Navigator.
If a source has to be removed, just right click on the source file in the Sources in Project
window in the Project Navigator and select Remove in that. Then select Project -> Delete
Implementation Data from the Project Navigator menu bar to remove any related files.
The source file will now be displayed in the Project Navigator window. The source
file window can be used as a text editor to make any necessary changes to the source file. All
the input/output pins will be displayed. Save your Verilog program periodically by selecting
the File->Save from the menu. You can also edit Verilog programs in any text editor and add
them to the project directory using “Add Copy Source”.
7
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
The Verilog source code template generated shows the module name, the list of ports
and also the declarations (input/output) for each port. Combinational logic code can
be added to the verilog code after the declarations and before the endmodule line.
For example, an output z in an OR gate with inputs a and b can be described as,
assign z = a | b;
A given logic function can be modeled in many ways in verilog. Here is another
example in which the logic function is implemented as a truth table using a case
statement:
module or_gate(a,b,z);
input a;
input b;
output z;
reg z;
always @(a or b)
begin
case ({a,b})
8
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
00: z = 1'b0;
01: z = 1'b1;
10: z = 1'b1;
11: z = 1'b1;
endcase
end
endmodule
Suppose we want to describe an AND gate. It can be done using the logic equation as
shown in Figure or using the case statement (describing the truth table) as shown in second
Figure. These are just two example constructs to design a logic function. Verilog offers
numerous such constructs to efficiently model designs.
9
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Click on the symbol of FPGA device and then right click > click on new source
10
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Select the Test Bench Waveform and give the file name select entity click next and finish
Select the desired parameters for simulating your design. In this case combinational circuit
and simulation time click finish
11
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Assign all input signal using just click on this and save file.
From the source process window. Click Behavioral simulation from drop-down menu
Select the test bench file (.tbw)and click process button double click the Simulation
Behavioral Model
12
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Verify your design in wave window by seeing behavior of output signal with respect to input
signal.
1) FUNCTIONAL SIMULATION
2) GATE-LEVEL SIMULATION
3) POST-PAR SIMULATION
13
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
RTL Schematic:
After the HDL synthesis phase of the synthesis process, you can display a schematic
representation of your synthesized source file. This schematic shows a representation
of the pre-optimized design in terms of generic symbols, such as adders, multipliers,
counters, AND gates, and OR gates double click View RTL Schematic.
14
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Technology Schematic:
4) Display of Truth Table and K-Map for your design just click the respective tabs.
Design summary:
After finishing the synthesis, you can view number of Slices, LUT (Look Up
Table), I/Os are taken by your deign in Device using Design summary.
15
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
After Synthesis, assign the Pin Value; double click the Assign Package Pins.
16
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Enter the Pin value for your input and output signals. if you want see your Pin assignment in
FPGA zoom in Architecture View or Package View
17
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Design Implementation begins with the mapping or fitting of a logical design file to a specific
device and is complete when the physical design is successfully routed and a bitstream is
generated. Double Click Implementation Design
18
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
After implementation you see Design Summary, you get the all details about your design. If
you want edit the place and route, double click View/Edit placed design
You see where your IOs are placed in FPGA. And zoom to view how Pins are placed in
FPGA.
19
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Just double click View/Edit Routed Design to view interconnection wires and blocks
20
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Click the pin to see where its placed in FPGA. And Zoom particular area to see Place and
Routing.
If you want to change the place of the design, click and trace to another slice
21
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
22
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Place & Route, the process of optimization of logic cells for effective utilization of
FPGA area and the speed of operation, is used to modify and infer the following:
1) RE-ASSIGNMENT OF PINS
2) RE-LOCATION OF SLICES
23
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
24
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Procedure:
¾ Started by clicking on the Project Navigator Icon on the Windows desktop.
¾ Select File->New Project to create a new project.
¾ Fill the necessary information’s based on previous chapters.
¾ Then click on NEXT.
¾ Click on the NEW SOURCE.
Select the Categories and symbols or type the symbol name in this case just type xor2, and2, or2.
25
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
26
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
27
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
To view the VHF file generated Clock on View HDL functional model in design utilities
28
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
To compile the design, expand the Implement design option by clicking on the ‘add’
sign (+) in front of the implement design tab. Now click on the option Compile Design in the
Processes window. It will go through steps like Check Syntax, Compile Logic, Interpret
Feedbacks, Reformat Logic and Optimize Hierarchy. If any of these steps could not be
done or done with errors, it will place a X mark in front of that, otherwise a tick mark will be
placed after each of them to indicate the successful completion. If everything is done
successfully, a tick mark will be placed before the Compile Design option. If there are
warnings, one can see mark in front of the option indicating that there are some warnings.
One can look at the warnings or errors in the Console window present at the bottom of the
Navigator window. Every time the design file is saved; all these marks disappear asking for
a fresh compilation.
To implement the design, double-click on the Implement Design option. It has many
steps in it e.g., Translation, Fitter, Timing Analysis and Launch Tools. One can use the
timing analyzer and post fit chipviewer from the Launch Tools section once the
implementation is completed successfully. If the implementation is done successfully, a tick
mark will be placed in front of the Implement Design option.
The above two steps can be done in a single step by just double-clicking on the Implement
Design option straightaway. This will do the compilation first and then the implementation.
29
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
A bitstream file needs to be prepared for each design and downloaded onto the
Pegasus prototyping board. This is done as follows:
1. Connect the 5V DC power cable to the power input on the demo board (J4).
2. Connect the download cable between the PC and demo board (J7).
3. Select Synthesis/Implementation from the drop-down list in the Sources window.
4. Select design file in the Sources window.
5. In the Processes window, click the “+” sign to expand the Generate Programming
File processes.
6. Double-click the Configure Device (iMPACT) process.
7. The Xilinx WebTalk Dialog box may open during this process. Click Decline.
8. Select Disable the collection of device usage statistics for this project only and
click OK. iMPACT opens and the Configure Devices dialog box is displayed.
9. In the Welcome dialog box, select Configure devices using Boundary-Scan (JTAG).
10. Verify that Automatically connect to a cable and identify Boundary-Scan chain is
selected.
11. Click Finish.
12. If you get a message saying that there are two devices found, click OK to continue.
The devices connected to the JTAG chain on the board will be detected and displayed
in the iMPACT window.
13. The Assign New Configuration File dialog box appears. To assign a configuration file
to the xc3s400 device in the JTAG chain, select the counter.bit file and click Open.
14. If you get a Warning message, click OK.
15. Select Bypass to skip any remaining devices.
16. Right-click on the xc3s400 device image, and select Program. The Programming
Properties dialog box opens.
17. Click OK to program the device.
30
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Note that you can assign pin numbers only to top-level Verilog / VHDL file.
¾ For the OR_GATE example, the user constraint file used is as follows:
# Pin 88 and 89 are FPGA pins connected to SW0 and SW1 in the Pegasus Board
# Pin 46 of the FPGA is connected to LED0 in the Pegasus Board.
NET a LOC="P88";
NET b LOC="P89";
NET z LOC="P46";
¾ Click on the Module View, choose the main design file and in the Process View -> User
Constraints –> Edit Constraints option; add the user constraint file for the design.
¾ Then, in the Process View window (left-bottom), double click on the ‘Generate
Programming file’.
¾ Wait for the programming file to be generated and then click on the “Generate
Programming File” Æ “Configure Device” option.
Once this is done, the following image pops up (JTAG Programmer Window). Choose
the ‘Select boundary scan’ option and click on NEXT.
31
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
On clicking Next, the following image comes up: Choose the option ‘Automatically
connect to cable and identify device’ and click on Finish.
Once this is done, a window pops up where you will see two devices connected in the
Boundary scan. The first one xc3s400 is the Spartan FPGA. Right click on the xc3s400
device and select “Assign New configuration file”. Once this is done, click on Ok on the
following pop up which will take you to the Select bit file window as shown – Choose
or_gate.bit
Now Right click on the xs3s400 device and select program as shown below:
32
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Once you select program, the following window will pop up. Click on OK [There is
no need to check the Verify option].
Once you click OK, you can see the status of the bitstream download in the lower half
of the window.
33
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Ensure that the “Programmed Successfully” message appears in the message window.
If this doesn’t appear, it could be due to the following reasons:
1. The JTAG cable is not connected between the FPGA board and the PC
parallel port.
2. You did not select the proper device for download in the JTAG chain.
3. The bitstream generated was not for the device: XC2S50-PQ208
In order to use the respective input/output device on the board, the pin number of the
device must be connected properly to the designs input/output. If the Programmed
Successfully message appears in the message window, you can start testing your design in the
FPGA board using the input and output devices on the board.
34
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
35
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Features which can be used to test the digital logic in the design:
• SPARTAN -3 FPGA : 400 k logic cell SPARTAN -3 FPGA in PQ208 Plastic Quad Flat
Package (MXS3FK-PQ208-IM )
Ð Three families Spartan 3 /Spartan 3L/Spartan 3 XA.
Ð Very low cost, high-performance logic solution for high-volume, consumer-oriented
applications.
- Densities as high as 74,880 logic cells.
- Three power rails for core (1.2V), I/O’s (1.2V to 3.3V) and Auxiliary purposes
(2.5V).
- 326 MHz system clock rate.
- 90 nm process technology.
Ð Select IO Signaling.
- Up to 784 I/O pins.
- 622 Mb/s data transfer rate per IO.
- 18 single-ended signal standards.
Ð Logic Resources
- Abundant Logic cells with shift register capability.
- Wide Multiplexers.
- Fast look-ahead carry logic.
- Dedicated 18 x 18 Multipliers.
Ð Select RAM Hierarchical Memory.
- Up to 1,872 Kbits of total block RAM.
- Up to 520 Kbits of Distributed RAM.
Ð Digital Clock Manager (up to 4DCMs)
- Clock skew elimination.
- Frequency synthesis
- High resolution phase shifting.
Ð Eight global clock lines and abundant routing.
• Seven Segment Display: Six-character multiplexed seven-segment LED display.
• Serial Interface: One RS-232 channel using MAX3223, 9 pin two channel serial
interfaces.
Ð DB9 9-pin female connector (DCE connector).
Ð RS-232 transceiver/level translator using MAX3223 in SSOP package.
Ð Uses straight-through serial cable to connect to computer or workstation serial port.
36
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
In order to use the respective input/output device on the board, the pin number of the
device must be connected properly to the design’s input/output. In the Pegasus board, the pin
number of these inputs/outputs are mentioned in the board manual and also mentioned in the
components of the board.
Observing outputs using the on-board LEDs and Seven Segment Displays
The Pegasus boards have six on-board 7-segment displays, which is connected to the
corresponding on-board Spartan FPGA chip. This display can be used to observe the outputs
of your design without using any additional wires if the design conforms to the pin
37
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
assignments for the on-board 7-segment display. The figure below shows the 7-segment
display with the conventional labeling of individual segments.
The Pegasus board contains a 6-digit common anode seven-segment LED display.
The display is multiplexed, so only seven cathode signals (CA, CB, CC, CD, CE, CF, CG)
exist to drive all 28 segments in the display. Six digit-enable signals (AN1, AN2, AN3, AN4,
AN5, AN6) drive the common anodes, and these signals determine which digit the cathode
signals illuminate.
LCD Interface
SPARTAN-3 -IM includes a LCD Module, which is a dot matrix liquid crystal
display that displays alphanumeric, Kana (Japanese) characters and symbols. Built in
controller provides connectivity between LCD and FPGA.
This LCD has a built in Dot Matrix controller, with font 5 X 7 or 5 X 10 dots, display
data RAM for 80 characters ( 80 x 8 bit) and a character generator ROM which provides 160
characters with 5x7 font and 32 characters with font of 5x10.
All the functions required for LCD are provided internally. Internal refresh is
provided by the Controller.
38
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Data Lines Connection
LCD has 8 bit bidirectional data bus interface to FPGA. When Enable signal is at low
level, this data bus remains in high impedance state. Interface details of the data lines with
SPARTAN-3 FPGA are as in Table.
Control Line Interface:
The control lines of LCD comprises of RS, R/W# and E The significance of the
above mentioned control signals is as follows
ASCII CODE
The ASCII code for 5x 7 LCD Display is given in Figure
39
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Design Description:
• Initially all Red Lights will be “ON” (South, west, North, East, Pedestrian)
• Green Lights of will be “ON”, Right, Left & Straight paths are free for Traffic.
• Yellow Phase is split as yellow1 & yellow2. In yellow1 phase yellow lights will be on
and respective left & pedestrian paths are free for traffic.
• In Yellow2 Phase only yellow lights will be “ON”
• Same flow is repeated for all four paths. (South, west, north, east).
¾ Flowchart:-
40
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Abbreviation used:-
South West
PSG – Pedestrian South Green PWR – Pedestrian West Red
PSR – Pedestrian South Red PWG – Pedestrian West Green
RS – Right South RW – Right West
LS – Left South LW – Left West
SS – Straight South SW – South West
YS – Yellow South YW – Yellow West
REDS – Red South REDW – Red West
North East
PNR- Pedestrian North red PEG – Pedestrian East green
PNG – Pedestrian North green PER – Pedestrian Ease Red
RN – Right North RE – Right East
LN – Left North LE – Left East
SN – Straight North SE – Straight East
YN - Yellow North YE – Yellow East
REDN – Red North REDE – Red East
41
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Experimental Set up:
Component Diagram
42
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
KEYS
net "RL<0>" Loc= "p96";
net "RL<1>" Loc= "p95";
net "RL<2>" Loc= "p94";
net "RL<3>" Loc= "p85";
net "SL<0>" Loc= "p86";
net "SL<1>" Loc= "p87";
net "SL<2>" Loc= "p90";
net "SL<3>" Loc= "p93";
LCD Interface
net "LCD_D<0>" Loc= "p167";
net "LCD_D<1>" Loc= "p166";
net "LCD_D<2>" Loc= "p165";
net "LCD_D<3>" Loc= "p162";
net "LCD_D<4>" Loc= "p161";
net "LCD_D<5>" Loc= "p156";
net "LCD_D<6>" Loc= "p155";
net "LCD_D<7>" Loc= "p154";
net "LCD_E" Loc= "p168";
net "LCD_RS" Loc= "p171";
net "LCD_RW_BAR" Loc= "p169";
Display
net "DIS<0>" Loc= "p97";
net "DIS<1>" Loc= "p100";
net "DIS<2>" Loc= "p101";
43
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Input Switches
net "IL<0>" Loc= "p57";
net "IL<1>" Loc= "p52";
net "IL<2>" Loc= "p51";
net "IL<3>" Loc= "p50";
net "IL<4>" Loc= "p48";
net "IL<5>" Loc= "p46";
net "IL<6>" Loc= "p45";
net "IL<7>" Loc= "p44";
net "IL<8>" Loc= "p43";
net "IL<9>" Loc= "p42";
net "IL<10>" Loc= "p40";
net "IL<11>" Loc= "p39";
net "IL<12>" Loc= "p37";
net "IL<13>" Loc= "p36";
net "IL<14>" Loc= "p35";
net "IL<15>" Loc= "p34";
Test LEDs
net "OL<0> Loc= "p68";
net "OL<1> Loc= "p67";
net "OL<2> Loc= "p65";
net "OL<3> Loc= "p64";
net "OL<4> Loc= "p63";
net "OL<5> Loc= "p62";
net "OL<6> Loc= "p61";
net "OL<7> Loc= "p58";
net "OL<8> Loc= "p80";
net "OL<9> Loc= "p79";
net "OL<10>" Loc= "p78";
net "OL<11>" Loc= "p77";
net "OL<12>" Loc= "p76";
net "OL<13>" Loc= "p74";
net "OL<14>" Loc= "p72";
net "OL<15>" Loc= "p71";
44
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
RTC
net "RTC_DIS<0>" LOC = "p16"; #J6-1
net "RTC_DIS<1>" LOC = "p15"; #J6-2
net "RTC_DIS<2>" LOC = "p19"; #J6-3
net "RTC_DIS<3>" LOC = "p18"; #J6-4
net "RTC_DIS<4>" LOC = "p21"; #J6-5
net "RTC_DIS<5>" LOC = "p22"; #J6-6
net "RTC_SEGA" LOC = "p24"; #J6-7
net "RTC_SEGB" LOC = "p20"; #J6-8
net "RTC_SEGC" LOC = "p27"; #J6-5
net "RTC_SEGD" LOC = "p26"; #J6-6
net "RTC_SEGE" LOC = "p29"; #J6-3
net "RTC_SEGF" LOC = "p28"; #J6-4
net "RTC_SEGG" LOC = "p33"; #J6-1
net "RTC_SEGDP" LOC = "p31"; #J6-2
Traffic Control
net "TRC_LE" LOC = "p107"; #J3-20
net "TRC_LN" LOC = "p125"; #J3-9
net "TRC_LS" LOC = "p150"; #J3-25
net "TRC_LW" LOC = "p130"; #J3-6
net "TRC_SE" LOC = "p115"; #J3-17
net "TRC_SN" LOC = "p123"; #J3-11
net "TRC_SS" LOC = "p152"; #J3-26
net "TRC_SW" LOC = "p146"; #J3-4
net "TRC_RE" LOC = "p114"; #J3-18
net "TRC_RN" LOC = "p122"; #J3-12
net "TRC_RS" LOC = "p111"; #J3-23
net "TRC_RW" LOC = "p147"; #J3-3
net "TRC_PEG" LOC = "p116"; #J3-16
net "TRC_PNG" LOC = "p128"; #J3-7
net "TRC_PSG" LOC = "p12"; #J3-28
net "TRC_PWG" LOC = "p148"; #J3-2
net "TRC_PER" LOC = "p117"; #J3-15
net "TRC_PNR" LOC = "p124"; #J3-10
net "TRC_PSR" LOC = "p13"; #J3-27
net "TRC_PWR" LOC = "p149"; #J3-1
net "TRC_REDE" LOC = "p109"; #J3-22
net "TRC_REDN" LOC = "p120"; #J3-13
net "TRC_REDS" LOC = "p108"; #J3-21
net "TRC_REDW" LOC = "p126"; #J3-8
net "TRC_YE" LOC = "p106"; #J3-19
45
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
IOs
net "IO<1>" LOC = "p184"; #J7-1
net "IO<2>" LOC = "p183"; #J7-2
net "IO<3>" LOC = "p187"; #J7-3
net "IO<4>" LOC = "p185"; #J7-4
net "IO<5>" LOC = "p190"; #J7-5
net "IO<6>" LOC = "p189"; #J7-6
net "IO<7>" LOC = "p194"; #J7-7
net "IO<8>" LOC = "p191"; #J7-8
net "IO<9>" LOC = "p197"; #J7-9
net "IO<10>" LOC = "p196"; #J7-10
net "IO<11>" LOC = "p199"; #J7-11
net "IO<12>" LOC = "p198"; #J7-12
net "IO<13>" LOC = "p203"; #J7-13
net "IO<14>" LOC = "p200"; #J7-14
net "IO<15>" LOC = "p205"; #J7-15
net "IO<16>" LOC = "p204"; #J7-16
net "IO<17>" LOC = "p3"; #J7-17
net "IO<18>" LOC = "p2"; #J7-18
net "IO<19>" LOC = "p5"; #J7-19
net "IO<20>" LOC = "p4"; #J7-20
net "IO<21>" LOC = "p9"; #J7-21
net "IO<22>" LOC = "p7"; #J7-22
net "IO<23>" LOC = "p11"; #J7-23
net "IO<24>" LOC = "p10"; #J7-24
46
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Aim:
Write the short objective of your program in your own wordings.
Required Packages:
1) Software details
2) Hardware details
Procedure:
Write all the theoretical procedure given in the corresponding operations like
Simulation, Synthesis, Place & Route, Back-annotation, Schematic & Implementation in
FPGA.
Circuit Diagram:
Draw the logic gates design diagram of your circuit.
Truth Table:
Draw the truth table of your circuit.
Program:
Write the HDL program (VHDL / Verilog HDL) for your design.
Model Result:
Write the expected result for your program.
Experimental Result:
Write the actual result of your design works.
Conclusion:
Write the conclusion of your experiment, based on the model & experimental result.
47
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
This is just an introductory level tutorial to the Verilog language. The reader is
encouraged to go through the various Verilog tutorials to understand the language better:
1. Module:
The <module_name> is the type of this module. The <portlist> is the list of
connections, or ports, which allows data to flow into and out of modules of this type.
Verilog models are made up of modules. Modules, in turn, are made of different types of
components. These include
• Parameters
• Nets
• Registers
• Primitives and Instances
• Continuous Assignments
• Procedural Blocks
• Task/Function definitions
2. Ports:
Ports are Verilog structures that pass data between two or more modules. Thus, ports can
be thought of as wires connecting modules. The connections provided by ports can be
either input, output, or bi-directional (inout).
Module instantiations also contain port lists. This is the means of connecting signals in
the parent module with signals in the child module.
48
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
3. Nets:
Nets are the things that connect model components together. They are usually thought of as
wires in a circuit. Nets are declared in statements like this:
Example:
4. Registers:
Registers are storage elements. Values are stored in registers in procedural assignment
statements. Registers can be used as the source for a primitive or module instance (i.e.
registers can be connected to input ports), but they cannot be driven in the same way a net
can.
Example:
5. Operators in Verilog:
Logical, arithmetic and relational operators available in Verilog are described in Table
49
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
6. Continuous assignments:
Continuous assignments are sometimes known as data flow statements because they
describe how data moves from one place, either a net or register, to another. They are usually
thought of as representing combinational logic. In general, any logic functionality which can
be implemented by means of a continuous assignment can also be implemented using
primitive instances.
A continuous assignment looks like this:
Examples:
7. Procedural Blocks:
Procedural blocks are the part of the language which represents sequential behavior.
A module can have as many procedural blocks as necessary. These blocks are sequences of
executable statements. The statements in each block are executed sequentially, but the blocks
themselves are concurrent and asynchronous to other blocks.
There are two types of procedural blocks, initial blocks and always blocks.
There may be many initial and always blocks in a module. Since there may be many modules
in a model, there may be many initial and always blocks in the entire model. All initial and
always blocks contain a single statement, which may be a compound statement, e.g.
initial
begin statement1 ; statement2 ; ... end
50
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
a. Initial Block:
All initial blocks begin at time 0 and execute the initial statement. Because the
statement may be a compound statement, this may entail executing lots of statements.
There may be time or event controls, as well as all of the control constructs in the
language. As a result, an initial block may cause activity to occur throughout the
entire simulation of the model.
When the initial statement finishes execution, the initial block terminates. If
the initial statement is a compound statement, then the statement finishes after its last
statement finishes.
Example:
initial begin
x = 1; // an initialization
y = f(x);
#1 x = 0; // a value change 1 time unit later
y = f(x);
end
b. Always Block:
Always blocks also begin at time 0. The only difference between an always
block and an initial block is that when the always statement finishes execution, it
starts executing again. Note that if there is no time or event control in the always
block, simulation time can never advance beyond time 0. Example,
always
#10 clock = ~clock;
Syntax:
if (condition)
statements;
if (condition)
statements;
else
statements;
if (condition)
statements;
else if (condition)
statements;
................
else
statements;
Example:
// Simple if statement
51
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
if (enable)
q <= d;
// One else statement
if (reset == 1'b1)
q <= 0;;
else
q <= d;
// Nested if-else-if statements
if (reset == 1'b0)
counter <= 4'b0000;
else if (enable == 1'b1 && up_en == 1'b1)
counter <= counter + 1'b1;
else if (enable == 1'b1 && down_en == 1'b1);
counter <= counter - 1'b0;
else
counter <= counter; // Redundant code
b. Case statement:
Syntax:
case (<expression>)
<case1> : <statement>
<case2> : <statement>
.....
default : <statement>
endcase
Example:
endmodule
Verilog allows you to represent the hierarchy of a design. A more common way of
depicting hierarchical relationships is:
52
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
We say that a parent instantiates a child module. That is, it creates an instance of it to
be a submodel of the parent. In this example,
Modules in a hierarchy have both a type and a name. Module types are defined in
Verilog. There can be many module instances of the same type of module in a single
hierarchy. The module definition by itself does not create a module. Modules are created by
being instantiated in another module, like this:
53
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
This is just an introductory level tutorial to the VHDL language. The reader is
encouraged to go through the various VHDL tutorials to understand the language better:
VHDL stands for VHSIC (Very High Speed Integrated Circuits) Hardware
Description Language. This tutorial deals with VHDL, as described by the IEEE standard
1076-1993.
The highest level of abstraction is the behavioral level that describes a system in
terms of what it does (or how it behaves) rather than in terms of its components and
interconnection between them. A behavioral description specifies the relationship between
the input and output signals. This could be a Boolean expression or a more abstract
description such as the Register Transfer or Algorithmic level.
As an example, let us consider a simple circuit that warns car passengers when the
door is open or the seatbelt is not used whenever the car key is inserted in the ignition lock At
the behavioral level this could be expressed as,
The structural level, on the other hand, describes a system as a collection of gates
and components that are interconnected to perform a desired function. A structural
description could be compared to a schematic of interconnected logic gates. It is a
representation that is usually closer to the physical realization of a system.
For the example above, the structural representation is shown in Figure below.
54
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
VHDL allows one to describe a digital system at the structural or the behavioral level.
The behavioral level can be further divided into two kinds of styles: Data flow and
Algorithmic. The dataflow representation describes how data moves through the system.
This is typically done in terms of data flow between registers (Register Transfer level). The
data flow model makes use of concurrent statements that are executed in parallel as soon as
data arrives at the input. On the other hand, sequential statements are executed in the
sequence that they are specified. VHDL allows both concurrent and sequential signal
assignments that will determine the manner in which they are executed.
A digital system in VHDL consists of a design entity that can contain other entities
that are then considered components of the top-level entity. Each entity is modeled by an
entity declaration and an architecture body. One can consider the entity declaration as the
interface to the outside world that defines the input and output signals, while the architecture
body contains the description of the entity and is composed of interconnected entities,
processes and components, all operating concurrently, as schematically shown in Figure. In a
typical design there will be many such entities connected together to perform the desired
function.
VHDL uses reserved keywords that cannot be used as signal names or identifiers.
Keywords and user-defined identifiers are case insensitive. Lines with comments start with
two adjacent hyphens (--) and will be ignored by the compiler. VHDL also ignores line
breaks and extra spaces. VHDL is a strongly typed language which implies that one has
always to declare the type of every object that can have a value, such as signals, constants
and variables.
a. Entity Declaration
55
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
The entity declaration defines the NAME of the entity and lists the input and output ports.
The general form is as follows,
An entity always starts with the keyword entity, followed by its name and the
keyword is. Next are the port declarations using the keyword port. An entity declaration
always ends with the keyword end, optionally [ ] followed by the name of the entity.
• generic: generic declarations are optional and determine the local constants
used for timing and sizing (e.g. bus widths) the entity. A generic can
have a default value. The syntax for a generic follows,
generic (
constant_name: type [:=value] ;
constant_name: type [:=value] ;
:
constant_name: type [:=value] );
For the example shown above, the entity declaration looks as follows.
-- comments: example of the buzzer circuit of fig. 2
entity BUZZER is
port (DOOR, IGNITION, SBELT: in std_logic;
56
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
The entity is called BUZZER and has three input ports, DOOR, IGNITION and
SBELT and one output port, WARNING. Notice the use and placement of semicolons! The
name BUZZER is an identifier. Inputs are denoted by the keyword in, and outputs by the
keyword out. Since VHDL is a strongly typed language, each port has a defined type. In this
case, we specified the std_logic type. This is the preferred type of digital signals. In
contrast to the bit type that can only have the values ‘1’ and ‘0’, the std_logic and std_ulogic
types can have nine values. This is important to describe a digital system accurately including
the binary values 0 and 1, as well as the unknown value X, the uninitialized value U, “-” for
don’t care, Z for high impedance, and several symbols to indicate the signal strength (e.g. L
for weak 0, H for weak 1, W for weak unknown - see section on Enumerated Types). The
std_logic type is defined in the std_logic_1164 package of the IEEE library. The type defines
the set of values an object can have. This has the advantage that it helps with the creation of
models and helps reduce errors. For instance, if one tries to assign an illegal value to an
object, the compiler will flag the error.
entity mux4_to_1 is
port (I0,I1,I2,I3: in std_logic_vector(7 downto 0);
OUT1: out std_logic_vector(7 downto 0));
end mux4_to_1;
An example of the entity declaration of a D flip-flop with set and reset inputs is
entity dff_sr is
port (D,CLK,S,R: in std_logic;
Q,Qnot: out std_logic);
end dff_sr;
b. Architecture body
The architecture body specifies how the circuit operates and how it is implemented.
As discussed earlier, an entity or circuit can be specified in a variety of ways, such as
behavioral, structural (interconnected components), or a combination of the above.
57
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
:
end architecture_name;
Behavioral model
The architecture body for the example shown above, described at the behavioral level,
is given below,
The header line of the architecture body defines the architecture name,
e.g. behavioral, and associates it with the entity, BUZZER. The architecture name can be
any legal identifier. The main body of the architecture starts with the keyword begin and
gives the Boolean expression of the function. We will see later that a behavioral model can be
described in several other ways. The “<= ” symbol represents an assignment operator and
assigns the value of the expression on the right to the signal on the left. The architecture body
ends with an end keyword followed by the architecture name.
A few other examples follow. The behavioral description of a two-input AND gate is
shown below.
entity AND2 is
port (in1, in2: in std_logic;
out1: out std_logic);
end AND2;
entity XNOR2 is
port (A, B: in std_logic;
Z: out std_logic);
end XNOR2;
58
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
(see section on Operators). For more information on behavioral modeling see section on
Behavioral Modeling.
Structural description
The circuit of above example can also be described using a structural model that
specifies what gates are used and how they are interconnected. The following example
illustrates it.
end structural;
Following the header is the declarative part that gives the components (gates) that are
going to be used in the description of the circuits. In our example, we use a two- input AND
gate, two-input OR gate and an inverter. These gates have to be defined first, i.e. they will
need an entity declaration and architecture body (as shown in the previous example). These
can be stored in one of the packages one refers to in the header of the file (see Library and
Packages below). The declarations for the components give the inputs (e.g. in1, in2) and the
output (e.g. out1). Next, one has to define internal nets (signal names). In our example these
signals are called DOOR_NOT, SBELT_NOT, B1, B2 (see Figure 2). Notice that one always
has to declare the type of the signal.
The statements after the begin keyword gives the instantiations of the components
and describes how these are interconnected. A component instantiation statement creates a
new level of hierarchy. Each line starts with an instance name (e.g. U0) followed by a colon
and a component name and the keyword port map. This keyword defines how the
components are connected. In the example above, this is done through positional association:
DOOR corresponds to the input, in1 of the NOT1 gate and DOOR_NOT to the output.
Similarly, for the AND2 gate where the first two signals (IGNITION and
DOOR_NOT) correspond to the inputs in1 and in2, respectively, and the signal B1 to the
59
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
output out1. An alternative way is to use explicit association between the ports, as shown
below.
U0: NOT1 port map (in1 => DOOR, out1 => DOOR_NOT);
U1: NOT1 port map (in1 => SBELT, out1 => SBELT_NOT);
U2: AND2 port map (in1 => IGNITION, in2 => DOOR_NOT, out1 => B1);
U3: AND2 port map (in1 => IGNITION, in2 => SBELT_NOT, B2);
U4: OR2 port map (in1 => B1, in2 => B2, out1 => WARNING);
Notice that the order in which these statements are written has no bearing on the
execution since these statements are concurrent and therefore executed in parallel. Indeed, the
schematic that is described by these statements is the same independent of the order of the
statements.
Structural modeling of design lends itself to hierarchical design, in which one can
define components of units that are used over and over again. Once these components are
defined they can be used as blocks, cells or macros in a higher level entity. This can
significantly reduce the complexity of large designs. Hierarchical design approaches are
always preferred over flat designs. We will illustrate the use of a hierarchical design approach
for a 4-bit adder, shown in Figure 4 below. Each full adder can be described by the Boolean
expressions for the sum and carry out signals,
sum = (A ⊕ B) ⊕ C
carry = AB + C(A ⊕ B)
In the VHDL file, we have defined a component for the full adder first. We used
several instantiations of the full adder to build the structure of the 4-bit adder. We have
included the library and use clause as well as the entity declarations.
60
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
-- 4-bit adder
library ieee;
use ieee.std_logic_1164.all;
entity FOURBITADD is
port (a, b: in std_logic_vector(3 downto 0);
Cin : in std_logic;
sum: out std_logic_vector (3 downto 0);
Cout, V: out std_logic);
end FOURBITADD;
Notice that the same input names a and b for the ports of the full adder and the 4-bit
adder were used. This does not pose a problem in VHDL since they refer to different levels.
However, for readability, it may be easier to use different names. We needed to define the
internal signals c(4:0) to indicate the nets that connect the output carry to the input carry of
the next full adder. For the first input we used the input signal Cin. For the last carry we
defined c(4) as an internal signal since the last carry is needed as the input to the xor gate. We
could not use the output signal Cout since VHDL does not allow the use of outputs as
internal signals! For this reason we had to define the internal carry c(4) and assign c(4) to the
output carry signal Cout.
61
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
A library can be considered as a place where the compiler stores information about a
design project. A VHDL package is a file or module that contains declarations of commonly
used objects, data type, component declarations, signal, procedures and functions that can be
shared among different VHDL models.
library ieee;
use ieee.std_logic_1164.all;
ieee Library:
To use any of these one must include the library and use clause:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
One can add other libraries and packages. The syntax to declare a package is as follows:
-- Package declaration
package name_of_package is
package declarations
end package name_of_package;
-- Package body declarations
package body name_of_package is
package body declarations
end package body name_of_package;
For instance, the basic functions of the AND2, OR2, NAND2, NOR2, XOR2, etc.
components need to be defined before one can use them. This can be done in a package, e.g.
basic_func for each of these components, as follows:
-- Package declaration
62
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
library ieee;
use ieee.std_logic_1164.all;
package basic_func is
-- AND2 declaration
component AND2
generic (DELAY: time :=5ns);
port (in1, in2: in std_logic; out1: out std_logic);
end component;
-- OR2 declaration
component OR2
generic (DELAY: time :=5ns);
port (in1, in2: in std_logic; out1: out std_logic);
end component;
end package basic_func;
Notice that we included a delay of 5 ns. However, it should be noticed that delay
specifications are ignored by the Foundation synthesis tool. We made use of the predefined
type std_logic that is declared in the package std_logic_1164. We have included the
library and use clause for this package. This package needs to be compiled and placed in
a library. Lets call this library my_func. To use the components of this package one has to
declare it using the library and use clause:
One can concatenate a series of names separated by periods to select a package. The
library and use statements are connected to the subsequent entity statement. The library
and use statements have to be repeated for each entity declaration.
63
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Constant
A constant can have a single value of a given type and cannot be changed during the
simulation. A constant is declared as follows,
where the initial value is optional. Constants can be declared at the start of an
architecture and can then be used anywhere within the architecture. Constants declared
within a process can only be used inside that specific process.
Variable
A variable can have a single value, as with a constant, but a variable can be updated
using a variable assignment statement. The variable is updated without any delay as soon as
the statement is executed. Variables must be declared inside a process. The variable
declaration is as follows:
The variable SUM, in the example above, is an integer that has a range from 0 to 256
with initial value of 16 at the start of the simulation. The fourth example defines a bit vector
or 8 elements: STS_BIT(7), STS_BIT(6),… STS_BIT(0).
Variable_name := expression;
Signal
Signals are declared with the following statement:
Signals are updated when their signal assignment statement is executed, after a certain
delay, as illustrated below,
64
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
One can also specify multiple waveforms using multiple events as illustrated below,
In the first case, the variables “variable1, variable2 and variable3” are computed
sequentially and their values updated instantaneously after the TRIGGER signal arrives.
Next, the RESULT is computed using the new values of the variables. This results in the
following values (after a time TRIGGER): variable1 = 2, variable2 = 5 (=2+3), variable3= 5.
65
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Since RESULT is a signal it will be computed at the time TRIGGER and updated at the time
TRIGGER + Delta. Its value will be RESULT=12.
On the other hand, in the second example, the signals will be computed at the time
TRIGGER. All of these signals are computed at the same time, using the old values of
signal1, 2 and 3. All the signals will be updated at Delta time after the TRIGGER has arrived.
Thus the signals will have these values: signal1= 2, signal2= 4 (=1+3), signal3=2 and
RESULT=7.
Enumerated Types
An enumerated type consists of lists of character literals or identifiers. The
enumerated type can be very handy when writing models at an abstract level. The syntax for
an enumerated type is,
type type_name is (identifier list or character literal);
If one does not initialize the signal, the default initialization is the leftmost element of the list.
type STD_ULOGIC is (
‘U’, -- uninitialized
‘X’, -- forcing unknown
‘0’, -- forcing 0
‘1’, -- forcing 1
‘Z’, -- high impedance
‘W’, -- weak unknown
‘L’, -- weak 0
‘H’. -- weak 1
‘-‘); -- don’t care
In order to use this type one has to include the clause before each entity declaration.
66
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Array Type
In the first two examples above we have defined a one-dimensional array of elements
of the type std_logic indexed from 15 down to 0, and 0 up to 15, respectively. The last
example defines a one-dimensional array of the type std_logic elements that uses the type
std_ulogic to define the index constraint. Thus this array looks as follows:
Index: ‘U’ ‘X’ ‘0’ ‘1’ ‘Z’ ‘W’ ‘L’ ‘H’ ‘-‘
Element:
We can now declare objects of these data types. Some examples are given
In the first example, the signal MEM_ADDR is an array of 16 bits, initialized to all
‘0’s. To access individual elements of an array we specify the index. For example,
MEM_ACCR(15) accesses the left most bit of the array, while DATA_WORD(15) accesses
the right most bit of the array with value ‘0’. To access a subrange, one specifies the index
range, MEM_ADDR(15 downto 8) or DATA_WORD(0 to 7).
0 2
1 3
4 6
5 7
To access an element one specifies the index, e.g. DATA_ARR(3,1) returns the value 4.
The last example defines a 9x9 array or table with an index the elements of the std_ulogic
type.
67
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Sometimes it is more convenient not to specify the dimension of the array when the
array type is declared. This is called an unconstrained array type. The syntax for the array
declaration is,
The range is now specified when one declares the array object,
variable MATRIX8: MATRIX (2 downto -8) := (3, 5, 1, 4, 7, 9, 12, 14, 20, 18);
variable ARRAY3x2: VECTOR2 (1 to 4, 1 to 3)) := ((‘1’,’0’), (‘0’,’-‘), (1, ‘Z’));
Record Type
A second composite type is the records type. A record consists of multiple elements
that may be of different types. The syntax for a record type is the following:
type name is
record
identifier :subtype_indication;
:
identifier :subtype_indication;
end record;
As an example,
type MY_MODULE is
record
RISE_TIME :time;
FALL_TIME : time;
SIZE : integer range 0 to 200;
DATA : bit_vector (15 downto 0);
end record;
signal A, B: MY_MODULE;
To access values or assign values to records, one can use one of the following methods:
B <= A;
Type Conversions
Since VHDL is a strongly typed language one cannot assign a value of one data type
to a signal of a different data type. In general, it is preferred to the same data types for the
68
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
signals in a design, such as std_logic (instead of a mix of std_logic and bit types). Sometimes
one cannot avoid using different types. To allow assigning data between objects of different
types, one needs to convert one type to the other. Fortunately there are functions available in
several packages in the ieee library, such as the std_logic_1164 and the std_logic_arith
packages. As an example, the std_logic_1164 package allows the following conversions:
The IEEE std_logic_unsigned and the IEEE std_logic_arith packages allow additional
conversions such as from an integer to std_logic_vector and vice versa.
An example follows.
entity QUAD_NAND2 is
port (A, B: in bit_vector(3 downto 0);
out4: out std_logic_vector (3 downto 0));
end QUAD_NAND2;
The expression “A and B” which is of the type bit_vector has to be converted to the type
std_logic_vector to be of the same type as the output signal out4.
type_name (expression);
In order for the conversion to be legal, the expression must return a type that can be
converted into the type type_name. Here are the conditions that must be fulfilled for the
conversion to be possible.
• Type conversions between integer types or between similar array types are possible
• Conversion between array types is possible if they have the same length and if they have
identical element types or convertible element types.
• Enumerated types cannot be converted.
Signal attributes
The following table gives several signal attributes.
69
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Attribute Function
signal_name’event returns the Boolean value True if an event on the
signal occurred, otherwise gives a False
signal_name’active returns the Boolean value True there has been a
transaction (assignment) on the signal, otherwise
gives a False
signal_name’transaction returns a signal of the type “bit” that toggles (0 to 1
or 1 to 0) every time there is a transaction on the
signal.
signal_name’last_event returns the time interval since the last event on the
signal
signal_name’last_active returns the time interval since the last transaction
on the signal
signal_name’last_value gives the value of the signal before the last event
occurred on the signal
signal_name’delayed(T) gives a signal that is the delayed version (by time
T) of the original one. [T is optional, default T=0]
signal_name’stable(T) returns a Boolean value, True, if no event has
occurred on the signal during the interval T,
otherwise returns a False. [T is optional, default
T=0]
signal_name’quiet(T) returns a Boolean value, True, if no transaction has
occurred on the signal during the interval T,
otherwise returns a False. [T is optional, default
T=0]
An example of an attribute is
This expression checks for the arrival of a positive clock edge. To find out how much time
has passed since the last clock edge, one can use the following attribute:
CLOCK’last_event
Scalar attributes
Several attributes of a scalar type, scalar-type, are supported. The following table shows
some of these attributes.
Attribute Value
scalar_type’left returns the first or leftmost value of scalar-
type in its defined range
scalar_type’right returns the last or rightmost value of scalar-
type in its defined range
scalar_type’low returns the lowest value of scalar-type in its
defined range
scalar_type’high returns the greatest value of scalar-type in
its defined range
scalar_type’ascending True if T is an ascending range, otherwise
70
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
False
scalar_type’value(s) returns the value in T that is represented by
s (s stands for string value).
Operators
VHDL supports different classes of operators that operate on signals, variables and constants.
The different classes of operators are summarized below.
Class
1. Logical operators and or nand nor xor xnor
2. Relational operators = /= < <= > >=
3. Shift operators sll srl sla sra rol ror
4.Addition operators + = &
5. Unary operators + -
6. Multiplying op. * / mod rem
7. Miscellaneous op. ** abs not
The order of precedence is the highest for the operators of class 7, followed by class 6 with
the lowest precedence for class 1. Unless parentheses are used, the operators with the highest
precedence are applied first. Operators of the same class have the same precedence and are
applied from left to right in an expression. As an example, consider the following
std_ulogic_vectors, X (=’010’), Y(=’10’), and Z (‘10101’). The expression
is equivalent to ((not X) & Y) xor (Z rol 1) = ((101) & 10) xor (01011) =(10110) xor
(01011) = 11101. The xor is executed on a bit-per-bit basis.
Behavioral Modeling: Sequential Statements
As discussed earlier, VHDL provides means to represent digital circuits at different
levels of representation of abstraction, such as the behavioral and structural modeling. In this
section we will discuss different constructs for describing the behavior of components and
71
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
circuits in terms of sequential statements. The basis for sequential modeling is the process
construct. As you will see, the process construct allows us to model complex digital systems,
in particular sequential circuits.
a. Process
A process statement is the main construct in behavioral modeling that allows you to use
sequential statements to describe the behavior of a system over time. The syntax for a process
statement is
library ieee;
use ieee.std_logic_1164.all;
entity DFF_CLEAR is
port (CLK, CLEAR, D : in std_logic;
Q : out std_logic);
end DFF_CLEAR;
72
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
flop in the above example. The expression CLK’event and CLK = ‘1’ checks for a
positive clock edge (clock event AND clock high).
The sensitivity list is a set of signals to which the process is sensitive. Any change in
the value of the signals in the sensitivity list will cause immediate execution of the process. If
the sensitivity list is not specified, one has to include a wait statement to make sure that the
process will halt. Notice that one cannot include both a sensitivity list and a wait statement.
Variables and constants that are used inside a process have to be defined in the
process_declarations part before the keyword begin. The keyword begin signals the start of
the computational part of the process. The statements are sequentially executed, similarly as
a conventional software program. It should be noted that variable assignments inside a
process are executed immediately and denoted by the “:=” operator. This is in contrast to
signal assignments denoted by “<=” and which changes occur after a delay. As a result,
changes made to variables will be available immediately to all subsequent statements within
the same process. For an example that illustrates the difference between signal and variable
assignments see the section on Data Types (difference between signals and variables).
The previous example of the D flip-flop illustrates how to describe a sequential circuit
with the process statement. Although the process is mainly used to describe sequential
circuits, one can also describe combinational circuits with the process construct. The
following example illustrates this for a Full Adder, composed of two Half Adders. This
example also illustrates how one process can generate signals that will trigger other processes
when events on the signals in its sensitivity list occur [3]. We can write the Boolean
expression of a Half Adder and Full Adder as follows:
Figure 5: Full Adder composed of two Half Adders, modeled with two processes P1 and P2.
library ieee;
use ieee.std_logic_1164.all;
entity FULL_ADDER is
port (A, B, Cin : in std_logic;
Sum, Cout : out std_logic);
end FULL_ADDER;
73
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Of course, one could simplify the behavioral model significantly by using a single process.
Wait statement
The wait statement will halt a process until an event occurs. There are several forms
of the wait statement,
The Xilinx Foundation Express has implemented only the first form of the wait statement.
The syntax is as follows,
The condition in the “wait until” statement must be TRUE for the process to resume. A
few examples follow.
The sequence following detector recognizes the input bit sequence X: "1011". The
machine will keep checking for the proper bit sequence and does not reset to the initial state
74
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
after it recognizes the string. In case we are implementing a Mealy machine, the output is
associated with the transitions as indicated on the following state diagram (Figure 6).
entity myvhdl is
port (CLK, RST, X: in STD_LOGIC;
Z: out STD_LOGIC);
end;
75
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
when S4 =>
if X='0' then
Sreg0 <= S3;
elsif X='1' then
Sreg0 <= S2;
end if;
when others =>
null;
end case;
end if;
end if;
end process;
-- signal assignment statements for combinatorial outputs
Z_assignment:
Z <= '0' when (Sreg0 = S1 and X='0') else
'0' when (Sreg0 = S1 and X='1') else
'0' when (Sreg0 = S2 and X='1') else
'0' when (Sreg0 = S2 and X='0') else
'0' when (Sreg0 = S3 and X='1') else
'0' when (Sreg0 = S3 and X='0') else
'0' when (Sreg0 = S4 and X='0') else
'1' when (Sreg0 = S4 and X='1') else
'1';
end myvhdl_arch;
Concurrent signal assignments are event triggered and executed as soon as an event
on one of the signals occurs. In the remainder of the section we will describe several
concurrent constructs for use in dataflow modeling.
We have discussed several concurrent examples earlier in the tutorial. In this section
we will review the different types of concurrent signal assignments.
76
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Another example is given below of a 4-bit adder circuit. Notice that we specified the
package: IEEE.std_logic_unsigned in order to be able to use the “+” (addition) operator.
entity ADD4 is
port (
A: in STD_LOGIC_VECTOR (3 downto 0);
B: in STD_LOGIC_VECTOR (3 downto 0);
CIN: in STD_LOGIC;
SUM: out STD_LOGIC_VECTOR (3 downto 0);
COUT: out STD_LOGIC
);
end ADD4;
begin
-- <<enter your statements here>>
Structural Modeling
Structural modeling was described briefly in the section Structural Modeling in
“Basic Structure of a VHDL file”. A structural way of modeling describes a circuit in terms
of components and its interconnection. Each component is supposed to be defined earlier
(e.g. in package) and can be described as structural, a behavioral or dataflow model. At the
lowest hierarchy each component is described as a behavioral model, using the basic logic
operators defined in VHDL. In general structural modeling is very good to describe complex
digital systems, though a set of components in a hierarchical fashion.
A structural description can best be compared to a schematic block diagram that can
be described by the components and the interconnections. VHDL provides a formal way to
do this by
• Declare a list of components being used
77
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Component declaration
The component name refers to either the name of an entity defined in a library or an
entity explicitly defined in the VHDL file (see example of the four bit adder).
The list of interface ports gives the name, mode and type of each port, similarly as is
done in the entity declaration.
component OR2
port (in1, in2: in std_logic;
out1: out std_logic);
end component;
component PROC
port (CLK, RST, RW, STP: in std_logic;
ADDRBUS: out std_logic_vector (31 downto 0);
DATA: inout integer range 0 to 1024);
component FULLADDER
port(a, b, c: in std_logic;
sum, carry: out std_logic);
end component;
As mentioned earlier, the component declaration has to be done either in the
architecture body or in the package declaration. If the component is declared in a package,
one does not have to declare it again in the architecture body as long as one uses the
library and use clause.
78
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
The instance name or label can be any legal identifier and is the name of this
particular instance. The component name is the name of the component declared earlier using
the component declaration statement. The port name is the name of the port and signal is the
name of the signal to which the specific port is connected. The above port map associates the
ports to the signals through named association. An alternative method is the positional
association shown below,
in which the first port in the component declaration corresponds to the first signal, the second
port to the second signal, etc. The signal position must be in the same order as the declared
component’s ports. One can mix named and positional associations as long as one puts all
positional associations before the named ones. The following examples illustrates this,
component NAND2
port (in1, in2: in std_logic;
out1: out std_logic);
end component;
signal int1, int2, int3: std_logic;
architecture struct of EXAMPLE is
U1: NAND2 port map (A,B,int1);
U2: NAND2 port map (in2=>C, in2=>D, out1=>int2);
U3: NAND3 port map (in1=>int1, int2, Z);
…..
library IEEE;
79
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity halfadder is
Port ( a : in std_logic;
b : in std_logic;
s : out std_logic;
c : out std_logic);
end halfadder;
architecture Behavioral of halfadder is
begin
s <= a xor b;
c <= a and b;
end Behavioral;
2) Full Adder:-
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity fa is
Port ( a : in std_logic;
b : in std_logic;
cin : in std_logic;
sum : out std_logic;
cout : out std_logic);
end fa;
architecture Behavioral of fa is
begin
sum <= a xor b xor cin;
cout <= (a and b) or (b and cin) or (cin and a);
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity fa is
Port ( a : in std_logic;
b : in std_logic;
cin : in std_logic;
sum : out std_logic;
cout : out std_logic);
end fa;
architecture Behavioral of fa is
begin
sum <= a xor b xor cin;
cout <= (a and b) or (b and cin) or (cin and a);
end Behavioral;
80
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity adder_8 is
Port ( a : in std_logic_vector(7 downto 0);
b : in std_logic_vector(7 downto 0);
cin : in std_logic;
cout : out std_logic;
sum : out std_logic_vector(7 downto 0));
end adder_8;
architecture Behavioral of adder_8 is
component fa is
Port ( a : in std_logic;
b : in std_logic;
cin : in std_logic;
sum : out std_logic;
cout : out std_logic);
end component;
signal c : std_logic_vector(6 downto 0);
begin
Inst0 : fa port map (a => a(0), b => b(0), cin => cin, cout
=> c(0), sum => sum(0));
Inst1 : fa port map (a => a(1), b => b(1), cin => c(0), cout
=> c(1), sum => sum(1));
Inst2 : fa port map (a => a(2), b => b(2), cin => c(1), cout
=> c(2), sum => sum(2));
Inst3 : fa port map (a => a(3), b => b(3), cin => c(2), cout
=> c(3), sum => sum(3));
Inst4 : fa port map (a => a(4), b => b(4), cin => c(3), cout
=> c(4), sum => sum(4));
Inst5 : fa port map (a => a(5), b => b(5), cin => c(4), cout
=> c(5), sum => sum(5));
Inst6 : fa port map (a => a(6), b => b(6), cin => c(5), cout
=> c(6), sum => sum(6));
Inst7 : fa port map (a => a(7), b => b(7), cin => c(6), cout
=> cout, sum => sum(7));
end Behavioral;
4) 4 – BIT MULTIPLIER:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
81
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
entity multiplier is
port( clk : in std_logic;
a, b : in std_logic_vector(3 downto 0);
product : out std_logic_vector(9 downto 0));
end multiplier;
architecture Behavioral of multiplier is
signal cin : std_logic:='0';
signal s1,s2,s3,s4 : std_logic_vector(7 downto 0);
signal a1,a2,a3,a4 : std_logic_vector(7 downto 0);
signal sum1 : std_logic_vector(8 downto 1);
signal sum2 : std_logic_vector(8 downto 1);
signal carry1 : std_logic_vector(8 downto 1);
signal carry2 : std_logic_vector(8 downto 1);
signal out1,out2 : std_logic_vector(8 downto 0);
signal sum3,carry3 : std_logic_vector(9 downto 1);
begin
process(clk)
begin
if clk 'event and clk='1' then
s1<= "0000" & a ;
s2<= "000" & a & '0';
s3<= "00" & a & "00";
s4<= '0' & a & "000";
if b(0)='1' then
a1<=s1;
else
a1<= "00000000";
end if;
if b(1)='1' then
a2<=s2;
else
a2<="00000000";
end if;
if b(2)='1' then
a3<=s3;
else
a3<="00000000";
end if;
if b(3)='1' then
a4<=s4;
else
a4<="00000000";
end if;
--------------------------------------------------------------
carry1(1)<=(a1(0) and a2(0)) or (a2(0) and cin) or (cin and
a1(0));
carry1(2)<=(a1(1) and a2(1)) or (a2(1) and carry1(1)) or
(carry1(1) and a1(1));
carry1(3)<=(a1(2) and a2(2)) or (a2(2) and carry1(2)) or
(carry1(2) and a1(2));
carry1(4)<=(a1(3) and a2(3)) or (a2(3) and carry1(3)) or
(carry1(3) and a1(3));
82
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
83
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
entity JKff is
port( clk, reset : in std_logic; ---inputs----
j, k : in std_logic;
q : out std_logic); ---outputs---
end JKff;
Architecture behavioural of JKff is
signal q_r :std_logic;
BEGIN
process(j, k, reset, clk)
BEGIN
if reset=’0’ then
q_r <= ‘0’;
elsif(clk’event and clk=’1’) then
if(j=’0’ and k=’0’) then
q_r <= q_r;
elsif(j=’0’ and k=’1’) then
q_r <= ‘0’;
elsif(j=’1’ and k=’0’) then
q_r <= ‘1’;
elsif(j=’1’ and k=’1’) then
q_r <= not(q_r);
84
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
end if;
end if;
end process;
q<=q_r;
end behavioural;
6) RAM design:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ram_8x32 is
Port ( clk : in std_logic;
wen : in std_logic;
addr : in std_logic_vector(2 downto 0);
di_wr : in std_logic_vector(31 downto 0);
do_wr : out std_logic_vector(31 downto 0));
end ram_8x32;
architecture Behavioral of ram_8x32 is
type ram_type is array (7 downto 0) of std_logic_vector(31 downto
0);
signal dpram8b32_storage : ram_type := (others=> (others => '0'));
begin
process(clk)
begin
if(clk'event and clk='1')then
if(wen = '1') then
dpram8b32_storage(conv_integer(addr)) <= di_wr;
end if;
end if;
end process;
do_wr <= dpram8b32_storage(conv_integer(addr));
end Behavioral;
85
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
variable NS : state_type;
begin
if(rst = '1')then
NS := A;
elsif(clk'event and clk = '1')then
case NS is
when A =>
z <= '0';
if(x = '1') then
NS := B;
else
NS := A;
end if;
when B =>
if(x = '1')then
NS := B;
z <= '1';
else
NS := A;
z <= '0';
end if;
end case;
end if;
end process;
end Behavioral;
Moore Machine
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity sm_moore_11_ol is
Port ( clk : in std_logic;
rst : in std_logic;
x : in std_logic;
z : out std_logic);
end sm_moore_11_ol;
architecture Behavioral of sm_moore_11_ol is
type state is (A,B,C);
signal temp : state;
begin
process(rst, clk)
begin
if(rst = '1') then
temp <= A;
elsif(clk'event and clk = '1')then
case temp is
when A =>
86
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
if(x='0')then
temp <= A;
else
temp <= B;
end if;
when B =>
if (x = '0') then
temp <= A;
else
temp <= C;
end if;
when others =>
if (x = '0') then
temp <= A;
else
temp <= C;
end if;
end case;
end if;
end process;
with temp select
z <= '0' when A | B,
'1' when others;
end Behavioral;
1) NAND Latch:
module ffNand;
wire q, qBar;
reg preset, clear;
nand #1
g1 (q, qBar, preset),
g2 (qBar, q, clear);
initial
begin
// two slashes introduce a single line comment
$monitor ($time,,
"Preset = %b clear = %b q = %b qBar = %b",
preset, clear, q, qBar);
//waveform for simulating the nand flip flop
#10 preset = 0; clear = 1;
#10 preset = 1;
#10 clear = 0;
#10 clear = 1;
#10 $finish;
87
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
end
endmodule
module top();
wire flag, numProduced, numConsumed;
wire [15:0] number, numberOut;
wire x2;
table
0 00 : 0;
0 01 : 0;
0 10 : 0;
0 11 : 1;
1 00 : 0;
1 01 : 1;
1 10 : 1;
1 11 : 1;
88
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
endtable
endprimitive
table
0 0? : 0;
0 ?0 : 0;
? 00 : 0;
? 11 : 1;
1 ?1 : 1;
1 1? : 1;
endtable
endprimitive
bufif1
g1(w1, dataIn, write);
tranif1
g2(w4, w1, address);
not (pull0, pull1)
g3(w3, w4), g4(w4, w3);
buf
g5(dataOut, w1);
89
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
endmodule
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity traffic_fsm is
Port ( CLK_4M,RESET : in std_logic;
TRC_LS,TRC_LW,TRC_LN,TRC_LE: out std_logic;
TRC_SS,TRC_SW,TRC_SN,TRC_SE: out std_logic;
TRC_RS,TRC_RW,TRC_RN,TRC_RE : out std_logic;
TRC_REDS,TRC_REDW,TRC_REDN,TRC_REDE : out
std_logic;
TRC_YS,TRC_YW,TRC_YN,TRC_YE : out std_logic;
TRC_PSR,TRC_PWR,TRC_PNR,TRC_PER : out std_logic;
TRC_PSG,TRC_PWG,TRC_PNG,TRC_PEG : out std_logic);
end traffic_fsm;
90
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
91
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
end if;
when west_r =>
if(cnt = 15 )then
ns <= north_g;
else
ns <= west_r;
end if;
when north_g =>
if(cnt = 10)then
ns <= north_orange;
else
ns <= north_g;
end if;
when north_orange =>
if(cnt = 14)then
ns <= north_r;
else
ns <= north_orange;
end if;
when north_r =>
if(cnt = 15)then
ns <= east_g;
else
ns <= north_r;
end if;
when east_g =>
if(cnt = 10)then
ns <= east_orange;
else
ns <= east_g;
end if;
when east_orange =>
if(cnt = 14)then
ns <= east_r;
else
ns <= east_orange;
end if;
when east_r =>
if(cnt = 15)then
ns <= south_g;
else
ns <= east_r;
end if;
when others =>
ns <= start;
end case;
end process;
process(ps)
begin
92
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
93
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
94
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
95
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
96
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
Similarly when Orange light of South direction is ON then the signals that are ON, now
are
Ð TRC_LS ( left south ) –‘1’.
Ð TRC_YS ( yellow south ) –‘1’.
Ð TRC_LE ( left east ) –‘1’.
Ð TRC_REDW ( red west ) –‘1’.
Ð TRC_REDN (red north ) –‘1’.
Ð TRC_REDE (red east ) –‘1’.
Ð TRC_PSR ( pedestrian south red) –‘1’.
Ð TRC_PWR ( pedestrian west red) –‘1’.
Ð TRC_PNR ( pedestrian north red) –‘1’.
Ð TRC_PER ( pedestrian east red) –‘1’.
Similarly when Red light of South direction is ON then the signals that are ON, now are
Ð TRC_LS ( left south ) –‘1’.
Ð TRC_REDW ( red west ) –‘1’.
Ð TRC_REDN (red north ) –‘1’.
Ð TRC_REDE (red east ) –‘1’.
Ð TRC_PSR ( pedestrian south red) –‘1’.
Ð TRC_PWR ( pedestrian west red) –‘1’.
Ð TRC_PNR ( pedestrian north red) –‘1’.
Ð TRC_PER ( pedestrian east red) –‘1’.
During this time all ways are Blocked for 1 second except left south ( ls -‘1’ ) and so on.
After that it goes clockwise for all Direction (i.e.:- South then West then North then East)
similarly.
97
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
reg l_n,y_n,redn,png ;
reg l_w,y_w,redw,pwg ;
reg l_e,y_e,rede,peg ;
reg l_s,y_s,reds,psg ;
reg ls,lw,ln,le;
reg ss,sw,sn,se;
reg rs,rw,rn,re;
reg red_s,red_w,red_n,red_e;
reg ys,yw,yn,ye;
reg ps_r,pw_r,pn_r,pe_r;
reg ps_g,pw_g,pn_g,pe_g;
reg [3:0]ps,ns;
reg [30:0] div;
reg [3:0] cnt;
wire clk_s;
parameter [3:0]start = 4'b0000;
parameter [3:0]south_g = 4'b0001;
parameter [3:0]south_orange = 4'b0010;
parameter [3:0]south_r = 4'b0011;
parameter [3:0]west_g = 4'b0100;
parameter [3:0]west_orange = 4'b0101;
parameter [3:0]west_r = 4'b0110;
parameter [3:0]east_g = 4'b0111;
parameter [3:0]east_orange = 4'b1000;
parameter [3:0]east_r = 4'b1001;
parameter [3:0]north_g = 4'b1010;
parameter [3:0]north_orange = 4'b1011;
parameter [3:0]north_r = 4'b1100;
always@ (posedge clk or posedge rst)
begin
if (rst)
div <= 2'b00;
else
div <= div + 1;
end
assign clk_s = div[20];
//*************************** Counter **************************
always@(posedge clk_s or posedge rst)
begin
if (rst)
cnt <= 4'b0;
else
cnt <= cnt + 1;
end
//*************************** Memory_logic *********************
always@(posedge clk_s or posedge rst)
begin
if (rst)
ps <= start;
else
ps <= ns;
end
98
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
always @(ps)
case (ps)
start : ns <= south_g;
south_g: begin
if(cnt == 10)
ns <= south_orange;
else
ns <= south_g;
end
south_orange: begin
if(cnt == 14)
ns <= south_r;
else
ns <= south_orange;
end
south_r : begin
if(cnt == 15)
ns <= west_g;
else
ns <= south_r;
end
west_g : begin
if(cnt == 10)
ns <= west_orange;
else
ns <= west_g;
end
west_orange : begin
if(cnt == 14)
ns <= west_r;
else
ns <= west_orange;
end
west_r : begin
if(cnt == 15 )
ns <= north_g;
else
ns <= west_r;
end
north_g : begin
if(cnt == 10)
ns <= north_orange;
else
ns <= north_g;
end
north_orange : begin
if(cnt == 14)
ns <= north_r;
else
ns <= north_orange;
end
north_r : begin
99
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
if(cnt == 15)
ns <= east_g;
else
ns <= north_r;
end
east_g : begin
if(cnt == 10)
ns <= east_orange;
else
ns <= east_g;
end
east_orange : begin
if(cnt == 14)
ns <= east_r;
else
ns <= east_orange;
end
east_r : begin
if(cnt == 15)
ns <= south_g;
else
ns <= east_r;
end
default : ns <= start;
endcase
//*************************** Output_logic **************************
always@(ps)
begin
red_s <= 0;
red_w <= 0;
red_n <= 0;
red_e <= 0;
redn <= 0;
redw <= 0;
rede <= 0;
reds <= 0;
rs <= 0;
rw <= 0;
rn <= 0;
re <= 0;
ss <= 0;
sw <= 0;
sn <= 0;
se <= 0;
ls <= 0;
lw <= 0;
ln <= 0;
le <= 0;
l_n <= 0;
l_w <= 0;
l_e <= 0;
l_s <= 0;
100
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
ps_g <= 0;
pw_g <= 0;
pn_g <= 0;
pe_g <= 0;
png <= 0;
pwg <= 0;
peg <= 0;
psg <= 0;
ys <= 0;
yw <= 0;
yn <= 0;
ye <= 0;
y_n <= 0;
y_w <= 0;
y_e <= 0;
y_s <= 0;
ps_r <= 0;
pw_r <= 0;
pn_r <= 0;
pe_r <= 0;
case (ps)
start : begin
red_s <= 1;
red_w <= 1;
red_n <= 1;
red_e <= 1;
redn <= 1;
redw <= 1;
rede <= 1;
reds <= 1;
end
south_g : begin
ls <= 1;
l_s <= 1;
rs <= 1;
ss <= 1;
le <= 1;
l_e <= 1;
red_w <= 1;
red_n <= 1;
red_e <= 1;
redw <= 1;
redn <= 1;
rede <= 1;
ps_r <= 1;
pw_r <= 1;
pn_r <= 1;
pe_r <= 1;
end
south_orange : begin
pn_g <= 1;
png <= 1;
101
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
le <= 1;
ls <= 1;
l_s <= 1;
ys <= 1;
y_s <= 1;
red_w <= 1;
red_n <= 1;
red_e <= 1;
redw <= 1;
redn <= 1;
rede <= 1;
ps_r <= 1;
pw_r <= 1;
pe_r <= 1;
end
south_r : begin
ls <= 1;
l_s <= 1;
red_w <= 1;
red_n <= 1;
red_e <= 1;
ps_r <= 1;
pw_r <= 1;
pn_r <= 1;
pe_r <= 1;
end
west_g : begin
lw <= 1;
ls <= 1;
rw <= 1;
sw <= 1;
l_w <= 1;
l_s <= 1;
red_s <= 1;
red_n <= 1;
red_e <= 1;
redw <= 1;
redn <= 1;
rede <= 1;
ps_r <= 1;
pw_r <= 1;
pn_r <= 1;
pe_r <= 1;
end
west_orange : begin
lw <= 1;
ls <= 1;
l_w <= 1;
l_s <= 1;
pe_g <= 1;
peg <= 1;
yw <= 1;
102
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
y_w <= 1;
red_s <= 1;
red_n <= 1;
red_e <= 1;
reds <= 1;
redn <= 1;
rede <= 1;
ps_r <= 1;
pw_r <= 1;
pn_r <= 1;
end
west_r : begin
lw <= 1;
l_w <= 1;
red_s <= 1;
red_n <= 1;
red_e <= 1;
reds <= 1;
redn <= 1;
rede <= 1;
ps_r <= 1;
pw_r <= 1;
pn_r <= 1;
pe_r <= 1;
end
north_g : begin
ln <= 1;
l_n <= 1;
rn <= 1;
sn <= 1;
lw <= 1;
l_w <= 1;
red_s <= 1;
red_w <= 1;
red_e <= 1;
reds <= 1;
redw <= 1;
rede <= 1;
ps_r <= 1;
pw_r <= 1;
pn_r <= 1;
pe_r <= 1;
end
north_orange : begin
ln <= 1;
lw <= 1;
l_n <= 1;
l_w <= 1;
ps_g <= 1;
psg <= 1;
yn <= 1;
y_n <= 1;
103
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
red_s <= 1;
red_w <= 1;
red_e <= 1;
reds <= 1;
redw <= 1;
rede <= 1;
pw_r <= 1;
pn_r <= 1;
pe_r <= 1;
end
north_r : begin
ln <= 1;
l_n <= 1;
red_s <= 1;
red_w <= 1;
red_e <= 1;
reds <= 1;
redw <= 1;
rede <= 1;
ps_r <= 1;
pw_r <= 1;
pn_r <= 1;
pe_r <= 1;
end
east_g : begin
re <= 1;
se <= 1;
le <= 1;
ln <= 1;
l_n <= 1;
l_e <= 1;
red_s <= 1;
red_w <= 1;
red_n <= 1;
reds <= 1;
redw <= 1;
rede <= 1;
ps_r <= 1;
pw_r <= 1;
pn_r <= 1;
pe_r <= 1;
end
east_orange : begin
ln <= 1;
le <= 1;
l_n <= 1;
l_e <= 1;
pw_g <= 1;
pwg <= 1;
ye <= 1;
y_e <= 1;
red_s <= 1;
104
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
red_w <= 1;
red_n <= 1;
reds <= 1;
redw <= 1;
rede <= 1;
ps_r <= 1;
pn_r <= 1;
pe_r <= 0;
end
east_r : begin
le <= 1;
l_e <= 1;
red_s <= 1;
red_w <= 1;
red_n <= 1;
reds <= 1;
redw <= 1;
rede <= 1;
ps_r <= 1;
pw_r <= 1;
pn_r <= 1;
pe_r <= 1;
end
default : begin
red_s <= 0;
red_w <= 0;
red_n <= 0;
red_e <= 0;
rs <= 0;
rw <= 0;
rn <= 0;
re <= 0;
ss <= 0;
sw <= 0;
sn <= 0;
se <= 0;
ls <= 0;
lw <= 0;
ln <= 0;
le <= 0;
ps_g <= 0;
pw_g <= 0;
pn_g <= 0;
pe_g <= 0;
ys <= 0;
yw <= 0;
yn <= 0;
ye <= 0;
ps_r <= 0;
pw_r <= 0;
pn_r <= 0;
pe_r <= 0;
105
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
l_n <= 0;
l_w <= 0;
l_e <= 0;
l_s <= 0;
png <= 0;
pwg <= 0;
peg <= 0;
psg <= 0;
y_n <= 0;
y_w <= 0;
y_e <= 0;
y_s <= 0;
redn <= 0;
redw <= 0;
rede <= 0;
reds <= 0;
end
endcase
end
endmodule
--******************************************************
106
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
107
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
108
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
if (sec1_rg == 4'b1001)
sec1_rg <= 4'b0000;
else
sec1_rg <= sec1_rg + 1;
end
end
end
assign sec1 = sec1_rg;
//------------------tc1 signal to start sec2 counter---------------------------
assign tc1 = (sec1_rg == 4'b1001) && (enable == 1);
//--************************* Second_cntr2 ***********************
always@(posedge clock or posedge reset)
begin
if (reset )
sec2_rg <= 4'b0000;
else if (load) begin
sec2_rg <= 4'b0100;
end
else
begin
if (tc1)
begin
if (sec2_rg == 4'b0101) begin
sec2_rg <= 4'b0000;
end
else begin
sec2_rg <= sec2_rg + 1;
end
end
end
end
assign sec2 = sec2_rg;
//-------------------------tc2 signal to start min1 counter-------------------
assign tc2 = (sec2_rg == 4'b0101) && (tc1 == 1);
//--************************ Minute_cntr1 *************************
always@(posedge clock or posedge reset)
begin
if (reset )
min1_rg <= 4'b0000;
else if (load) begin
min1_rg <= 4'b0100;
end
else
begin
if (tc2)
begin
if (min1_rg == 4'b1001) begin
min1_rg <= 4'b0000;
end
else begin
min1_rg <= min1_rg + 1;
end
109
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
end
end
end
assign min1 = min1_rg;
//------------------------tc3 signal to start min2 counter--------------------
assign tc3 = (min1_rg == 4'b1001) && (tc2 == 1);
//--************************ Hour_cntr1 *************************
always@(posedge clock or posedge reset)
begin
if (reset)
min2_rg <= 4'b0000;
else if (load) begin
min2_rg <= 4'b0100;
end
else
begin
if (tc3)
begin
if (min2_rg == 4'b0101) begin
min2_rg <= 4'b0000;
end
else
begin
min2_rg <= min2_rg + 1;
end
end
end
end
assign min2 = min2_rg;
//---------------------tc4 signal to start hr1 counter--------------------------
assign tc4 = (min2_rg == 4'b0101) && (tc3 == 1);
//--************************ Hour_cntr1 *************************
always@(posedge clock or posedge reset)
begin
if (reset)
hr1_rg <= 4'b0000;
else if (load) begin
hr1_rg <= 4'b0001;
end
else
begin
if (tc6)
begin
hr1_rg <= 4'b0000;
end
else
begin
if (tc4)
begin
if (hr1_rg == 4'b1001) begin
hr1_rg <= 4'b0000;
end
110
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
else
begin
hr1_rg <= hr1_rg + 1;
end
end
end
end
end
assign hr1 = hr1_rg;
//---------------------tc5 signal to start hr2 counter--------------------------
assign tc5 = (hr1_rg == 4'b1001) && (tc4 == 1);
//------------------------tc6 signal to reset at
23:59:59--------------------------
assign tc6 = (hr2_rg == 4'b0010) && (hr1_rg == 4'b0011) && (tc4 == 1);
//--************************ Hour_cntr2 *************************
always@(posedge clock or posedge reset)
begin
if (reset)
hr2_rg <= 4'b0000;
else if (load) begin
hr2_rg <= 4'b0000;
end
else
begin
if (tc6)
begin
hr2_rg <= 4'b0000;
end
else
begin
if (tc5)
begin
if (hr2_rg == 4'b0010) begin
hr2_rg <= 4'b0000;
end
else
begin
hr2_rg <= hr2_rg + 1;
end
end
end
end
end
assign hr2 = hr2_rg;
always@(posedge pulsegen[9] or posedge reset)
begin
if (reset)
cnk2 <= 3'b0;
else
begin
if (cnk2 == 3'b101)
cnk2 <= 3'b0 ;
111
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
else
cnk2 <= cnk2 + 1;
end
end
always@(cnk2)
case (cnk2)
3'b000 : mout <= sec1;
3'b001 : mout <= sec2;
3'b010 : mout <= min1;
3'b011 : mout <= min2;
3'b100 : mout <= hr1;
3'b101 : mout <= hr2;
endcase
always@(mout)
case (mout)
4'b0000 : sgout_rg <= 8'b11000000;
4'b0001 : sgout_rg <= 8'b11111001;
4'b0010 : sgout_rg <= 8'b10100100;
4'b0011 : sgout_rg <= 8'b10110000;
4'b0100 : sgout_rg <= 8'b10011001;
4'b0101 : sgout_rg <= 8'b10010010;
4'b0110 : sgout_rg <= 8'b10000010;
4'b0111 : sgout_rg <= 8'b11111000;
4'b1000 : sgout_rg <= 8'b10000000;
4'b1001 : sgout_rg <= 8'b10011000;
endcase
always@(cnk2)
case (cnk2)
3'b000 : dis_sig <= 6'b111110;
3'b001 : dis_sig <= 6'b111101;
3'b010 : dis_sig <= 6'b111011;
3'b011 : dis_sig <= 6'b110111;
3'b100 : dis_sig <= 6'b101111;
3'b101 : dis_sig <= 6'b011111;
endcase
assign sgout = ~ sgout_rg;
assign dis = ~ dis_sig;
endmodule
112
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
113
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE
Compiled by ECE Department Faculties of K.L.N. College of Engineering
module circuit(A,B,C,D,F)
input A,B,C,D;
output F;
wire w,x,y,z,a,d;
and (x,B,C,d);
and (y,a,C);
and (w,z,B);
or (z,y,A);
or (F,x,w);
not (a,A);
not (d,D);
endmodule
Processes
1) Simulation
2) Synthesis
3) Placing & Routing
4) Back-annotation
5) Schematic
6) Downloading in FPGA
PART-B:
1. Briefly explain the Simulation diagram (Functional, Transport Delay, Gate Delay,
Inertial Delay).
2. Briefly explain the Synthesis diagram& various Synthesis Software Name.
3. Briefly explain the Place & Route and back annotation diagram.
4. Briefly explain the FPGA Schematic Entry with diagram.
5. Briefly explain the Physical Layout using CAD Tools.
6. Briefly explain about the transistor level circuit design with CAD example.
114
Mr.N.Janakiraman M.E.,M.B.A.,I.T.I.L.,M.I.S.T.E., (A.C.S.,) S.G.L./ECE Ms.R.ThivyaPrabha M.E.,L/ECE