sp3im lab manual vhdl

69
LAB MANUAL FOR SPARTAN-3 INTERFACING MODULE MODEL : MXS3FK-PQ208-IM Rev : 003 MECHATRONICS TEST EQUIPMENT (I) PVT.LTD. B-3,MAYUR COMPLEX, OPP. BHELKE NAGAR, NEAR YASHAVANTRAO CHAVAN NATYAGRUH, KOTHRUD, PUNE- 411038 PHONE : +91-20-25386926 FAX : +91-20-25386930 EMAIL : [email protected] URL : www.mte-india.com

Upload: zahida-perveen

Post on 09-Mar-2015

72 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Sp3im Lab Manual Vhdl

LAB MANUAL

FOR

SPARTAN-3 INTERFACING MODULE MODEL : MXS3FK-PQ208-IM

Rev : 003

MECHATRONICS TEST EQUIPMENT (I)PVT.LTD. B-3,MAYUR COMPLEX, OPP. BHELKE NAGAR,

NEAR YASHAVANTRAO CHAVAN NATYAGRUH, KOTHRUD, PUNE- 411038

PHONE : +91-20-25386926 FAX : +91-20-25386930 EMAIL : [email protected] URL : www.mte-india.com

Page 2: Sp3im Lab Manual Vhdl

Table of contents

PREFACE......................................................................................................................................... 1ABOUT THIS MANUAL ................................................................................................................. 1

MANUAL CONTENTS ................................................................................................................ 1

CHAPTER 1...................................................................................................................................... 2STUDY OF SIMULATION TOOLS ................................................................................................. 2

1.1SIMULATION USING XILINX HDL BENCHER ..................................................................... 2 1.2 SIMULATION USING MODELSIM SIMULATOR ............................................................... 11

CHAPTER 2.................................................................................................................................... 16STUDY OF SYNTHESIS TOOLS ................................................................................................ 16

CHAPTER 3.................................................................................................................................... 23PLACE AND ROUTE AND BACK ANNOTATION FOR FPGA .................................................... 23

CHAPTER 4.................................................................................................................................... 26STUDY OF DEVELOPMENT TOOL FOR FPGA FOR SCHEMATIC ENTRY ............................. 26

CHAPTER 5.................................................................................................................................... 32TRAFFIC LIGHT CONTROLLER USING FPGA .......................................................................... 32

5.1 DESIGN DESCRIPTION:- .................................................................................................. 32 5.2 EXPERIMENTAL SET UP:- ................................................................................................ 35 5.3 COMPONENT DIAGRAM – .............................................................................................. 36

CHAPTER 6.................................................................................................................................... 45DESIGN AND SIMULATION OF PIPELINED SERIAL AND PARALLEL ADDER ....................... 45

6.1 DESIGN DESCRIPTION:- .................................................................................................. 45 6.2 PROCEDURE:- .................................................................................................................. 46 6.3 VHDL CODE FOR RIPPLE CARRY ADDER ..................................................................... 48

CHAPTER 7.................................................................................................................................... 49DESIGN AND SIMULATION OF SIGNED 8 BIT MULTIPLIER ................................................... 49

7.1 DESIGN DESCRIPTION:- .................................................................................................. 49 7.2 PROCEDURE:- .................................................................................................................. 50

CHAPTER 8.................................................................................................................................... 52STUDY OF FPGA BOARD AND TESTING ON BOARD LED AND SWITCHES ......................... 52

8.1 DIP SWITCHES ................................................................................................................ 52 8.2 KEY SWITCHES ................................................................................................................ 52 8.3 LEDS .................................................................................................................................. 52 8.4 VHDL CODE FOR LEDS AND SWITCHES ....................................................................... 52

CHAPTER 9.................................................................................................................................... 55TESTING THE TRAFFIC CONTROLLER DESIGN ON THE FPGA BOARD .............................. 55

Page 3: Sp3im Lab Manual Vhdl

CHAPTER 10.................................................................................................................................. 61REAL CLOCK TIMER .................................................................................................................. 61

10.1 DESCRIPTION FOR REAL CLOCK TIMER ..................................................................... 61 10.2 VHDL CODE FOR REAL CLOCK TIMER ........................................................................ 61

Page 4: Sp3im Lab Manual Vhdl

PREFACE

About This ManualManual ContentsThis manual contains following chapters:• Chapter 1, “Study of Simulation using tools ”• Chapter 2, “Study of Synthesis tools ” • Chapter 3, “Place and Root and Back annotation for FPGAs ”• Chapter 4, “Study of development tool for FPGAs for schematic entry and vhdl ”• Chapter 5, “Design of traffic light controller using vhdl and above tools ”• Chapter 6, “Design and simulation of pipelined serial and parallel adder ” • Chapter 7, “ Design and Simulation of Signed 8 bit Multiplier ” • Chapter 8, ” Study of FPGA board and testing on board LEDs and switches ”• Chapter 9, ” Testing the traffic controller design on the FPGA board ” • Chapter 10, “Design a Real Time Clock and its working on the FPGA board ”

1

Page 5: Sp3im Lab Manual Vhdl

CHAPTER 1

Study of Simulation Tools

Simulation is functional emulation of the circuit design through software programs that uses models to replicate how a system will perform in terms of timings and results.

Xilinx ISE tool supports the following simulation tools:• HDL Bencher is an automated test bench creation tool. It is fully integrated with Project

Navigator.• ModelSim from Model Technology, Inc, is integrated in Project Navigator to simulate the design

at all steps (Functional and Timing). ModelSim XE, the Xilinx Edition of Model Technology, Inc.’s ModelSim application, can be installed from the MTE CD included in your ISE Tool

