19EC516 - HDL Programming APRIL 2024
19EC516 - HDL Programming APRIL 2024
UNIT – I
Questions
At this level, the module is designed This is the highest level of abstraction
by specifying the data flow. The provided by Verilog HDL. A module can
QA103
designer is be implemented in terms of the desired
aware of how data flows between design algorithm without concern for the
hardware registers and how the data is hardware implementation details.
processed in the design. Designing at this level is very similar to C
programming.
Questions
Q. No Questions
QA202
QA203 List out the keywords used for switch primitives in switch level modeling?
MOS switches
nmos
pmos
cmos
Bidirectional switches
tran
tranif0
tranif1
Resistive switches
rnmos
rpmos
rcmos
Resitive bidirectional switches
rtran
rtranif0
rtranif1
Write Verilog code for CMOS inverter in switch level modeling.
module my_not (input x, output f);
// internal declaration
supply1 vdd;
QA204 supply0 gnd;
// NOT gate body
pmos p1 (f, vdd, x);
nmos n1 (f, gnd, x);
endmodule
QA205 Differentiate the timing checks $setup and $hold.
UNIT – III
Q. No Questions
Write the VHDL code for half subtractor using dataflow modeling.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity HALF_SUB is
port(A, B : in std_logic;
QA304 DIFF, Borrow : out std_logic);
end HALF_SUB;
UNIT – IV
Q. No Questions
Function Procedure
Functions are used to describe frequently used These are used to partition large behavioral
sequential algorithms that return a single value that is descriptions into modular sections.
returned to the calling program using a return
statement.
Eg., resolution functions, type conversion functions. Eg., Arithmetic Unit, Memories, Control Unit, etc
These are usually used for computing a single value. Procedures can return zero or more values using
parameters of mode out and inout
Functions are used to compute values that are A process that calls a procedure with a wait statement
available instantaneously. cannot have a sensitivity list. This follows from the
fact that a process cannot be sensitive to signals and
also be made to wait simultaneously.
A function cannot be made to wait. A procedure body can have a wait statement. Hence
any variables declared in the procedure retain their
values through this wait period and cease to exist only
when the procedure terminates.
The general syntax of a subprogram specification for a Syntax for a procedure body
function body is
procedure procedure-name ( parameter-list )
function function-name (parameter-
list) return return-type The parameter-list specifies the list of formal
parameters for the procedure. Parameters may be
The parameter-list describes the list of formal constants, variables, or signals and their modes may
parameters for the function. The only mode allowed be in, out, or inout.
for the parameters is mode in. Also, only constants
and signal objects can be passed in as parameters.
The purpose of defining a generic statement within an entity is to confer more flexibility and reusability. A generic
QA402
parameter is basically used globally with some value. Whenever one want to reuse same thing again and again then
defining it as a generic parameter will be useful rather than defining it again and again.
2. Package body.
The package declaration defines the interface for the package, much the same way that the entity defines the interface
for a model.
A package declaration contains a set of declarations that may possibly be shared by many design units. It defines the
interface to the package, that is, it defines items that can be made visible to other design units, for example, a function
declaration.
configuration_specification ⇐
Write the syntax for configuration specification.
for component_specification
QA404 binding_indication ;
{ use vunit verification_unit_name { , … } ; }
end for ;
This is similar to the form in a component configuration, but without the nested configuration for the architecture.
Define component and give its syntax.
A component declaration declares a virtual design entity interface that may be used in component instantiation
statement.
QA405 component component_name [ is ]
generic (generic_list);
port (port_list);
end component component_name;
UNIT V
Q. No Questions
• “always” construct
• “assign” statements
• “parameter” statement
Differentiate simulation and synthesis in HDL.
Simulation Synthesis
Process of describing the behavior of the process of constructing a physical system
circuit using input signals output signal and from an abstract descriptions of predefined
delays set of building blocks.
QA504*
Uses the sensitivity list to figure out when to Ignores sensitivity list
run the process
Simulation is used to verify the functionality Synthesis is used for
of the circuit convert VHDL description to match the
target technology.
Define technology mapping and optimization.
Technology mapping is an important task of logic synthesis of digital circuits. It consists of transforming a multiple-
*
QA505 level Boolean network into an interconnection of primitive gates that belong to a pre-specified library.
Optimization: Synthesis optimizes the design for various metrics, such as area, power consumption, and timing. By
leveraging advanced algorithms, it improves the performance and efficiency of the resulting netlist.
Q. No Questions
QB101 (a) Design the 8-Ripple carry Adder using Structural level modeling in Verilog HDL
endmodule
(Or)
QB101 (b) Build a JK flip flop and SR Flip flop circuit using an always statement with necessary logic diagram using
Behavioral modeling in Verilog HDL.
JK Flip flop Verilog code : (7 Marks)
module JK_flipflop (q, q_bar, j,k, clk, reset);
input j,k,clk, reset;
output reg q;
output q_bar;
// always@(posedge clk or negedge reset) // for asynchronous reset
always@(posedge clk) begin // for synchronous reset
if(!reset)
q <= 0;
else
begin
case({j,k})
2'b00: q <= q; // No change
2'b01: q <= 1'b0; // reset
2'b10: q <= 1'b1; // set
2'b11: q <= ~q; // Toggle
endcase
end
end
assign q_bar = ~q;
endmodule
Interpret the operator types in data flow modelling with an example also write the 4:1 mux using conditional
QB102 (a) operators.
Types of Operators : 9 Marks
Arithmetic Operator
Logical operator
Relational Operator
Equality Operator
Bitwise Operator
Reduction Operator
Shift Operator
Concatenation Operator
Conditional Operator
QB103 (a)* (i)Implement a Verilog-based full adder circuit by instantiating two half adder modules, ensuring that it
correctly performs binary addition for three input bits. (Use structural level modeling) (7)
(ii) Design a priority encoder circuit for 8 inputs and 3 outputs. Provide the Verilog code for the design using
case statement. (6)
(i)
(Or)
103 b) (i)Design 4-bit ripple counter using behavioral modeling of Verilog code (8)
(ii) Design a Serial In Serial Out Shift Register using Verilog (5)
module D_FF(q,d,clk,reset);
input d,clk,reset;
output reg q;
if(reset)
q<=1'b0;
else
q<=d;
end
endmodule
module T_FF(q,clk,reset);
input clk,reset;
output q;
wire d;
D_FF dff0(q,d,clk,reset);
not n1(d,q);
endmodule
module ripple_counter_4_bit(q,clk,reset);
input clk,reset;
output[3:0]q;
T_FF tff0(q[0],clk,reset);
T_FF tff1(q[1],q[0],reset);
T_FF tff2(q[2],q[1],reset);
T_FF tff3(q[3],q[2],reset);
endmodule
ii) SISO
module sisomod(clk,clear,si,so);
input clk,si,clear;
output so;
reg so;
begin
if (clear)
else
end
endmodule
UNIT II
Q. No Questions
(ii)Design 4:1 multiplexer and 4 input AND function with UDP using Verilog HDL. (9Marks)
// A 4-to-1 multiplexer
primitive udp_mux41 (f, s0, s1, i0, i1, i2, i3);
input s0, s1, i0, i1, i2, i3;
output f;
table
// s0 s1 i0 i1 i2 i3 : f
0 0 0 ? ? ? : 0;
0 0 1 ? ? ? : 1;
1 0 ? 0 ? ? : 0;
1 0 ? 1 ? ? : 1;
0 1 ? ? 0 ? : 0;
0 1 ? ? 1 ? : 1;
1 1 ? ? ? 0 : 0;
1 1 ? ? ? 1 : 1;
endtable
endprimitive
QB202 (a) (i)Explain the type of delay models in detail with examples.
(i) Lumped delay model (4)
(Or)
QB203 (b)* Write the switch level Verilog code (i) 2 input XOR gate (ii) 2 input NOR gate.
(i) Xor gate (7)
(ii) NOR gate (6)
UNIT – III
Q. No Questions
QB301 (a)* Develop VHDL code for an 8 to 3 priority encoder using behavior modeling.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity PRI_EN is
port (A: in STD_LOGIC_VECTOR (7 downto 0);
Y: out STD_LOGIC_VECTOR (2 downto 0));
end PRI_EN;
architecture behav of PRI_EN is
begin
process (A)
begin
If (A(7) = '1') then Y <= "111";
elsif (A(6) = '1') then Y <= "110";
elsif (A(5) = '1') then Y <= "101";
elsif (A(4) = '1') then Y <= "100";
elsif (A(3) = '1') then Y <= "011";
elsif (A(2) = '1') then Y <= "010";
elsif (A(1) = '1') then Y <= "001";
elsif (A(0) = '1') then Y <= "000";
else
Y <= "XXX";
end if ;
end process ;
end behav;
Or
Write VHDL code for a 8:1 Multiplexer and 1:8 demultiplexer Gate and Dataflow modeling.
QB 301 (b)*
8:1 Mux
1 to 8 deMux:
(i)Write VHDL code for 7 segment display using case statement. (7)
(ii)Write VHDL code for JK flip-flop using behavior modeling. (6)
library ieee;
use ieee.std_logic_1164.all;
entity JK_FF is
port (J, K, Clock, Reset : in std_logic;
Q : out std_logic);
end JK_FF;
architecture sig of JK_FF is
begin
process (Clock, Reset) is
begin
if (Reset = '0') then
QB302 (a)*
Q <= '0';
elsif (Clock=’1’ and Clock’event) then
case ((J&K)) is
when "11" => Q <= not Q;
when "10" => Q <= '1';
when "01" => Q <= '0';
when “00”=> Q<=Q;
when others => ‘0’;
end case;
end if;
end process;
end sig;
(or)
(i)
Syntax
if (boolean-expression) then
sequential-statements
[ elsif boolean-expression then -- elsif clause; if stmt can have 0 or
sequential-statements ] -- more elsif clauses.
[ else -- else clause. sequential-statements ]
end if;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity multiplexer_4_1 is
port(
din : in STD_LOGIC_VECTOR(3 downto 0);
sel : in STD_LOGIC_VECTOR(1 downto 0);
dout : out STD_LOGIC
);
end multiplexer_4_1;
(ii)
library IEEE;
use IEEE.std_logic_1164.all;
entity decoder is
port(a : in std_logic_vector (1 downto 0);
d : out std_logic_vector (3 downto 0));
end decoder;
architecture bhv of decoder is
begin
process(a)
begin
case a is
when "00" => d <= "0001";
when "01" => d <= "0010";
when "10" => d <= "0100";
when "11" => d <= "1000";
end case;
end process;
end bhv;
QB303 (a) Develop a VHDL code for Modulus 10 counter.
Library IEEE;
Use IEEE.std_logic_1164.all;
Use IEEE.std_logic_arith.all;
entity Modulus_CTR is
port (clk, rst: in std_logic;
count: out std_logic_vector(3 downto 0)
);
end Modulus_CTR;
Test Bench:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tb_counters is
end tb_counters;
begin
dut: Modulus_CTR port map (clk => clk_tb, rst=>rst_tb, count =>
count_tb);
-- Clock process definitions
clock_process :process
begin
clk <= '0';
wait for 10 ns;
clk <= '1';
wait for 10 ns;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
rst_tb <= '1';
wait for 20 ns;
rst_tb <= '0';
wait;
end process;
end Behavioral;
(Or)
(Or)
QB303 (b)* (i)Design SR flip flop in behavior modeling using if statement in VHDL. (7)
(ii)Design a 2 to 4 decoder in behavior modeling using case statement in VHDL.(6)
(i)
VHDL Code for SR FlipFlop
library ieee;
use ieee. std_logic_1164.all;
use ieee. std_logic_arith.all;
use ieee. std_logic_unsigned.all;
entity SR_FF is
PORT( S,R,CLOCK: in std_logic;
Q, QBAR: out std_logic);
end SR_FF;
entity decoder is
port(a : in std_logic_vector (1 downto 0);
d : out std_logic_vector (3 downto 0));
end decoder;
architecture bhv of decoder is
begin
process(a)
begin
case a is
when "00" => d <= "0001";
when "01" => d <= "0010";
when "10" => d <= "0100";
when "11" => d <= "1000";
end case;
end process;
end bhv;
UNIT IV
Q. No Questions
Describe in detail about Generics in VHDL with a suitable example.
Definition for Generic Constant (3 Marks)
QB401 (a)*
Definition for Generic Statements (3 Marks)
Explanation of these with example (7 Marks)
(Or)
Develop a VHDL code for 8-bit counter
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
entity counter is
Port ( rst,clk,up_dwn : in std_logic;
count: out std_logic_vector(7 downto 0));
end counter;
architecture count_arch of counter is
QB401 (b) begin
process(rst,clk)
begin
if (rst = ‘1’) then count <= “0000”;
elsif (clk’event and clk = ‘0’) then
if (up_dwn = ‘1’) then count <= count – 1;
else count <= count + 1;
end if;
end if;
end process;
end count_arch;
Illustrate the concepts of procedure and function with appropriate examples.
Procedure & Function Syntax (3 Marks)
QB402 (a)
Procedure & Function Explanation (5 Marks)
Procedure & Function Example (5 Marks)
(Or)
QB402 (b) Design a 10 bit adder using VHDL by instantiating fulladder.
library IEEE
use IEEE.STD_LOGIC_1164.all;
entity adder_10bit is
port(a : in STD_LOGIC_VECTOR(9 downto 0); b : in STD_LOGIC_VECTOR(9 downto 0);
sum : out STD_LOGIC_VECTOR(9 downto 0) ; carry : out STD_LOGIC);
end adder_10bit;
architecture adder_10bit_arc of adder_4bit is
Component fa is
port (a : in STD_LOGIC; b : in STD_LOGIC; c : in STD_LOGIC;
sum : out STD_LOGIC; carry : out STD_LOGIC);
end component;
signal s : std_logic_vector (8 downto 0);
begin
u0 : fa port map (a(0),b(0),'0',sum(0),s(0));
u1 : fa port map (a(1),b(1),s(0),sum(1),s(1));
u2 : fa port map (a(2),b(2),s(1),sum(2),s(2));
u3 : fa port map (a(3),b(3),s(2),sum(3),s(3));
u4 : fa port map (a(4),b(4),s(3),sum(4),s(4));
u5 : fa port map (a(5),b(5),s(4),sum(5),s(5));
u6 : fa port map (a(6),b(6),s(5),sum(6),s(6));
u7 : fa port map (a(7),b(7),s(6),sum(7), s(7));
u8 : fa port map (a(8),b(8),s(7),sum(8),s(8));
u9 : fa port map (a(9),b(9),s(8),sum(9),carry);
end adder_10bit_arc;
use IEEE.STD_LOGIC_1164.all;
entity fa is
port (a : in STD_LOGIC;b : in STD_LOGIC;c : in STD_LOGIC;
sum : out STD_LOGIC; carry : out STD_LOGIC);
end fa;
architecture fa_arc of fa is
begin
sum <= a xor b xor c;
carry <= (a and b) or (b and c) or (c and a);
end fa_arc
QB403 (a) Explain the package declaration and package body in detail.
Package declaration Syntax and Example – (7 Marks)
Package body syntax and Example – (6 Marks)
(Or)
(Or)
Discuss about basic configuration declarations and write an example for the configuration of a four-bit register.
configuration_declaration ⇐
Configuration Declarations (7Marks)
component_specification ⇐
end [ configuration ] [ identifier ] ;
Q. No Questions
Illustrate about Verilog HDL synthesis and draw the logic synthesis design flow from RTL to Gates.
Verilog HDL Synthesis (7 Marks)
Verilog Constructs
Verilog Operators
Interpretation of a Few Verilog Constructs
Synthesis Design Flow (6 Marks)
RTL to Gates
QB501 (a)*
(Or)
Describe useful modelling tips for logic synthesis.
Verilog coding styles(13Marks)
Use meaningful names for signals and variables
Avoid mixing positive and negative edge triggered flipflops
Use bsic building blocks vs use continuous assign statements
QB501 (b)*
Instantiate multiplexers vs use if-else or case statements
Use parenthesis to optimize logic structure
Use arithmetic operators *,/,and % vs Design buiding blocks
Becareful with multiple assignments to the same variables
Define if-else or case statements explicitly
Write short notes on horizontal partitioning and vertical partitioning.
QB502 (a)*
(or)
Describe about the synthesis of combinational circuits with a suitable example.
Styles for Synthesizable Combinational Logic (10Marks)
• The possible styles for modeling combinational logic with example.
– Netlist of Verilog built-in primitives like gate instances (AND, OR, NAND, etc.).
– Combinational UDP (not all synthesis tools support this).
– Continuous assignments.
– Functions.
– Behavioral statements.
– Tasks without event or delay control.
QB502 (b)*
– Interconnected modules of one or more of the above.
synthesis rules for combinational logic.(3Marks)
The output of a combinational logic circuit at time t should depend only upon the inputs applied at time t.
• Rules to be followed:
– Avoid technology dependent modeling (i.e. implement functionality, not timing).
– There must not be any feedback in the combinational circuit.
– For “if…else” or “case” constructs, the output of the combinational function must be specified for all possible input
cases.
– If the rules the not followed, the circuit may be synthesized as sequential.
Describe about the synthesis of sequential circuits with a suitable example.(13 Marks)
Design Specification
Circuit Requirements
Finite State Machine (State Diagram)
Verilog Description (Program of FSM)
QB503 (a)*
Technology Library
Design Constraints
Logic Synthesis
Optimized Gate Level Netlist(Gate Level Diagram)
Verification
(Or)
*
QB503 (b) Write a Verilog module to implement a J-K master-slave flip-flop with asynchronous set and reset at the gate
level. The module will take as arguments the following:
1-bit data input “J”, 1-bit data input “K”, 1-bit clock input “Clk”, 1-bit data input “Set”, 1-bit data input “Rst”,
1-bit output “Q” and 1-bit output “Qb”
Gate level Diagram (4 Marks)
Verilog Description (9 Marks)
(PART C – 15 Marks - Either Or Type)
UNIT - I
Q. No Questions
QC101 (a) Develop and verify an HDL behavioral description of 16-bit arithmetic logic unit (ALU). The circuit has 4-bit select bus (Sel),
sixteen-bit input A[15:0] and B[15:0], and an 16-bit output Y.
Write a verilog code for a BCD to 7 segment decoder using case statement in behavioral description. The seven segments of the
QC101 (b)* decoder display are a, b, c, d, e, f and g. A segment glows when the corresponding bit if segment is zero.
UNIT – II
Q. No Questions
QC201 (a)* (i)Write the Verilog description of positive edge sensitive SR Flip Flop using UDP. (7 Marks)
// A positive edge sensitive SR flip-flop
Primitive SRFF (q, s, r, clk, clr);
input s, r, clk, clr;
output reg q;
table
// s r clk clr q q_new
? ? ? 1 : ? : 0; // clear
? ? ? (10) : ? : -; // ignore .. no change
0 0 (01) 0 : ? : -; // no change
0 1 (01) 0 : ? : 0; // reset condition
1 0 (01) 0 : ? : 1; // set condition
1 1 (01) 0 : ? : x; // invalid condition
? ? (10) 0 : ? : -; // ignore .. no change
endtable
endprimitive
(ii) Write a Verilog program for a full adder circuit using a task. Define the task 'FA' that takes three inputs (A, B, and Cin)
and produce two outputs (Sum and Cout). Ensure that your program invokes the task for the generation of Sum and Cout
after a delay of 2 time units. (8Marks)
(Or)
QC201 (b)*
(ii) Write the switch level modeling for D flip flop.(7Marks)
(i)Write the switch level Verilog code for 2:1 Multiplexer.(8Marks)
Q. No Questions
QC301 (a)*
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity jkc is
Port ( clock : in std_logic;
reset : in std_logic;
count : out std_logic_vector(3 downto 0)
);
end jkc;
d1 : jkff
port map (
reset => reset,
clock => temp(3),
j => '1',
k => '1',
q => temp(2)
);
d2 : jkff
port map (
reset => reset,
clock => temp(2),
j => '1',
k => '1',
q => temp(1)
);
d3 : jkff
port map (
reset => reset,
clock => temp(1),
j => '1',
k => '1',
q => temp(0)
);
(Or)
QC301 (b)* Design the following code converters using dataflow modeling in VHDL.
(i) Gray to Binary (8)
(ii) Binary to Gray (7)
(i)
(ii)
UNIT IV
Q. No Questions
QC401 (a)* (i)Design a Parallel In serial Out Shift Register using VHDL. (7 Marks)
library ieee;
use ieee.std_logic_1164.all;
entity piso is
port(
clk,rst : in std_logic;
);
end piso;
begin
process (clk,rst)
begin
temp<=D;
else
end if;
end if;
end process;
q<= temp(3);
end arch;
(ii)Design a Serial In Parallel Out Shift Register using VHDL. (8 Marks)
library ieee;
use ieee.std_logic_1164.all;
entity sipo is
port(
Input_Data: in std_logic;
end sipo;
begin
process (clk)
begin
Q <= "0000";
end process;
end arch;
(Or)
QC401 (b)* Develop a VHDL code for 4-bit Ring Counter using D Flip-Flop.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Ring_counter is
RESET : in STD_LOGIC;
end Ring_counter;
begin
process(CLOCK,RESET)
begin
if RESET = '1' then
end if;
end process;
Q <= q_tmp;
end Behavioral;
UNIT V
Q. No Questions
QC501 (a)* Write a Verilog description of a Mealy sequence detector circuit that accepts a serial bit stream “x” as input and produces
a serial bit stream “z” as output. Whenever the bit pattern “1101” appears in the input stream, it outputs z = 1; at all
other times, z = 0.
//1101 Mealy Sequence Detector
module mealy_1101(
input x,clk,reset,
output reg z
);
always@(PS or x)
begin
case(PS)
S0 : begin
z=0;
NS = x ? S1 : S0 ;
$display(PS);
end
S1 : begin
z=0;
NS = x ? S2 : S0 ;
$display(PS);
end
S2 : begin
z=0;
NS = x ? S2 : S3 ;
$display(PS);
end
S3 : begin
z=x?1:0;
NS = x ? S1 : S0 ;
$display(PS);
end
endcase
end
endmodule
(Or)
QC501 (b)* Design a state machine in Verilog to manage the different traffic light states (e.g., green, yellow, red) and transitions
between these states.
There are three lamps, RED, GREEN and YELLOW, that should glow cyclically with a fixed Fme interval (say, 1 second)
– The FSM will have three states, corresponding to the glowing state of the lamps.
– The input set is null; state transition will occur whenever clock signal comes.
– This is a Moore Machine, since the lamp that will glow only depends on the state and not on the inputs (here null).