Verilog Lab
Verilog Lab
Verilog Lab
LABORATORY MANUAL
By: Smt.Meenakshi A Hugar
E&CE Dept.
SEMESTER:III
PART A
ALU should use combinational logic to calculate an output based on the four bit op-code
input.
ALU should pass the result to the out bus when enable line in high, and tri-state the out
bus when the enable line is low.
ALU should decode the 4 bit op-code according to the example given below.
OPCODE ALU
Operation
1. A+B
2. A-B
3. A
Complement
4. A*B
5. A AND B
6 Write Verilog code for counter with given input clock and check whether it works asclock
divider performing division of clock by 2, 4, 8 and 16. Verify the functionality of the code.
PART-B
7 Write a Verilog code to design a clock divider circuit that generates 1/2, 1/3rd and 1/4thclock from a
given input clock. Port the design to FPGA and validate the functionality through oscilloscope.
8 Interface a DC motor to FPGA and write Verilog code to change its speed and direction.
9 Interface a Stepper motor to FPGA and write Verilog code to control the Stepper motor rotation which in
turn may control a Robotic Arm. External switches to be used for different controls like rotate the Stepper
motor (i) +N steps if Switch no.1 of a Dip switch is closed (ii) +N/2 steps if Switch no. 2 of a Dip switch
is closed (iii) –N steps if Switch no. 3 of a Dip switch is closed etc.
10 Interface a DAC to FPGA and write Verilog code to generate Sine wave of frequency F KHz (eg. 200
11 KHz) frequency. Modify the code to down sample the frequency to F/2 KHz. Display the Original and
Introduction to HDL
2. Design Synthesis – next step in the design process is to transform design specification
into a more suitable representation that can be further processed in the later stages in the
design flow. This representation is called the netlist. Prior to netlist creation synthesis tool
checks the model syntax and analyse the hierarchy of your design which ensures that your
design is optimized for the design architecture you have selected. The resulting netlist is
saved to a Native Generic Circuit (NGC) file (for Xilinx® Synthesis Technology (XST)
compiler) or an Electronic Design Interchange Format (EDIF) file (for Precision, or
Synplify/Synplify Pro tools).
3. Design Implementation
Implementation step maps netlist produced by the synthesis tool onto particular device's
internal structure. It consists from three steps:
3.1 Translate step – merges all incoming netlists and constraints into a Xilinx Native
Generic Database (NGD) file.
3.2 Map step - maps the design, specified by an NGD file, into available resources on
the target FPGA device, such as LUTs, Flip-Flops, BRAMs,... As a result, an Native
Circuit Description (NCD) file is created.
3.3 Place and Route step - takes a mapped Native Circuit Description (NCD) file,
places and routes the design, and produces an NCD file that is used as input for bit
stream generation.
Timing Simulation – allows you to check does the implemented design meet all
functional and timing requirements and behaves as you expected. The timing simulation
uses the detailed information about the signal delays as they pass through various logic
and memory components and travel over connecting wires. Using this information it is
possible to accurately simulate the behaviour of the implemented design. This type of
simulation is performed after the design has been placed and routed for the target PLD,
because accurate signal delay information can now be estimated. A process of relating
Dept. of ECE, Page 2
VERILOGLAB 20EC32P
accurate timing information with simulation model of the implemented design is called
Back-Annotation.
Static Timing Analysis – helps you to perform a detailed timing analysis on mapped,
placed only or placed and routed FPGA design. This analysis can be useful in evaluating
timing performance of the logic paths, especially if your design doesn't meet timing
requirements. This method doesn't require any type of simulation.
5. Generate Programming File – this option runs BitGen, the Xilinx bitstream generation
program, to create a bitstream file that can be downloaded to the device.
6. Programming – iMPACT Programmer uses the output from the Generate Programming File
process to configure your target device.
7. Testing – after configuring your device, you can debug your FPGA design using the Xilinx
ChipScope Pro tool or some external logic analyzer.
8. Estimate Power – after implementation, you can use the XPower Analyzer for estimation
and power analysis. XPower Analyzer is delivered with ISE Design Suite. With this tool you
can estimate power, based on the logic and routing resources of the actual design.
a) Select VERILOG MODULE as the source type in the New Source dialog box.
d) Click Next.
e) Define the ports for your Verilog source.
In the Port Name column, type the port names on three separate rows: A, B and C.
In the Direction column, indicate whether each port is an input, output, or inout.
For A and B, select in from the list. For C, select out from the list.
6) Click Finish in the New Source Information dialog box to complete the new source file
template. Click Next in the New Project Wizard. Click next again.
ISE creates and displays the new project in the Sources in Project window and adds the
and_gate.v file to the project.
8) Double-click on the and_gate.v file in the Sources in Project window to open the Verilog
file in the ISE Text Editor.
The and_gate.v file contains:
Module name with the inputs and outputs declared.
9) Add the relationship between input and output after the input and output declared in
module. Save the file by selecting File > Save.
10) When the source files are complete, the next step is to check the syntax of the
design. Syntax errors and typos can be found using this step.
a) Select the counter design source in the ISE Sources window to display the
related processes in the Processes for Source window.
b) Click the “+”next to the Synthesize-XST process to expand the hierarchy.
c) Double-click the Check Syntax process.
11) When an ISE process completes, you will see a status indicator next to the process name.
a) If the process completed successfully, a green check mark appears.
b) If there were errors and the process failed, a red X appears.
c) A yellow exclamation point means that the process completed successfully, but
some Warnings occurred.
d) An orange question mark means the process is out of date and should be run again.
e) Look in the Console tab of the Transcript window and read the output and
status messages produced by any process that you run.
Caution! You must correct any errors found in your source files. If you continue
without valid syntax, you will not be able to simulate or synthesize your design.
12) After the successful check syntax in the process Examine RTL diagrams.
13) To Create Testbench waveform, Right click on file name in source window, and_gate.v
and add source.
14) Add testbench waveform source with a new file name and click next.
15) A timing window pops up. Click on combinatorial and click next.
16) A graphical window of input and output appears. Make changes according to the truth
table and save.
19) In process window click on Xilix ISE simulator and RUN. Output window appears.
Analyze the waveforms according to the truth table.
20) Double-click the Assign Package Pins process found in the User Constraints process
group. ISE runs the Synthesis and Translate step and automatically creates a User Constraints
File(UCF). You will be prompted with the following message.
21) Click
Yes to add the UCF file to your project. The file is added to your project and is visible in
the Sources in Project.
22) Now the Xilinx Pin out and Area Constraints Editor (PACE) opens.
23) You can see your I/O Pins listed in the Design Object List window. Enter a pin location
for each pin in the Loc column as specified below
A: P1, B:P2, C:P3
24) Click on the Package View tab at the bottom of the window to see the pins you just
added. Put your mouse over grid number to verify the pin assignment.
The Program File is created. It is written into a file called andgate.jed This is the actual
configuration data
1. Double Click the Generate Programming File process located near the bottom of the
Processes for Source window.
This section provides simple instructions for configuring a Spartan-3 xc3s200 device
connected to your PC.
Note: Your board must be connected to your PC before proceeding. If the device on your
board does not match the device assigned to the project, you will get errors. Please refer to
the IMPACT Help for more information. To access the help, select Help > Help Topics
To configure the device:
1. Click the “+” sign to expand the Generate Programming File processes.
5. If you get a message saying that there was one device found, click OK to continue
6. The iMPACT will now show the detected device, right click the device and select New
Configuration File.
7. The Assign New Configuration File dialog box appears. Assign a configuration file to
each device in the JTAG chain. Select the andgate.jed file and click Open
8. Right-click on the counter device image, and select Program... to open the Program
Options dialog box.
9. Click OK to program the device. ISE programs the device and displays Programming
Succeeded if the operation was successful
10. Close IMPACT without saving
Learning Objective: To study the Verilog code for all the logic gates
Algorithm:
Start
Initialize Input & output ports. .
Construct the truth table and extract the expression.
Write the Verilog code using a dataflow modeling style.
verify the functionality of design with the truth table
observe the timing diagram and verify
End the program.
VERILOG CODE :
1. AND gate
module and_gate
(a,b,c);
input a;
input b;
output c;
assign c= a&b;
endmodule
2. OR gate
module or_gate
(a,b,c);
input a;
input b;
output c;
assign c= a|b;
endmodule
3. NOT gate
4. NAND gate
5. NOR gate
module nor_gate
(a,b,c);
input a;
input b;
output c;
assign c= ~(a|b);
endmodule
6. XOR gate
module xor_gate
(a,b,c);
input a;
input b;
output c;
assign c= a^b;
endmodule
7. XNOR gate
VERILOG CODE
Result: The Simulation has carried out and verified with respect to truth table.
Outcomes: Familiar with Verilog HDL Program, usage of Xilinx software and understand
ISE Simulator.
VIVA QUESTIONS
1. What is HDL?
2. What is the importance of HDL?
3. What are the differences between CPLD & FPGA?
4. What are the different types of HD Language?
5. What is Module?
6. What is entity & architecture?
7. What is package?
8. What is port?
9. Whether VHDL is case sensitive or not?
10. What is bit?
11. What is keyword?
12. What is binding?
13. What is import?
14. What is out port?
15. What is buffer?
16. What is inout port?
17. What are the different types of operator?
18. What is operator?
19. What are the different types of operator?
20. What are logical operators?
21. What are relational operators?
22. What are arithemetic operator?
23. What are shift operator?
24. What are Boolean logical operator?
25. What are rotate operator?
26. What is data type?
27. What are the different types of data types?
28. What are the different types of scalar types?
29. What are files types?
30. What are the different verilog data types?
31. What are the different types of styles or architecture?
32. What is behavioral description?
33. What is structural description?
34. What is switch level description?
35. What is data flow description?
36. What is mixed-language description?
Algorithm:
Start
Initialize Input & output ports. .
Construct the truth table.
Write the Verilog code using a behavioral modeling style with respect to the truth
table
verify the functionality of design referring to truth table
observe the timing diagram
End the program.
i) 2 to 4 decoder
Figure: 2 to 4 Decoder
VERILOG CODE :
Structural code for 2 to 4 decoder
endmodule
VERILOG CODE :
VERILOG CODE:
module prio_enco(en, a_in, y_op);
input en;
input [7:0] a_in;
output [2:0] y_op;
reg [2:0] y_op;
always @ (a_in,en)
begin
if(en==1) y_op = 3‟bzzz;
if(a_in[7] == 1) y_op = 3‟b000;
if(a_in[6] == 1) y_op = 3‟b001;
if(a_in[5] == 1) y_op = 3‟b010;
if(a_in[4] == 1) y_op = 3‟b011;
if(a_in[3] == 1) y_op = 3‟b100;
if(a_in[2] == 1) y_op = 3‟b101;
if(a_in[1] == 1) y_op = 3‟b110;
if(a_in[0] == 1) y_op = 3‟b111;
default: y_op=3'bxxx;
end
endmodule
VERILOG CODE :
module mux8_1(en,i_in, sel, y_out);
input en;
input [7:0] a_in;
input [2:0] sel;
output y_out;
reg y_out;
always@ (i_in,sel )
begin
if(en==1)
y_out=1‟bz;
else
case (sel)
3'b000:y_out=i_in[0];
3'b001: y_out=i_in[1];
3'b010: y_out=i_in[2];
3'b011: y_out=i_in[3];
3'b100: y_out=i_in[4];
3'b101: y_out=i_in[5];
3'b110: y_out=i_in[6];
3'b111: y_out=i_in[7];
Truth Table :
Equation for G1= B1‟ B2 + B1 B2‟ Equation for G0= B1‟ B0 + B1 B0‟
VERILOG CODE:
Result: The Simulation has carried out and verified with respect to truth table.
Outcomes: Be able to model digital systems at several levels of abstractions and also able to
write the Verilog HDL code for different combinational circuits by using truth table in
dataflow and behavioral model.
VIVA QUESTIONS:
1. What is package?
2. What is Library function?
3. What is process?
4. What is signal assignment operator?
5. What is signal?
6. What is Vector?
7. Why do we need Procedures, Tasks and Functions?
8. Explain the difference between Function and Procedure in VHDL?
9. Explain the difference between Function and Task in Verilog?
10. How do we specify the signals in Procedure‟s declaration?
11. Give an Example of a built-in Procedure?
12. Give an Example of a built-in Task?
13. Where the Procedures can be called from(from which part of the Program)?
14. Where the Tasks can be called from(from which part of the Program)?
15. Where the Functions can be called from(from which part of the Program) in VHDL?
16. Where the Tasks can be called from(from which part of the Program) in Verilog?
17. What does return statement do in Functions?
18. Give Examples for built-in Function?
19. What are the limitation for Mixed –Language Description?
20. What are the Advantages of Mixed-Language Description?
PROGRAM - 2 ADDERS
AIM: Write a Verilog code to describe the functions of a Full Adder .
Learning Objective: To study the working and writing HDL code for Adders.
Algorithm:
Start
Initialize Input & output ports. .
Construct the truth table and extract the expression also draw the logic circuit.
Write the Verilog code using a dataflow, behavioral and structural modeling styles
with respect to the truth table, expression and logic circuit.
verify the functionality of design referring to truth table
observe the timing diagram
End the program.
Block Diagram:
CODE :
wire s1,c1,c2,c3;
xor(s1,a,b);
xor(s,c,s1);
and(c1,a,b);
and(c2,s1,cin);
or(carry,c1,c2);
endmodule
(Extra Stuff)
iii) Verilog - Structural Style (Using two half adders) :
Result: The Simulation has carried out and verified with respect to truth table.
Outcomes: Be able to design a model in three modeling style such as dataflow, behavioral
and structural.
VIVA QUESTIONS
Learning Objective: Design of ALU unit and knowing the operation of ALU.
Algorithm:
Start
Initialize Input & output ports. .
Write the Verilog code using a behavioral modeling style for a given opcode
verify the functionality of design referring to truth table
observe the timing diagram
End the program.
VERILOG CODE:
module alu(a, b, opcode,en,y,y_mul);
input [31:0] a;
input [31:0] b;
input en;
input [2:0] opcode;
output [31:0] y;
output[63:0]y_mul;
reg [31:0] y;
reg [63:0] y_mul;
always @(a, b , opcode)
begin
if (en==1)
case (opcode)
3'b000:y=a+b;
3'b001:y=a-b;
3'b010:y=~a;
3'b011:y_mul=a*b
; 3'b100:y= a&b;
3'b101:y=a|b;
3'b110:y=~(a&b);
3'b111:y=a^b;
default:begin end
endcase
else
begin
y=32‟bz;
y_mul=64‟bz
end
end
endmodul
e
Result: The Simulation has carried out and verified with respect to truth table.
Outcomes: Be able to design a small digital circuit and functional verification is learned.
VIVA QUESTIONS
Learning Objective: To Study and write the Verilog code for mention Flip-Flops
Algorithm:
Start
Initialize Input & output ports. .
Construct the truth table.
Write the Verilog code using a behavioral modeling style with respect to the truth
table
verify the functionality of design referring to truth table
observe the timing diagram
End the program.
Note: The same Algorithm follows for all types of flip flops.
a. JK FLIP-FLOP
VERILOG CODE :
reg q,qb;
always @ (posedge clk)
begin
if (rst==1)
begi
n q=0;
qb=1;
end
else
case (jk)
2'b00: begin
q=q; qb=qb;
end
2'b01: begin
q=0; qb=1;
end
2'b10: begin
q=1; qb=0;
end
2'b11: begin
q=~q; qb=~qb;
end
default:begin end
endcase
end
endmodule
b. SR FLIPFLOP
VERILOG CODE :
output q,qb;
reg q,qb;
always @ (posedge clk)
begin
if (rst==1)
begin
q=0; qb=1;
end
else
case (sr)
2'b00: begin q=q; qb=qb; end
2'b01: begin q=0; qb=1; end
2'b10: begin q=1; qb=0; end
2'b11: begin q=1'bx; qb=1'bx; end
default:begin end
endcase
end
endmodule
c. T-FLIPFLOP
Algorithm:
Start
Initialize T is reset and CLK as input ,a and qn as ouput
If clk=‟1‟ and an event on the positive pulse
If t=0 then q=1 else q=0 qb=1
Stop
VERILOG CODE :
D-FLIPFLOP
VERILOG CODE :
begin
if (rst==1)
begi
n q=0; qb=1;
end
else
begin
q=d; qb=~d;
end
end
endmodule
Result: The Simulation has carried out and verified with respect to truth table.
VIVA QUESTIONS
1. Which part of the Program provides information about the inputs, outputs and their types?
2. How do you map an array onto a logic diagram?
3. How the Sequential statements are mapped onto a logic diagram?
4. How the following codes can be mapped onto logic diagram?
a. Process(a,x,x1) b. Cases(ct) c. for i in 0 to 3 loop d. begin e. 1‟b0:4‟b d=a+b; f.
ifa(i)=‟1‟ g. then h. if(a = „1‟) then i. 1‟b1: ; j. result:=result+2**I k. endcase l. end if; m.
Else n.Y<=x1; o. end loop; p. End if;
5. How the Procedures/ tasks are mapped?
6. How the Functions are mapped?
7. Differentiate between procedure mapping and function mapping?
8. What is Simulation?
9. On what basis the codes are synthesized.
10. What is meant by mapping?
11. What are the functions of compiler?
12. Will different Simulators assign same number of gates for a single code?
13. Is there any differences between mapping or signal and variable assignment? Statement?
14. Differentiate between behavioral and structural descriptions?
15. In which applications behavioral desc is used?
16. Explain the Structure of behavioral?
17. Difference between process and always?
18. Explain Syntax of process?
19. What is Sensitivity list?
20. What is Event?
21. Is process a Concurrent or Sequential Statement?
22. What is “INITIAL”?
23. Why Label required for a statement?
24. Explain structure of IF-ELSE statement?
25. Explain structure of CASE statement?
26. Explain different Loops Structures?
27. How is For different from While?
28. How is 2‟s Compliment computed in VHDL?
29. Differentiate between Active High and Active Low Signal?
Dept. of ECE, Page 33
VERILOGLAB 20EC32P
PROGRAM 5 - COUNTERS
AIM: Design 4 bit binary, BCD Counter (Synchronous reset and Asynchronous reset) and
“any sequence” Counters.
Learning Objective: To study and write the code for Sequential circuits.
Algorithm:
Start
Initialize Input & output ports. .
Construct the truth table.
Write the Verilog code using a behavioral modeling style with respect to the truth
table
verify the functionality of design referring to truth table
observe the timing diagram
End the program.
A. BINARY COUNTER
B. BCD COUNTER
else
if (dout<=9)
dout = dout + 1;
else
if (dout==9) begin
dout <= 0;
end
end
endmodule
Synchronous Counter
module sync_up_dwn_counter(cnt,clk,up_dwn,clr);
input clk,clr;
input up_dwn;
output [3:0] cnt;
Dept. of ECE, Page 37
VERILOGLAB 20EC32P
reg [3:0]cnt;
ASynchronous Counter
tmp = 4'b0000;
else
if (enable)
tmp = tmp + 1'b1;
end
assign asy_up = tmp;
endmodule
end
1'b1 : begin
if(cnt[1:0] == 2'b01)
cnt[1:0] = 2'b10;
else if(cnt[2:0] == 3'b011)
cnt[2:0] = 3'b100;
else if(cnt[3:0] == 4'b0111)
cnt[3:0] = 4'b1000;
else if(cnt[3:0] == 4'b1111)
cnt[3:0] = 4'b0000;
else
cnt[0] = ~cnt[0];
end
endcase
end
end
endmodul
e
I. N - SEQUENCE COUNTER
initial
begin
N = 4'b1011; //:. At t = 0, let this module set N = 11
end
always @ (posedge clk)
begin
if (reset)
temp <= 4'b0001;
else if (temp == N)
temp <= 4'b0001;
else begin
temp[0] <= ~(temp[0]);
if (temp[0]) begin
temp[1]<= ~(temp[1]);
if(temp[1]) begin
temp[2]<=~(temp[2]);
if(temp[2]) begin
temp[3]<=~(temp[3]);
end
end
end
Dept. of ECE, Page 42
VERILOGLAB 20EC32P
end
end
assign q = temp;
endmodule
Result: The Simulation has carried out and verified with respect to truth table.
Outcomes: Be able to model a memory system with clock Truth table implementation seen
VIVA QUESTIONS
1. What is meant by “Rising-Edge Signal”?
2. In Verilog how it is represented?
3. Differentiate between Casex and Casez?
4. Difference between Encoder with and without priority?
5. Difference between repeat and Forever in Verilog?
6. Difference between Next and Exit?
7. Difference between Syntax and Semantic Errors?
8. What is Port Map?
9. Explain different types of Mapping?
10. Does Verilog or VHDL have built in primitive Gates. Example?
11. What is Three state Output?
12. What is State mission?
13. Difference between Mealy and Moore Circuits?
14. Explain generate?
PART B –INTERFACING
TRAINING BOARD [TK BASE] SPECIFICATION
Learning Objective: To study and write the code to control speed, direction of DC Motor.
reg pdcm;
reg [7:0] cnt;
reg [11:0] sclkdiv;
wire clk1;
initial
begin : process_2
sclkdiv = {12{1'b 0}};
end
initial
begin : process_1
cnt = {8{1'b 0}};
end
VIVA QUESTIONS
Learning Objective: To study and write the code to control speed, direction of stepper
Motor
Stepper Motor
module stepper ( dout, clk, reset, dir);
output [3:0] dout;
input clk;
input reset;
input dir;
wire [3:0] dout;
reg [20:0] div;
wire clkdiv;
reg [3:0] shift_reg;
Outcomes: Design, and interface a stepper motor using HDL Also control and reverse
directions of the motor using HDL.
VIVA QUESTIONS
Learning Objective: To Study and write HDL code to generate different wave forms (sine,
square, triangle, ramp) using DAC change the frequency and amplitude
Sine Wave
module sinewave (clk,rst,dac_out);
input clk;
input rst;
output reg [7:0] dac_out;
initial begin
counter[0]= 8'd128; // 128+128sin(theta) * Theta in Degree give as 0,15,30,45,60,75 . .upto
34values
counter[1]= 8'd161;
counter[2]= 8'd192;
counter[3]= 8'd218;
counter[4]= 8'd232;
counter[5]= 8'd244;
counter[6]= 8'd251;
counter[7]= 8'd255;
counter[8]= 8'd255;
counter[9]= 8'd251;
counter[10]= 8'd244;
counter[11]= 8'd232;
counter[12]= 8'd218;
counter[13]= 8'd192;
counter[14]= 8'd182;
counter[15]= 8'd161;
counter[16]= 8'd139;
counter[17]= 8'd116;
counter[18]= 8'd94;
counter[19]= 8'd73;
counter[20]= 8'd54;
counter[21]= 8'd37;
counter[22]= 8'd23;
counter[23]= 8'd11;
counter[24]= 8'd4;
counter[25]= 8'd4;
counter[26]= 8'd11;
counter[27]= 8'd23;
counter[28]= 8'd37;
counter[29]= 8'd54;
counter[30]= 8'd73;
counter[31]= 8'd94;
counter[32]= 8'd116;
counter[33]= 8'd128;
end
always @(posedge(clkdiv))
begin
if(i>34)
begin
i=0;
end
dac_out <= counter[i];
i = i + 1;
end
endmodule
//Extra Stuff
Square
input clk;
input rst;
output reg [7:0] dac_out;
always @(posedge(clkdiv))
begin
if (rst == 1'b1)
begin
counter <= 8'b 00000000;
end
end
always @(counter)
begin
if (counter <= 128)
begin
dac_out <= 8'b 11111111;
end
else
begin
dac_out <= 8'b 00000000;
end
end
endmodule
Triangle
module tri_wave ( clk, rst, dac_out);
input clk;
input rst;
output [7:0] dac_out;
always @(posedge(clkdiv))
begin : process_2
if (rst == 1'b 1)
counter <= 8'b 00000000;
end
counter <= counter + 1;
endmodule
Ramp
Module ramp_wave ( clk, rst, dac_out);
input clk;
input rst;
output [7:0] dac_out;
always @(posedge(clkdiv))
begin : process_2
if (rst == 1'b 1)
begin
counter <= 8'b 00000000;
end
endmodule
Outcomes: Design, and interface a DAC using HDL be able to generate different waveforms
using DAC on CRO
PROGRAM 4 – ELEVATOR
AIM: Write HDL code to simulate Elevator operation.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity TKBELE is
Port ( pkeyret : in std_logic_vector(3 downto 0);
pkeyscn : out std_logic_vector(3 downto 0);
pdspseg : out std_logic_vector (6 downto 0);
pdspmux : out std_logic_vector (3 downto 0);
pclk100K : in std_logic);
end TKBELE;
-- process keypress
process(pkeyret)
begin
case pkeyret is
when "1110" => skeyhit <= '1';
when "1101" => skeyhit <= '1';
when "1011" => skeyhit <= '1';
when "0111" => skeyhit <= '1';
when others => skeyhit <= '0';
end case;
end process;
-- process keyval
process(skeyhit)
begin
if( rising_edge(skeyhit)) then
if(skeyscn = "1110" and pkeyret = "1110")
then skeyflr <= 0;
elsif(skeyscn = "1110" and pkeyret = "1101")
then skeyflr <= 1;
elsif(skeyscn = "1110" and pkeyret = "1011")
then skeyflr <= 2;
elsif(skeyscn = "1110" and pkeyret = "0111")
then skeyflr<= 3;
elsif(skeyscn = "1101" and pkeyret = "1110")
then skeyflr <= 4;
elsif(skeyscn = "1101" and pkeyret = "1101")
then skeyflr <= 5;
elsif(skeyscn = "1101" and pkeyret = "1011")
then skeyflr <= 6;
elsif(skeyscn = "1101" and pkeyret = "0111")
then skeyflr <= 7;
elsif(skeyscn = "1011" and pkeyret = "1110")
then skeyflr <= 8;
elsif(skeyscn = "1011" and pkeyret = "1101")
then skeyflr <= 9;
elsif(skeyscn = "1011" and pkeyret = "1011")
then skeyflr <= 10;
elsif(skeyscn = "1011" and pkeyret = "0111")
then skeyflr <= 11;
elsif(skeyscn = "0111" and pkeyret = "1110")
then skeyflr <= 12;
elsif(skeyscn = "0111" and pkeyret = "1101")
then skeyflr <= 13;
elsif(skeyscn = "0111" and pkeyret = "1011")
then skeyflr <= 14;
elsif(skeyscn = "0111" and pkeyret = "0111")
then skeyflr <= 15;
end if;
end if;
end process;
-- process clk divider
process(pclk100k)
begin
if( rising_edge(pclk100k)) then
sclkdiv <= sclkdiv+1;
end if;
skeyclk <= sclkdiv(6);
sflrclk <= sclkdiv(15);
end process;
end behavioral;
Result: The Elevation from one point to another has interfaced by interfacing with evelator
unit in FPGA.
Outcomes: Design, and interface an Elevator using HDL Be able to display different floors
of an elevator in seven segment display.
VIVA QUESTIONS
Learning Objective: To study HDL code to simulate Analog to Digital Converter (ADC)
using temperature sensor.
entity adc is
Port ( addr : out std_logic_vector(1 downto 0);
chin: in std_logic_vector(1 downto 0);
strt : out std_logic;
EOC : in std_logic;
dout : in std_logic_vector(7 downto 0);
clk1: in std_logic;
oen1: out std_logic;
oen2: out std_logic;
oen3: out std_logic;
oen4: out std_logic;
oen5: out std_logic;
oen6: out std_logic;
disp: out std_logic_vector(7 downto 0));
end adc;
p1:process(clk1)
begin
if clk1'event and clk1 = '1' then
clk_count <= clk_count + 1;
clk_dsp <= clk_count(8 downto 7);
clk <= clk_count(6);
end if;
end process p1;
p2:process(clk_dsp)
begin
case clk_dsp is
when "00" => soen2 <= '1';
soen1 <= '0';
when "01" => soen1 <= '1';
soen2 <= '0';
when others => soen1 <= '0';
soen2 <= '0';
end case;
end process p2;
pp:process(clk)
begin
case current_state is
when state1 =>
strt <= '1'; --enabling start/ale
p4:process(clk1)
type t_mem is array(0 to 15) of std_logic_vector(7 downto 0);
variable mem_data: t_mem:=
("00111111", "00000110", "01011011", "01001111", --0123
"01100110", "01101101", "01111101", "00000111", --4567
"01111111", "01101111", "01110111", "01111100", --89ab
"00111001", "01011110", "01111001", "01110001"); --cdef
variable adv : integer := 0;
begin
if clk1'event and clk1 = '1' then
adv := conv_integer(address(3 downto 0));
data <= mem_data(adv);
end if ;
end process p4;
p5: process(clk)
begin
if clk1'event and clk1 = '1' then
if ( soen2 = '1' ) then
address <= check(3 downto 0);
disp <= data;
else
if (soen1 = '1' ) then
address <= check(7 downto 4);
disp <= data;
end if;
end if;
end if;
end process p5 ;
end behavioral;
Result: The analog to digital conversion is observed and the values are displayed in segment.
Outcomes: Design, and interface of ADC using VHDL and display the measured values in
seven segment display.
VIVA QUESTIONS
1. What is ADC ?
2. How many types of ADC ?
3. Difference between ADC and DAC ?
4. A 4-bit R/2R digital-to-analog (DAC) converter has a reference of 5 volts. What is the
analog output for the input code 0101.
5. What is the resolution of a digital-to-analog converter (DAC)?
6. The practical use of binary-weighted digital-to-analog converters is limited to..
7. Which is not an analog-to-digital (ADC) conversion error?