1.1 Simulation using Xilinx HDL Bencher[[

Step1: Start the Xilinx Project Navigator by using the desktop shortcut or by using the Start Programs Xilinx ISE (8.2i).

2

PROCESSWINDOW

WORK SPACE

SOURCE

WINDOW

TRANSCRIPT

Page 6: Sp3im Lab Manual Vhdl

Step2: Create a new projectSelect File menu and then select New project.

Specify the project name and location in pop up window and click NEXT

Select Device. Select the required family, device, package, speed grade, Synthesis tool Simulator from new project wizard pop up window. Click NEXT. Project summary will be displayed.

3

Page 7: Sp3im Lab Manual Vhdl

Click FINISH to start Project.

4

Page 8: Sp3im Lab Manual Vhdl

Step 3: To create new VHD file Right click on the device name and select NEW SOURCE

Select VHDL MODULE in NEW SOURCE WIZARD and give suitable name for the Project. Click NEXT for the DEFINE MODULE Window.

Assign required ports in this Window. The direction

5

VHDLMODUL

Page 9: Sp3im Lab Manual Vhdl

6

Page 10: Sp3im Lab Manual Vhdl

Step 4: Write the Behavioural VHDL Code in VHDL EditorSample code is given below for this experiment.

7

Page 11: Sp3im Lab Manual Vhdl

Step 5: SIMULATION using ISE toolCreating a test bench fileVerify the operation of your design before you implement it as hardware. Simulation can be done using ISE simulator. For this click on the symbol of FPGA device and then right click Click on new source Test Bench Waveform and give the name Select entityFinish.

The window to Select Clock, Duty Cycle will appear. Select required parameters and say FINISH

8

Page 12: Sp3im Lab Manual Vhdl

Step 6: BEHAVIOURAL SIMULATIONSelect Behavioural Simulation from the scroll down list.

9

Page 13: Sp3im Lab Manual Vhdl

Step 7: Give wave pattern on the input signals as required. Then double click on Simulate Behavioural Model for simulating.

The wave form according to the inputs given will appear in the window. The wave form can be analysed for the correctness of functionality.

10

Page 14: Sp3im Lab Manual Vhdl

1.2 Simulation Using Modelsim SimulatorStep 1: Repeat the steps for creating a design as in ISE HDL Bencher flowStep 2: Click on the device name and go to properties. Select ModelSim VHDL in that.

Step 3: Click on the device name and go to properties. Select ModelSim VHDL in that.

11

Page 15: Sp3im Lab Manual Vhdl

Step 4: Select Behavioural Simulation from the scroll down list. Double click on Simulate Behavioural Model to open Model Sim Simulator.

Step 5:

12

Page 16: Sp3im Lab Manual Vhdl

Step 6: Enlarged view of waveform.

Step 7: POST TRANSLATE SIMULATIONSimilarly select Post-Translate Simulation and run Model Sim. The observed waveform is given below. The delay after Translating Behavioural Model to RTL Model can be observed.

13

Page 17: Sp3im Lab Manual Vhdl

Step 8: POST MAP SIMULATIONSimilarly select Post-MAP Simulation and run Model Sim. The observed waveform is given below. The Post Map Simulation shows the delay in output after mapping the signals into FPGA.

14

Page 18: Sp3im Lab Manual Vhdl

Step 9: POST ROUTE SIMULATIONSimilarly select Post-Route Simulation and run Model Sim. The Post Route Simulation shows the delay in output after Routing all the signals in FPGA, including Global Clock. This will be the maximum delay for getting the output. The observed waveform is given below.

15

Page 19: Sp3im Lab Manual Vhdl

CHAPTER 2

Study of Synthesis ToolsSynthesis describes the process of transformation of the model of a design, from one level of abstraction in one domain [say HDL] to a lower level of abstraction in same or other domain.

Step 1: Start the Xilinx Project Navigator by using the desktop shortcut or by using the Start Programs Xilinx ISE (8.2i).

16

PROCESSWINDOW

WORK SPACE

SOURCE

WINDOW

TRANSCRIPT

Page 20: Sp3im Lab Manual Vhdl

Step 2: Create a new projectIn the window go to FILE New project.

Specify the project name and location on window that appears and say NEXT

Select Device. Select the device, package and speed needed from choice given. Click in the field to access the pull-down list.The Simulator we like to select can be selected here.Click NEXT for next option.

17

Page 21: Sp3im Lab Manual Vhdl

The Project Summary is displayed and we can verify it.

Say FINISH to start Project.

18

Page 22: Sp3im Lab Manual Vhdl

Step 3: To create new VHD file Right click on the device name and select NEW SOURCE

Select VHDL MODULE in NEW SOURCE WIZARD and give suitable name for the Project. Click NEXT for the DEFINE MODULE Window.

Assign required ports in this Window. The direction

19

VHDLMODUL

Page 23: Sp3im Lab Manual Vhdl

Step 4: Write the Behavioural VHDL Code in VHDL EditorSample code is given below for this experiment.

20

Page 24: Sp3im Lab Manual Vhdl

Check SyntaxRun the Check syntax Process window synthesizecheck syntax >, and remove errors if present

Step 5: Synthesize the design using XST.Translate your design into gates and optimize it for the target architecture. This is the synthesis phase.Again for synthesizing your design, from the source window selects synthesis/Implementation from the drop-down menu.

Highlight file in the Sources in Project window. To run synthesis, right-click on Synthesize, and the Run option, or double-click on Synthesize in the Processes for Current Source window. Synthesis will run, and

• a green check will appear next to Synthesize when it is successfully completed.

• a red cross indicates an error was generated and a yellow exclamation ! mark indicates that a warning was generated.Check the synthesis report. If there are any errors correct it and rerun synthesis

21

SYNTHESIS

Page 25: Sp3im Lab Manual Vhdl

22

SYNTHESIS COMPLETED

SUCCESSFULL

Page 26: Sp3im Lab Manual Vhdl

CHAPTER 3

Place and Route and Back Annotation for FPGA

Back annotation is the translation of a routed or fitted design to a timing simulation netlist.

To define the behavior of the FPGA, a hardware description language (HDL) or a schematic design methods are used. Common HDLs are VHDL and Verilog. Then, using an electronic design automation tool, a technology-mapped netlist is generated. The netlist can then be fitted to the actual FPGA architecture using a process called place-and-route, usually performed by the FPGA Company’s proprietary place-and-route software. The user will validate the map, place and route results via timing analysis, simulation, and other verification methodologies. Once the design and validation process is complete, the binary file generated and is used to (re)configure the FPGA.In an attempt to reduce the complexity of designing in HDLs, which have been compared to the equivalent of assembly languages, there are moves to raise the abstraction level of the design.

To simplify the design of complex systems in FPGAs, there exist libraries of predefined complex functions and circuits that have been tested and optimized to speed up the design process. These predefined circuits are commonly called IP cores, and are available from FPGA vendors and third-party IP suppliers.

In a typical design flow, an FPGA application developer will simulate the design at multiple stages throughout the design process. Initially the RTL description in VHDL or Verilog is simulated by creating test benches to simulate the system and observe results. Then, after the synthesis engine has mapped the design to a netlist, the netlist is translated to a gate level description where simulation is repeated to confirm the synthesis proceeded without errors. Finally the design is laid out in the FPGA at which point propagation delays can be added and the simulation run again with these values back-annotated onto the netlist.

23

Page 27: Sp3im Lab Manual Vhdl

After Synthesis, go to back annotate pin location in Implement Design and double click to start back annotation.

In back annotation the tool translates and routes the logic in FPGA and generates the constraint file such that minimum delay paths are included. This helps to make the design faster.

24

Page 28: Sp3im Lab Manual Vhdl

Once back annotation is completed, constraint file is generated.

25

Page 29: Sp3im Lab Manual Vhdl

CHAPTER 4

Study of Development Tool for FPGA for Schematic Entry

This topic gives the overview of schematic entry using ISE .The steps to generate a full adder is given in this chapter. We generate Truth Table for the required functionality. Solve the Equation and we get the gates required to implement the design.

1. Full Adder Truth Table

Input OutputC A B S C0 0 0 0 01 0 0 1 00 1 0 1 01 1 0 0 10 0 1 1 01 0 1 0 10 1 1 0 11 1 1 1 1

2. Solving Equation

S = A*B*C + AB*C* + A*BC* + ABC= (A XOR B) XOR C

C1 = AB*C + ABC + ABC* + ABC= AB + (A XOR B) C

Once the schematic is finalised we can enter it to FPGA schematic editor and the steps are given below.

26

Page 30: Sp3im Lab Manual Vhdl

Step 1: Select SCHEMATIC from new source and assign name to the file.

Step 2: From the Sources select LOGIC and from symbols we can pick and drop any gates we need. Selection of XOR gate is shown below.

Step 3: Once the component is selected, for providing connection to other components or

27

Page 31: Sp3im Lab Manual Vhdl

external input, we can use ADD WIRE option, as shown below.

For Assigning Entity, ie input or output signals, we can use ADD I/O MARKER

28

ADD WIRE

ADD I/O MARKER

Page 32: Sp3im Lab Manual Vhdl

Double Click on the IO Marker and in the Pop up window assign name for the Signal.

29

Page 33: Sp3im Lab Manual Vhdl

Step 4: The Completed Schematics is given below

30

Page 34: Sp3im Lab Manual Vhdl

Step 5: After the schematic entry is completed go to the SOURCES and SYNTHESIS the design.

To view the VHF file generated Clock on View HDL functional model in design utilities

31

Page 35: Sp3im Lab Manual Vhdl

CHAPTER 5

Traffic Light Controller using FPGA

Traffic Light controller is implemented on FPGA and verified using Traffic Light Interface Module.There are simple rules for traffic lights on one node, and complex ways of regulating a whole infrastructure of them. It is necessary to adjust general algorithms

5.1 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:-

32

Page 36: Sp3im Lab Manual Vhdl

To implement Traffic Light controller refer the waveform given below

Algorithm is implemented in VHDL with a 13 state Finite State Machine. Refer Fig Below.

Figure 1: State Diagram for Traffic Light Controller

33

Page 37: Sp3im Lab Manual Vhdl

Abbreviation used:-South West

PSG – Pedestrian South Green PWR – Pedestrian West RedPSR – Pedestrian South Red PWG – Pedestrian West GreenRS – Right South RW – Right WestLS – Left South LW – Left WestSS – Straight South SW – South WestYS – Yellow South YW – Yellow WestREDS – Red South REDW – Red West

North EastPNR- Pedestrian North red PEG – Pedestrian East greenPNG – Pedestrian North green PER – Pedestrian Ease RedRN – Right North RE – Right EastLN – Left North LE – Left EastSN – Straight North SE – Straight East YN - Yellow North YE – Yellow EastREDN – Red North REDE – Red East

34

Page 38: Sp3im Lab Manual Vhdl

5.2 Experimental Set up:-

Figure 2: Traffic Light Interface to SPARTAN-3 FPGA

35

Page 39: Sp3im Lab Manual Vhdl

5.3 Component Diagram –

CONCLUSION:-Design of “Traffic Light Controller” is implemented on FPGA and is verified using Traffic Light Interface Module according to the following Algorithm.

36

Page 40: Sp3im Lab Manual Vhdl

5.4 VHDL Code for Traffic Light Controllerlibrary IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating---- any Xilinx primitives in this code.---- library UNISIM;---- use UNISIM.VComponents.all;

entity traffic_fsm is Port ( clk,rst : in std_logic;

ls,lw,ln,le: out std_logic;ss,sw,sn,se : out std_logic;rs,rw,rn,re : out std_logic;red_s,red_w,red_n,red_e : out std_logic;

ys,yw,yn,ye : out std_logic;ps_r,pw_r,pn_r,pe_r : out std_logic;ps_g,pw_g,pn_g,pe_g : out std_logic);

end traffic_fsm;

architecture Behavioral of traffic_fsm istype state is (start,south_g,south_orange,south_r,west_g,west_orange, west_r,east_g,east_orange,east_r,north_g,north_orange,north_r);signal ps , ns : state;signal div : std_logic_vector(30 downto 0);signal clk_s : std_logic;signal cnt : std_logic_vector(3 downto 0) ;beginprocess(clk,rst)begin

if(rst = '1') thendiv <= (others => '0');

elsif(clk'event and clk = '1') thendiv <= div + 1;

end if;end process;clk_s <= div(21);

process(clk_s ,rst)begin

if(rst = '1') thencnt <= (others => '0');

elsif(clk_s'event and clk_s = '0') thencnt <= cnt + 1;

end if;end process;

process(clk_s,rst)begin

if (rst = '1')thenps <= start;

elsif(clk_s'event and clk_s = '1') thenps <= ns;

end if;end process;

37

Page 41: Sp3im Lab Manual Vhdl

process(ps)begin

case ps is when start => ns <= south_g;when south_g =>

if(cnt = 10)thenns <= south_orange;

elsens <= south_g;

end if;

when south_orange => if(cnt = 14) then

ns <= south_r;else

ns <= south_orange;end if;

when south_r => if(cnt = 15)then

ns <= west_g;else

ns <= south_r;end if;

when west_g => if(cnt = 10) then

ns <= west_orange;else

ns <= west_g;end if;

when west_orange =>if(cnt = 14) then

ns <= west_r;else

ns <= west_orange;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

38

Page 42: Sp3im Lab Manual Vhdl

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

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';

39

Page 43: Sp3im Lab Manual Vhdl

pe_r <= '0';

case ps iswhen start =>

red_s <= '1'; red_w <= '1'; red_n <= '1'; red_e <= '1';

when south_g => ls <= '1'; rs <= '1'; ss <= '1'; le <= '1'; red_w <= '1'; red_n <= '1'; red_e <= '1'; ps_r <= '1'; pw_r <= '1'; pn_r <= '1'; pe_r <= '1';

when south_orange => pn_g <= '1'; le <= '1'; ls <= '1'; ys <= '1'; red_w <= '1'; red_n <= '1'; red_e <= '1'; ps_r <= '1'; pw_r <= '1'; pe_r <= '1';

when south_r => ls <= '1'; red_w <= '1'; red_n <= '1'; red_e <= '1'; ps_r <= '1'; pw_r <= '1'; pn_r <= '1'; pe_r <= '1';

when west_g => lw <= '1'; ls <= '1'; rw <= '1'; sw <= '1'; red_s <= '1'; red_n <= '1'; red_e <= '1'; ps_r <= '1'; pw_r <= '1'; pn_r <= '1'; pe_r <= '1';

when west_orange => lw <= '1'; ls <= '1'; pe_g <= '1';

40

Page 44: Sp3im Lab Manual Vhdl

yw <= '1'; red_s <= '1'; red_n <= '1'; red_e <= '1'; ps_r <= '1'; pw_r <= '1'; pn_r <= '1';

when west_r => lw <= '1'; red_s <= '1'; red_n <= '1'; red_e <= '1'; ps_r <= '1'; pw_r <= '1'; pn_r <= '1'; pe_r <= '1';

when north_g =>ln <= '1';rn <= '1';sn <= '1';lw <= '1';red_s <= '1'; red_w < = '1';red_e <= '1';ps_r <= '1';pw_r <= '1';pn_r <= '1';pe_r <= '1';

when north_orange =>ln <= '1';lw <= '1';ps_g <= '1';yn <= '1';red_s <= '1'; red_w <= '1';red_e <= '1';pw_r <= '1';pn_r <= '1';pe_r <= '1';

when north_r =>ln <= '1';red_s <= '1'; red_w <= '1';red_e <= '1';ps_r <= '1';pw_r <= '1';pn_r <= '1';pe_r <= '1';

when east_g => re <= '1';se <= '1';le <= '1';ln <= '1';red_s <= '1'; red_w <= '1';

41

Page 45: Sp3im Lab Manual Vhdl

red_n <= '1';ps_r <= '1';pw_r <= '1';pn_r <= '1';pe_r <= '1';

when east_orange =>ln <= '1';le <= '1'; pw_g <= '1';ye <= '1';red_s <= '1'; red_w <= '1';red_n <= '1';ps_r <= '1';pn_r <= '1';pe_r <= '1';

when east_r => le <= '1';

red_s <= '1'; red_w <= '1';red_n <= '1';ps_r <= '1';pw_r <= '1';pn_r <= '1';pe_r <= '1';

when others => 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';

end case;

42

Page 46: Sp3im Lab Manual Vhdl

end process;end Behavioral;

43

Page 47: Sp3im Lab Manual Vhdl

--******************************************************Description of above Code:-To Start the Traffic light controller 1. Initially the Red light of all the directions is ON.2. Traffic starts from the South Direction; hence the green light of South direction goes ON.

The signals that are ON, now are :- ls ( left south ) –‘1’. rs ( right south ) –‘1’. ss ( straight south ) –‘1’. le ( left east ) –‘1’. red_w ( red west ) –‘1’. red_n (red north ) –‘1’. red_e (red east ) –‘1’. ps_r ( pedestrian south red) –‘1’. pw_r ( pedestrian west red) –‘1’. pn_r ( pedestrian north red) –‘1’. pe_r ( pedestrian east red) –‘1’.

Similarly when Orange light of South direction is ON then the signals that are ON, now are ls ( left south ) –‘1’. ys ( yellow south ) –‘1’. le ( left east ) –‘1’. red_w ( red west ) –‘1’. red_n (red north ) –‘1’. red_e (red east ) –‘1’. ps_r ( pedestrian south red) –‘1’. pw_r ( pedestrian west red) –‘1’. pn_r ( pedestrian north red) –‘1’. pe_r ( pedestrian east red) –‘1’.

Similarly when Red light of South direction is ON then the signals that are ON, now are ls ( left south ) –‘1’. red_w ( red west ) –‘1’. red_n (red north ) –‘1’. red_e (red east ) –‘1’. ps_r ( pedestrian south red) –‘1’. pw_r ( pedestrian west red) –‘1’. pn_r ( pedestrian north red) –‘1’. pe_r ( 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.

44

Page 48: Sp3im Lab Manual Vhdl

CHAPTER 6

Design and Simulation of Pipelined Serial and Parallel Adder

6.1 Design Description:-The ripple carry adder is the basis of any other adder structures since it is simply composed of n-bit full adders that are connected in series. The functionality of a full adder can easily be obtained from its truth table, shown in Figure 6. (a), and from which we have the full adder gate level logic functions. For an n-bit ripple carry adder, the block diagram is shown below in Figure 6 (b)

A

B

C IN+SUMCOUT

A B CIN Sum

0

0

0

0

1

1

1

1

0

0

1

1

0

0

1

1

0

1

0

1

0

1

0

1

0

1

1

0

1

0

0

1

0

0

0

1

0

1

1

1

COUT

Sum = A + B + CIN

Cout = A.B + A.CIN + B.CIN

Figure 6(a)

45

COUT +

AB

CIN

SUM

Page 49: Sp3im Lab Manual Vhdl

C0C1 FA

A0B0

S0

C2 FA

S1

C3 FA

S2

Cn FA

Sn

A1A2An B1B2Bn

Figure 6(b) n-bit Ripple Carry Adder (RCA)

6.2 Procedure:-Step 1: Start the Xilinx Project Navigator by using the desktop shortcut or by using the

Start Programs Xilinx ISE Project Navigator.

Step 2: In the Project Navigator window go on FILE New projectSelect Device.

Step 3: Click on symbol of FPGA device and then right click Click on new source Verilog module and give name signed8bitDefine portsFinish.

Step 4: Generate the Behavioral Verilog Code for the multiplier.Check syntax, and remove errors if present. Synthesize the design using XST.Highlight vhd file in the Sources in Project window. To run synthesis, right-click on Synthesize, and choose the Run option, or double-click on Synthesize in the Processes for Current Source window. Synthesis will run, and a green check will appear next to Synthesize when it is successfully completed. A yellow exclamation mark indicates that a warning was generated, and a red cross

46

Page 50: Sp3im Lab Manual Vhdl

indicates an error was generated. Warnings are OK.

If there are any errors, you can View Synthesis Report by expanding Synthesis, right-click and choose the View option, otherwise continue on to the next step.

Step 5: Write User Constraint file wherein the FPGA pins are locked as per the Spartan-II hardware. Running the Xilinx Implementation Tools.Once synthesis is complete, you can place and route your design to fit into a Xilinx device (Spartan2 200k), and you can also get some post place-and-route timing information about the design. This procedure runs you through the basic flow for implementation.

Right-click on Implement Design, and choose the Run option, or double left-click on Implement Design. Right-click on Generate Programming File, and choose the Run option, or double left-click on Generate Programming File. This will generate the Bitstream. Double click on Configure Device to download the bitstream.The output can be observed on the output LEDs.

47

Page 51: Sp3im Lab Manual Vhdl

6.3 VHDL Code for Ripple Carry Adder

**************************************************-- * Pipelined adder structures-- * parameterized pipelining stage-- * ripple carry adder-- **************************************************library ieee;use ieee.std_logic_1164.all;use work.iscas1.all;use work.par_pkg.all;use work.DFF.all;entity pipeline_rca isport( signal clock : in std_logic;a,b : in std_logic_vector(bit_width-1 downto 0);cin : in std_logic;sum : out std_logic_vector(bit_width-1 downto 0);cout : out std_logic);end pipeline_rca;architecture structural of pipeline_rca istype IARRAY is array (natural range <>) of integer;beginprocess(clock,a,b,cin)variable low_index, high_index, index : integer;variable temp_sum : std_logic_vector(sum’range);variable temp_cout, temp_cin, regout: std_logic;constant p_level : iarray(0 to 1) :=(4,4);begintemp_cin := cin;low_index := 0;if (clock’event and clock = ’1’) thenfor i in p_level’low to p_level’high loopindex := p_level(i);high_index := (index-1)+low_index;ripple_adder(a(high_index downto low_index), b(high_index downto low_index), temp_cin,temp_sum(high_index downto low_index), temp_cout);reg(clock, temp_cout, regout);low_index := high_index + 1;temp_cin := regout;end loop;sum <= temp_sum;cout<= temp_cout;end if;end process;end structural;

48

Page 52: Sp3im Lab Manual Vhdl

CHAPTER 7

Design and Simulation of Signed 8 bit Multiplier

7.1 Design Description:-Booth’s algorithm is implemented for multiplying two signed 8-bit numbers.The easiest solution to signed multiplication is to make both the numbers positive and then complement the product.

Current Bit Previous Bit

ACTION

0 0 No Arithmetic operation0 1 Add multiplicand to the left half of the product1 0 Subtract multiplicand from left half of the product1 1 No Arithmetic operation

Shift right after each operation.Assume that there is a 0 bit at the right of LSB.

Multiply 2 X (- 3) i.e. 0010 X 1101

Iteration Step Multiplicand Product0 0010 0000110101 (10) Prod = Prod – Mcand 0010 111011010

Shift right Prod 0010 1111011012 (01) Prod = Prod + Mcand 0010 000101101

Shift right Prod 0010 0000101103 (10) Prod = Prod – Mcand 0010 111010110

Shift right Prod 0010 1111010114 (11) No operation 0010 111101011

Shift right Prod 0010 111110101

49

Page 53: Sp3im Lab Manual Vhdl

7.2 Procedure:-Step 1: Start the Xilinx Project Navigator by using the desktop shortcut or by using the

Start Programs Xilinx ISE Project Navigator.

Step 2: In the Project Navigator window go on FILE New projectSelect Device.

Step 3: Click on symbol of FPGA device and then right click Click on new source Verilog module and give name signed8bitDefine portsFinish.

Step 4: Generate the Behavioral Verilog Code for the multiplier.Check syntax, and remove errors if present. Synthesize the design using XST.Highlight signed8bit.v file in the Sources in Project window. To run synthesis, right-click on Synthesize, and choose the Run option, or double-click on Synthesize in the Processes for Current Source window. Synthesis will run, and a green check will appear next to Synthesize when it is successfully completed. A yellow exclamation mark indicates that a warning was generated, and a red cross indicates an error was generated. Warnings are OK.

50

Page 54: Sp3im Lab Manual Vhdl

If there are any errors, you can View Synthesis Report by expanding Synthesis, right-click and choose the View option, otherwise continue on to the next step.

Step 5: Write User Constraint file wherein the FPGA pins are locked as per the Spartan-II hardware. Running the Xilinx Implementation Tools.Once synthesis is complete, you can place and route your design to fit into a Xilinx device (Spartan2 200k), and you can also get some post place-and-route timing information about the design. This procedure runs you through the basic flow for implementation.

Right-click on Implement Design, and choose the Run option, or double left-click on Implement Design.Right-click on Generate Programming File, and choose the Run option, or double left-click on Generate Programming File. This will generate the Bitstream. Double click on Configure Device to download the bitstream.The output can be observed on the output LEDs.

51

Page 55: Sp3im Lab Manual Vhdl

CHAPTER 8

Study of FPGA Board and Testing on Board LED and Switches8.1 DIP Switches The switches connect to an associated FPGA. The switches are used to give input to the FPGA or the design implemented on FPGA. A 4.7KΩ series resistor provides nominal input protection.

When in the UP or ON position, a switch connects the FPGA pin to VCCO, a logic High. When DOWN or in the OFF position, the switch connects the FPGA pin to ground, a logic Low. The switches typically exhibit about 2 ms of mechanical bounce and there is no active debouncing circuitry, although such circuitry could easily be added to the FPGA design programmed on the board.

8.2 Key SwitchesThe Key switches can provide pulse input to the FPGA. The switches connect to an associated FPGA pin. Pressing a key generates logic High on the associated FPGA pin. There is no active debouncing circuitry on the key switches.

8.3 LEDSTest LEDs are provided for mapping output of FPGA or tracking particular stage in the design. A series current limiting resistor of 270Ω is associated with every LED. To light an individual LED, drive the associated FPGA control signal High

8.4 VHDL Code for LEDs and Switches

Library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity keydis isPort ( rst : in std_logic; Clock : in std_logic;

-- keyboard return and scan lines ret_lin : in std_logic_vector(3 downto 0); scan_lin : out std_logic_vector(3 downto 0);

-- display i/os segments and display selects segments : out std_logic_vector(7 downto 0); dis_sel : out std_logic_vector(5 downto 0);

-- Input switches and output leds IL : in std_logic_vector(15 downto 0); OL : out std_logic_vector(15 downto 0) );end keydis;---------------------------------------------------------------architecture Behavioral of keydis is---------------------------------------------------------------signal Divider : std_logic_vector(20 downto 0);signal SClock, DClock, ORed, Interrupt : std_logic;signal Scan, Decoded : std_logic_vector(1 downto 0);

52

Page 56: Sp3im Lab Manual Vhdl

signal SL_S,D,Display_s : std_logic_vector(3 downto 0);signal segments_s : std_logic_vector(7 downto 0);

----------------------------------------begin---------Clock Divider----------process(rst, Clock)begin if(rst = '1')then Divider <= (others=>'0'); elsif(Clock'event and Clock = '1')then Divider <= Divider + 1; end if;end process;-----------------Scan & Debounce clock--------------SClock <= Divider(14);DClock <= Divider(11);------------------Scan Counter----------------------process(SClock, Rst)begin if(Rst = '1')then Scan <= (others=>'0'); elsif(SClock'event and SClock='1')then Scan <= Scan + 1; end if;end process;

SL_S <= "0111" when Scan = "00" else "1011" when Scan = "01" else "1101" when Scan = "10" else "1110" ;

scan_lin <= SL_S;

ORed <= (not ret_lin(0)) or (not ret_lin(1)) or (not ret_lin(2)) or (not ret_lin(3));

process(Rst,DClock)begin if(Rst = '1')then D <=(others => '0'); elsif(DClock'event and DClock = '1')then D <= D(2 downto 0) & ORed; end if;end process;

Interrupt <= '1' when(D = "1111")else '0';

Decoded <= "00" when (ret_lin = "0111") else "01" when (ret_lin = "1011") else "10" when (ret_lin = "1101") else "11";

process(Interrupt, Rst)begin if(Rst = '1')then

53

Page 57: Sp3im Lab Manual Vhdl

Display_s <= (others=>'0'); elsif(Interrupt'event and Interrupt = '1')then Display_s <= Scan & Decoded; end if;end process;----------------------------------------------------------------- .a.-- f| |b-- .g. -- e| |c-- .d.

-- dphgfedcbaSegments_s <= "01000000" when Display_s ="0000" else --0

"01111001" when Display_s ="0001" else --1 "00100100" when Display_s ="0010" else --2 "00110000" when Display_s ="0011" else --3 "00011001" when Display_s ="0100" else --4 "00010010" when Display_s ="0101" else --5 "00000010" when Display_s ="0110" else --6 "01111000" when Display_s ="0111" else --7 "00000000" when Display_s ="1000" else --8

"00010000" when Display_s ="1001" else --9

"00001000" when Display_s ="1010" else --A"00000011" when Display_s ="1011" else --B"01000110" when Display_s ="1100" else --C"00100001" when Display_s ="1101" else --D"00000110" when Display_s ="1110" else --E"00001110" when Display_s ="1111" else --F"01000000";

Segments <= segments_s;

dis_sel <= (others=>'0');-- test input switches and output ledsOL <= IL;end Behavioral;

54

Page 58: Sp3im Lab Manual Vhdl

CHAPTER 9

Testing the Traffic Controller design on the FPGA board

The VHDL code for traffic Controller is as given in Chapter 5. Follow the steps given in chapter two and synthesis the design. Once design is synthesized successfully it is ready to be implemented on FPGA.

Step 1: The first step for implementation is to generate constraint file. The constraint file specifies the FPGA pins used for accessing the design.

55

Page 59: Sp3im Lab Manual Vhdl

Step 2: To create new UCF file. Right click on the device name and select NEW SOURCE. Select IMPLEMENTATION CONSTRAINT FILE in NEW SOURCE WIZARD and give suitable name for the Project. Click NEXT for the DEFINE MODULE Window.

56

Implementation Constraints File

Page 60: Sp3im Lab Manual Vhdl

Step 3: Click on the UCF File (Traffic_Light.ucf) and Select the Edit Constraints (Text). Write the constraint file as shown in figure below.

For implementing your design, from the source window selects Generate Programming File from the drop-down menu.

57

Page 61: Sp3im Lab Manual Vhdl

Step 4: Procedure for downloading using iMPACT• Boundary Scan Mode

1. Right click on “Configure Device (iMPACT)” -> and Say RUN or Double click on “Configure Device (iMPACT)”.

2. Right click in workspace and say Initialize chain .The device is seen.3. Right click on the device and say Program.

58

Page 62: Sp3im Lab Manual Vhdl

59

Page 63: Sp3im Lab Manual Vhdl

If the device is programmed properly, it says Programming Succeeded or else. Programming Failed. The DONE Led glows green if programming succeeds.

Note: Before downloading make sure that Protoboard is connected to PC's parallel port with the cable provided and power to the Protoboard is ON

60

Page 64: Sp3im Lab Manual Vhdl

CHAPTER 10

Real Clock Timer10.1 Description for Real Clock TimerReal Clock timer consists of six character multiplexed display working on system clock of 4 MHz. Out of six displays first two (DIS -6 and DIS- 5) are used to display hours, next two (DIS-4 and DIS-3) are used to display minutes and last two (DIS -2 and DIS-1) are used to display seconds status.Real time status is displayed on these seven segments by writing a HDL functionality of 6 counters cascaded with each other and decoding its output to seven segment equivalents.

HDL functionality also offers a provision for loading the real clock timer with a new value using load signal, when high real clock timer is loaded with new value. Control signal is also provided to set 24 or 12 hour mode of operation, when high 24 hour mode is selected whereas low on control signal selects 12 hour mode of operation.

10.2 VHDL Code for Real Clock Timerlibrary IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating---- any Xilinx primitives in this code.--library UNISIM;--use UNISIM.VComponents.all;------------------------------------------------------------------------------This is real time clock in this we use--4mhz clock-- to generate 1 sec clock we use enable signal high for last 1 count -- sec1 counter for reading sec-- sec2 counter for reading sec-- min1 counter for reading min-- min2 counter for reading min-- hr1 counter for reading hr-- hr2 counter for reading hr

entity realclock isport(reset,clock,load,control:in std_logic; sgout_rg:out std_logic_vector(7 downto 0);

dis:out std_logic_vector(5 downto 0));

end realclock;

architecture Behavioral of realclock issignal tc,tc1,tc2,tc3,tc4,tc5,tc6,enable:std_logic;signal sec1,sec2,min1,min2,hr1,hr2: std_logic_vector(3 downto 0);signal sec1_rg:std_logic_vector(3 downto 0);signal sec2_rg:std_logic_vector(3 downto 0);signal min1_rg:std_logic_vector(3 downto 0);signal min2_rg:std_logic_vector(3 downto 0);signal hr1_rg:std_logic_vector(3 downto 0);signal hr2_rg:std_logic_vector(3 downto 0);signal pulsegen:std_logic_vector(21 downto 0);

61

Page 65: Sp3im Lab Manual Vhdl

signal sel:std_logic_vector(2 downto 0);signal mout:std_logic_vector(3 downto 0);signal sgout:std_logic_vector(7 downto 0);signal dis_sig:std_logic_vector(5 downto 0);signal cnk2:std_logic_vector(2 downto 0); begin--*************************** Pulse Generator ******************p0:process(reset,clock,pulsegen) beginif (reset = '1') then pulsegen <= "0000000000000000000000";elsif rising_edge (clock) then if (pulsegen = "1111010000100100000000") then pulsegen <= "0000000000000000000000"; else

pulsegen <= pulsegen + 1; end if;

end if;

end process;

---------- Enable signal to generate 1-sec pulse for sec1 counter

enable <= '1' when pulsegen = "1111010000100100000000" else --enable signal for sec1 counter '0';--************************ Second_cntr1 *************************

p1:process (reset,clock,sec1_rg,enable,load) --decade counter beginif (reset = '1') then sec1_rg <= "0000";elsif load = '1' then sec1_rg <= "0100";

elsif rising_edge(clock) then if (enable = '1') then

if (sec1_rg = "1001")then sec1_rg <= "0000";

else sec1_rg <= sec1_rg + 1; end if;

end if; end if;

sec1 <= sec1_rg;end process ;

------------------tc signal to start sec2 counter---------------------------

tc <= '1' when (sec1_rg = "1001") and (enable = '1') else --signal for sec2 counter '0';

--************************* Second_cntr2 *********************** p2:process (reset,clock,sec2_rg,tc,load) --sec2 counter for reading upto 59 sec

62

Page 66: Sp3im Lab Manual Vhdl

beginif (reset = '1') then sec2_rg <= "0000";

elsif (load = '1') then sec2_rg <= "0100";

elsif rising_edge(clock) then if (tc = '1') then if (sec2_rg = "0101")then

sec2_rg <= "0000"; else sec2_rg <= sec2_rg + 1; end if;

end if;end if;

sec2 <= sec2_rg;end process;

-------------------------tc1 signal to start min1 counter-------------------tc1 <= '1' when (sec2_rg = "0101") and (tc = '1') else '0' ;--************************ Minute_cntr1 *************************

p3:process(reset,clock,min1_rg,tc1,load) -- min1 counterbeginif (reset = '1') then min1_rg <= "0000";

elsif load = '1' then min1_rg <= "0100";

elsif rising_edge(clock) thenif (tc1 = '1') then if (min1_rg = "1001")then

min1_rg <= "0000"; else min1_rg <= min1_rg + 1; end if;end if;

end if;

min1 <= min1_rg;end process;

------------------------tc2 signal to start min2 counter--------------------tc2 <= '1' when (min1_rg ="1001") and (tc1 = '1') else --pulse for min2 counter '0';

--************************ Minute_cntr2 ************************* p4:process(reset,clock,min2_rg,tc2,load) --min2 counterbeginif (reset = '1') then min2_rg <= "0000";

63

Page 67: Sp3im Lab Manual Vhdl

elsif load = '1' then min2_rg <= "0100";

elsif rising_edge(clock) thenif (tc2 = '1') then if (min2_rg = "0101")then

min2_rg <= "0000"; else min2_rg <= min2_rg + 1; end if;end if;

end if; min2 <= min2_rg;end process;

--------------------tc3 signal to start hr1 counter-------------------------tc3 <= '1' when (min2_rg ="0101") and (tc2 = '1') else '0';

--************************ Hour_cntr1 *************************

p5:process(reset,clock,hr1_rg,tc3,load,control,tc6,tc5) --hr1 counterbeginif (reset = '1') then hr1_rg <= "0000";

elsif (load = '1') then hr1_rg <= "0001";

elsif rising_edge(clock) thenif control = '1' then

if (tc5 = '1') thenhr1_rg <= "0000";elseif (tc3 = '1') then if (hr1_rg = "1001")then

hr1_rg <= "0000"; else hr1_rg <= hr1_rg + 1; end if;end if;

end if;

else

if (tc6 = '1') thenhr1_rg <= "0001";elseif (tc3 = '1') then if (hr1_rg = "1001")then

hr1_rg <= "0000"; else hr1_rg <= hr1_rg + 1;

64

Page 68: Sp3im Lab Manual Vhdl

end if;end if;

end if;end if;end if;

hr1 <= hr1_rg;end process; ---------------------tc4 signal to start hr2 counter--------------------------tc4 <= '1' when (hr1_rg ="1001") and (tc3 = '1') else '0';

------------------------tc5 signal to reset at 23:59:59--------------------------tc5 <= '1' when (hr2_rg ="0010")and (hr1_rg ="0011") and (tc3 = '1') else '0';-----------------------------tc6 signal to reset at 11:59:59--------------- tc6 <= '1' when (hr2_rg = "0001") and (hr1_rg = "0010") and (tc3 = '1') else '0';--************************ Hour_cntr2 *************************

p6:process(reset,clock,hr2_rg,tc4,load,control) --hr2 counterbeginif (reset = '1') then hr2_rg <= "0000";

elsif load = '1' then hr2_rg <= "0000";

elsif rising_edge(clock) then if (control = '1') then if (tc5 = '1') then

hr2_rg <="0000";elseif (tc4 = '1') then if (hr2_rg = "0010")then

hr2_rg <= "0000";else hr2_rg <= hr2_rg + 1; end if;end if;

end if;

else

if (tc6 = '1') thenhr2_rg <="0000";elseif (tc4 = '1') then if (hr2_rg = "0001")then

hr2_rg <= "0000";else hr2_rg <= hr2_rg + 1; end if;

65

Page 69: Sp3im Lab Manual Vhdl

end if; end if;

end if;end if;

hr2 <= hr2_rg;end process;

p14:process(reset, pulsegen(9)) beginif (reset = '1') thencnk2 <= "000";elsif rising_edge(pulsegen(9)) then if (cnk2 = "101") then cnk2 <= "000"; else cnk2 <= cnk2 + 1; end if;

end if;end process;

mout <= sec1 when cnk2 = "000" else sec2 when cnk2 = "001" else min1 when cnk2 = "010" else min2 when cnk2 = "011" else

hr1 when cnk2 = "100" else hr2 when cnk2 = "101";

sgout <= "11000000" when mout = "0000" else "11111001" when mout = "0001" else "10100100" when mout = "0010" else "10110000" when mout = "0011" else "10011001" when mout = "0100" else "10010010" when mout = "0101" else

"10000010" when mout = "0110" else "11111000" when mout = "0111" else "10000000" when mout = "1000" else "10011000" when mout = "1001" else "11111111" ;

dis_sig <= "111110" when cnk2 = "000" else"111101" when cnk2 = "001" else"111011" when cnk2 = "010" else "110111" when cnk2 = "011" else"101111" when cnk2 = "100" else"011111" ;--when cnk2 = "101" ;

sgout_rg <= sgout; dis <= dis_sig;

end Behavioral;

66