Interview 2
Interview 2
Using following program bold characters can be displayed. Note that this program takes help
of
UNIX facilities. This may not work on PC based simulators.
module bold;
initial begin
$display ("Normal Text");
$display ("\033[1mBold Text");
$display ("\033[mSwitch back to Normal Text.....");
$display ("\033[7mInverse Text.");
$display ("\033[mSwitch back to Normal Text.....");
$display ("\033[1mBold Text \033[mfollowed by \033[7mInverse text
\033[m");
end
endmodule
Sample Verilog Questions asked in Interviews. Please contribute with your questions.
If
you are looking for answers please refer to website Site FAQ
Differentiate between Inter assignment Delay and Inertial Delay.
What are the different State machine Styles ? Which is better ? Explain
disadvantages and advantages.
What is the difference between the following lines of code ?
• reg1<= #10 reg2 ;
• reg3 = # 10 reg4 ;
What is the value of Var1 after the following assignment ?
reg Var1;
initial begin
Var1<= "-"end
In the below code, Assume that this statement models a flop with async reset. In
this, how does the synthesis tool, figure out which is clock and which is reset. Is the
statements within the always block is necessary to find out this or not ?
1 module which_clock (x,y,q,d);
2 input x,y,d;
3 output q;
4 reg q;
5
6 always @ (posedge x or posedge y)
7 if (x)
8 q <= 1'b0;
9 else
10 q <= d;
11
12 endmodule
What is the output of the two codes below ?
1 module quest_for_out();
2
3 integer i;
4 reg clk;
5
6 initial begin
7 clk = 0;
8 #4 $finish;
9 end
10
11 always #1 clk = ! clk;
12
13 always @ (posedge clk)
14 begin : FOR_OUT
15 for (i=0; i < 8; i = i + 1) begin
16 if (i == 5) begin
17 disable FOR_OUT;
18 end
19 $display ("Current i : ‰g",i);
20 end
21 end
22 endmodule
1 module quest_for_in();
2
3 integer i;
4 reg clk;
5
6 initial begin
7 clk = 0;
8 #4 $finish;
9 end
10
11 always #1 clk = ! clk; 12
13 always @ (posedge clk)
14 begin
15 for (i=0; i < 8; i = i + 1) begin : FOR_IN
16 if (i == 5) begin
17 disable FOR_IN;
18 end
19 $display ("Current i : ‰g",i);
20 end
21 end
22 endmodule
Why cannot initial statement be synthesizeable ?
Consider a 2:1 mux; what will the output F be if the Select (sel) is "X" ?
What is the difference between blocking and nonblocking assignments ?
What is the difference between wire and reg data type ?
Write code for async reset D-Flip-Flop.
Write code for 2:1 MUX using different coding methods.
Write code for a parallel encoder and a priority encoder.
What is the difference between === and == ?
What is defparam used for ?
What is the difference between unary and logical operators ?
What is the difference between tasks and functions ?
What is the difference between transport and inertial delays ?
What is the difference between casex and case statements ?
What is the difference between $monitor and $display ?
What is the difference between compiled, interpreted, event based and cycle based
simulators ?
What is code coverage and what are the different types of code coverage that one
does ?
How do I generate clock in Verilog ?There are many ways to generate
clock in Verilog; you could use one of the following
methods:
Method #1
1 initial begin
2 clk = 0;
3 end
4
5 always begin
6 #5 clk = ~clk;
7
8 end
Method #2
1 initial begin
2 clk = 0;
3 forever begin
4 #5 clk = ~clk;
5 end
6 end
Method #3
1 initial begin
2 clk = 0;
3 end
4
5 always begin
6 #5 clk = 0;
7 #5 clk = 1;
8 end
There are many ways to generate clocks: you may introduce jitter, change duty cycle.
How do I test my design xyz ?
To test or verify or validate any design, you need to have a test bench; writing test
benches is as difficult as designing itself. Please refer to the Verilog tutorial section in
"Art of Writing Test Bench" for more details.
What is the difference between wire and reg ?
Please refer to tidbits section for the difference between wire and reg.
What is the difference between blocking and nonblocking
assignment ?Please refer to tidbits section for difference between blocking and
nonblocking statement.
How do I write a state machine in Verilog ?
Please refer to tidbits section for "writing FSM in Verilog".
How do I avoid Latch in Verilog ?
Latches are always bad (I don't like that statement); latches are caused when all the
possible cases of assignment to variable are not covered. Well this rule applies to
combinational blocks (blocks with edge sensitive lists are sequential blocks); let's
look at
the following example.
Bad Code
1 always @ (b or c)
2 begin
3 if (b) begin
4 a = c;
5 end
6 end
In the code above, value of a is retained, and it gets changed only when b is set to '1'.
This
results in a latch. (Need to phrase it right)
Good Code #1
1 always @ (b or c)
2 begin
3 a = 0;
4 if (b) begin
5 a = c;
6 end
7 end
In the code above, no matter what the value of b is, a gets value of '0' first and if b is
set
to '1' and c is set to '1', only then a gets '1'. This is the best way to avoid latches.
Good Code #2
1 always @ (b or c)
2 begin
3 if (b) begin
4 a = c;
5 end else begin
6 a = 0;
7 end
8 endIn the above code, all the possible cases are covered (i.e. b = 1 and b = 0 case).
How does this xyz code get synthesized ?
Well it is a long story; let me cover that in the synthesis part of Verilog tutorial. You
can
refer to Actel HDL coding Style. One simple logic is: any code inside always blocks
with
edge sensitive sensitivity list, results in flip-flops and assign; inside level sensitive
always
blocks results in combo logic.
How do I implement Memories in Verilog ?
You can implement them by declaring 2-dimension arrays. More details can be found
in
the Verilog tutorial section "Modeling memories and FSM".
How do I read and write from a file ?
To Read from a file we use $readmemh, where h stands for hex decimal. For writing
we
use $writememh, $fdisplay, $fmonitor. You could refer to the Verilog tutorial section
for
more details.
What is this `timescale compiler directive ?
`timescale is used for specifying the reference time unit for the simulator. Syntax of
the
`timescale is as below:
`timescale <reference_time_unit>/<time_precision>
example : `timescale 10ns/1ns
Timescale directive tends to make more sense at gatelevel simulation than at RTL
simulation.
Can we mix blocking and nonblocking in one always block ?
Yes, we can have both blocking and nonblocking code in same always block. Some
things that one should know to use this are:
• Blocking assignments are treated as combinational logic.
•
One should not assign a variable in the same always block with both blocking and
nonblocking assignments.
• Not all synthesis tools support this. (Design compiler supports this).What is the
output of AND gate in the circuit below, when A and B are as in
waveform? Tp is the gate delay of respective gate.
Identify the circuit below, and its limitation.
What is the current through the resistor R1 (Ic) ?Referring to the diagram below,
briefly explain what will happen if the propagation
delay of the clock signal in path B is much too high compared to path A. How do we
solve this problem if the propagation delay in path B can not be reduced ?
What is the function of a D flip-flop, whose inverted output is connected to its
input ?
Design a circuit to divide input frequency by 2.
Design a divide-by-3 sequential circuit with 50% duty cycle.Design a divide-by-5
sequential circuit with 50% duty cycle.
What are the different types of adder implementations ?
Draw a Transmission Gate-based D-Latch.
Give the truth table for a Half Adder. Give a gate level implementation of it.
What is the purpose of the buffer in the circuit below, is it necessary/redundant to
have a buffer ?
What is the output of the circuit below, assuming that value of 'X'
a := a + b;
b := a + 3;
What is uncertainty?
Synthesis is the stage in the design flow which is concerned with translating the HDL code
into gates - and that's putting it very simply! First of all, the HDL code must be written in a
particular way for the synthesis tool that you are using to infer required hardware. Of course,
a synthesis tool doesn't actually produce gates - it will output a netlist of the design that you
have synthesised that represents the chip which can be fabricated through an ASIC or FPGA
vendor.
begin
q <= a^b;
q <= a & b;
q <= a|b;
end
Fork, Join
For removing hold violations, add redundant logic in the path where there are hold violations,
as it will slow down the data path, and the data will not change in the hold window, thereby
avoiding hold violation.
NOR gate:
Multiplexer equation: Y = I1.(S) + I0.not(S)
I1 => '0' ; I0 => 'not(B)' ; S => 'A'
Y = 0.(A) + not(B).not(A)
Upon simplifying above equation, Y = not(A+B)
Q.2) Implement EX-OR and EX-NOR gates using
2-to-1 multiplexer.
Answer) EX-OR gate:
EX-NOR gate:
A or B = C ; A or C = B
AND gate,
A and B = C; A and C = B
A xor B = C; A xor C = B
A xor (A xor C) = C,
0 + A.C + not(A).C = C,
Another Implementation :
Another Implementation:
If B => '0'
Verilog Interview Questions - v1.1
Q.1) A task can have arguments of type :
A. Input only.
B. Output only.
C. Both input and output.
D. All input, output and inout.
Answer) D
Answer) C
Answer) A
Answer) B
Answer)
From the above waveform, we can derive the following equation :
= 100ps
Q.3) Calculate the hold slack for the above example. ( hold t = 100ps)
Answer)
From the above waveform, the equation for the hold slack comes as :
hold-slack = tclk-q + tcombo – thold
= 600ps
When En = 1; In = 0,
The PMOS part of the circuit conducts resulting in '1' at the output.
When En = 1; In = 1,
The NMOS part of the circuit conducts resulting in '0' at the output.
When the voltage on node X is a '1', the complementary '0' is applied to node active-low X,
allowing both transistors to conduct and pass the signal at A to B. Similarly, when the voltage
on node active-low X is a '0', the complementary '1' is applied to node A, turning both
transistors off and forcing a high-impedance condition on both the A and B nodes.
reg a, b;
initial
begin
a = 0;
#10 b = 1;
end
The execution of the procedural assignment is delayed by the number specified by the delay
control. Therefore, the 'b' assignment is delayed by the 10 time units.
initial
begin
a = 0; b = 0;
c = #10 a + b;
end
Take the value of a and b at the time = 0, evaluate a + b and then wait 10 time units to
assign value to c.
a) Value of a = 1100
b) 0Value of b = 010
c) Size is 00000400
Q.3) What will be the output of following code?
reg a,b,c;
reg [2:0] d;
initial
begin
a = 1'b0;
$display("Time %t a %b b %b c %c d %d",
$time,a,b,c,d);
b = #10 1'b1;
$display("Time %t a %b b %b c %c d %d",
$time,a,b,c,d);
c = #5 1'b0;
$display("Time %t a %b b %b c %c d %d",
$time,a,b,c,d);
d = #20 {a,b,c};
$display("Time %t a %b b %b c %c d %d",
$time,a,b,c,d);
end
Answer)
Time 0 a 0 b x c x d x
Time 10 a 0 b 1 c x d x
Time 15 a 0 b 1 c 0 d x
Time 35 a 0 b 1 c 0 d 010
Initial 3 a 0 b 1 c x d x
Initial 2 a 0 b 1 c 1 d x
Initial 4 a 0 b 1 c 1 d 0
Verilog Interview Questions - v1.4
Answer) D
Mealy Machine
In a Mealy machine, the outputs are a function of the present state and the value of inputs.
Due to this, outputs may change asynchronously with change in inputs.
Output = f(Present State, Input)
Moore Machine
In a Moore machine, the outputs depend only on the present state. In the case of Moore
Machine, the next state is calculated using the inputs and the current state. The outputs are
computed by a combinatorial logic circuit whose inputs are the state variables.
Please go through the excitation table for D - flip flop for better understanding.
Mealy FSM
State truth table
Y = In.q1
Q1 = In.q1 + In.q0
Q0 = In.not(q1).not(q0)
Y = q0.q1
Q1 = In.q0 + In.q1
Q0 = In.q1 + In.not(q0)
Synchronous and Asynchronous
resets
Reset
Reset is needed for:
Synchronous Resets
Advantages :
Disadvantages :
Since the reset input is added to combinatorial logic, hence the combinatorial logic
becomes complex.
May require a pulse stretch circuit to guarantee that a reset pulse is wide enough to
be seen at the rising clock edge.
Reset buffer tree may be required to ensure that all resets occur in the same clock
cycle.
Require a free running clock to ensure reset takes place.
Asynchronous Resets :
Based on the fact that the reset has priority over other signals, when asserted, reset occurs.
The main problem when dealing with the asynchronous resets is their removal; the
asynchronous resets need to be de-asserted synchronously.
Asynchronous Resets
Advantages :
Disadvantages :
The flop becomes sensitive to the glitches or noise present in the reset line.
The deactivation of reset of all flip flops must be synchronous.
Asynchronous Reset Problem
Problems with asynchronous de-assertion of asynchronous reset :
Reset recovery time refers to the time between when reset is de-asserted and the time that
the clock signal goes high again. Missing a recovery time can cause signal integrity or
metastability problems with the registered data outputs.
When reset removal is asynchronous to the rising clock edge, slight differences in
propagation delays in either or both the reset signal and the clock signal can cause some
registers or flip-flops to exit the reset state before others.
Reset Synchronizer
Without a reset synchronizer, the usefulness of the asynchronous reset in the final system is
void even if the reset works during simulation.
Reset Synchronizer
An external reset signal asynchronously resets a pair of master reset flip-flops, which then
drives the master reset signal asynchronously through the reset buffer tree to the rest of the
flip flops in the design. The entire design will be asynchronously reset.
Reset removal is done by de-asserting the reset signal, which in turn allows the d-input of the
first master reset flip flop to pass through the reset synchronizer. The reason for using two flip
flops is to remove any metastability that might be caused by the reset signal being removed
asynchronously and too close to the rising clock edge. As two flip flops are used , it typically
takes two active clock edges after reset removal to synchronize removal of master reset.
Removal time specifies the minimum amount of time between an active clock edge and the
release of an asynchronous control signal.
Reset Recovery time and Reset Removal time
Verilog Interview Questions - v1.5
I) initial
begin
clk = 0;
end
always
begin
end
II) initial
begin
clk = 0;
forever
begin
end
end
III) initial
begin
clk = 0;
end
always
begin
#(CLK_PERIOD/2) clk = 0;
#(CLK_PERIOD/2) clk = 1;
end
If you want to read more about setup and hold violations, go through this post.
Step I :
Design a odd number counter (in this case, counter which counts up-to 2)
2-bit counter
D0 = q1
D1 = not(q1).not(q0)
From the above simplifications, we can draw the circuit for divide by 3 counter.
Now, we have divided the input clock by 3, but the duty cycle is still not 50%. To get 50% duty
cycle, we shift the Q0 output by 90 degrees and add a gate to OR the two flip flops' output.
Please note that in above figure, the last flop has negated clock at its clock input terminal.
The above method can be extended to other odd larger by divide "N" numbers by following
the same design flow :
Design a Up or Down divide by "N" counter.
Add a flip flop to follow one of the flip flops in the counter 1/2 clock cycle.
OR the output of added flip flop with the one that is driving it to achieve 50% duty
cycle.