Docsity

cheat sheet for ee564, Cheat Sheet of Verilog and VHDL

Toggle sidebar
bg1
ECE 564 / 464 VERILOG MIDTERM FRONT: TIMING + RTL
Exam reference •delays in ns •bold numbers are worked example answers •use the course’s positive-skew-as-penalty convention
1. SETUP, HOLD, SKEW: MEMORIZE
tcq Clock edge until launching FF output Q changes.
tlogic Gate propagation delay (count gates on a path).
tsu Receiving D must be stable before edge.
thReceiving D must remain stable after edge.
tskew
Different clock arrivals; course practice treats given positive
uncertainty as a penalty.
FF →FF setup (MAX delays, slowest path):
Tclk,min =tcq,max +tlogic,max +tsu,max +tskew
Setup slack =Tclk −Tclk,min,fmax = 1/Tclk,min .
FF →FF hold (MIN delays, fastest path):
tcq,min +tlogic,min ≥th,max +tskew
Hold margin
=
tcq,min
+
tlogic,min −th−tskew
. If negative: hold violation.
A negative margin requires adding at least its magnitude as minimum delay.
Remember: setup
→
too late
→
MAX delay; hold
→
too early
→
MIN
delay. Longer clock period typically fixes setup, not hold. If a real problem
gives signed capture-minus-launch skew rather than uncertainty, its effect can
be opposite; follow the problem’s stated convention.
2. ALL FOUR PATH TYPES / SDC
FF →FF tcq +tlogic +tsu +U≤T.
Input →FF tin +tlogic +tsu +U≤T.
FF →output tcq +tlogic +tout +U≤T.
Input
→
output
Usually budget
T−tin −tout −U
(if constrained relative
to one period).
Solve unknown maximum logic delay: subtract every other delay/uncer-
tainty from the clock period. U=clo ck uncertainty/skew penalty given.
Boundary constraints: If a separate downstream module is driven by FF
output Q,
set_input_delay(max)
=
tcq,max
+
tlogic,max
from source FF to
port; do not include downstream setup. If an upstream module feeds your
FF D,
set_output_delay(max)
=
tlogic,max
+
tsu
+
U
from your input to FF
(when no other external budget). Port-specific paths matter.
Reports:
report_timing
(max) checks setup;
report_timing -min
checks hold.
Reports analyze, not repair.
compile
synthesizes;
compile -incremental
refines
an existing compilation.
3. WORKED TIMING PROBLEMS (LIKE QUIZZES)
A. Screenshot:
tcq
= (2
,
3
,
5)
, tgate
= (1
,
2
,
3)
, tsu
= (1
,
1
,
2)
, th
=
(1,1,2), U = 1.
A <= (B&C)^D; B <= (A|C)&D;
C <= (A^B)&D; D <= A^B; E <= A|D;
Longest FF
→
FF path: 2 gates (AND/XOR, OR/AND, XOR/AND).
Tmin
=
5 + 2(3) + 2 + 1 = 14 ns.
Shortest register path: 1 gate; earliest 2 + 1 = 3, hold need 2 + 1 = 3;
hold margin 0, NO violation (False). Since outputs A–E are registered,
downstream module input_delay =tcq,max =5ns.
B. Two-gate FF path (P2 Q11): clock-Q
max
= 7, gate
max
= 5 each,
setupmax = 3, U=2. Tmin = 7 + 2(5) + 3 + 2 = 22 ns.
C. HOLD direct C
→
A (P2 Q14): clock-Q
min
= 4, no gates, hold=2,
U=1; 4−(2 + 1) = +1 safety, signed “too fast” answer -1 .
D. Boundary/IO (P2 Q1, Q8): E directly captures into FF A; output-delay
budget = setup max 2+U1 =
3
. FF
→
output adder: T=14, cq=2, out=1,
U=0 ⇒max adder=14 −2−1 = 11 .
E. Input
→
FF (screenshot): T=10, in=2, U=2, setup=1
⇒
allowed logic
10 −2−2−1 = 5ns.
11. SYNOPSYS / ASIC / PORTS
ASIC choice: 3000-unit, 30 MHz, time-to-market
→
FPGA. Full-custom:
best physical control, very expensive/slow. Standard cell: automated ASIC,
sizable NRE. Gate array: quicker traditional ASIC, limited flexibility. FPGA:
reprogrammable/fast startup, higher per-unit cost/power.
Synthesis aim: minimum feasible area while meeting timing;
compile
maps
RTL,
compile -incremental
improves mapped result. Multiplication
D=A*B
may use DesignWare library elements.
Parent/child types: parent interconnect of child procedural output D =
wire D; (Verilog); inside child, procedural D is output reg D.
4. READ RTL ⇒IDENTIFY HARDWARE
assign y=a&b; AND gate; continuous combinational
assign y=s?b:a; 2:1 MUX (s=1 chooses b)
always @(*) Combinational procedural block (all
outputs assigned in all paths)
always @(posedge clk) Edge-triggered D FFs; no assignment
means hold previous value
if (rst_n==0) Assert an active-LOW reset
x<=y Nonblocking: RHS old values, updates
together
x=y Blocking: RHS reads latest earlier
blocking assignments in same procedure
Equivalent 2:1 MUX styles (choose ONE, same hardware):
assign y = sel ? b : a;
always @(*) begin
if (sel) y = b;
else y = a;
end
D flip-flop: Qafter edge =Djust before edge .
always @(posedge clk) Q <= D; // rising-edge FF
Four-state logic: 0, 1, x (unknown), z (high impedance).
reg
means proce-
dural variable, not necessarily physical register. A port driven from a child
module is typically
wire
in the parent; a signal assigned inside a procedural
always block is reg (Verilog) or logic (SystemVerilog).
5. FIND THE ERROR (TOP EXAM TARGET)
Missing branch ⇒unintended LATCH:
always @(*) if (A) D = C | B; // no else
When
A=0
, D must remember past value. Fix: b egin with
D=0;
or add
else
D=.... A latch is level-sensitive; FF is edge-sensitive.
Incomplete sensitivity ⇒simulation mismatch:
always @(A or B)
if (A) D = C | B; else D = C ^ B;
C
omitted: simulation may fail to update when C changes. Fix:
always @(*)
.
Complete if/else prevents a latch here.
Glitchy latch enable / combinational loop:
always @(*) if (A) D = B & C;
assign A = E & (B | D);
D latches when A=0, and its gate/enable A depends on D through logic.
Danger: combinational glitches on level-sensitive latch enable, unpredictable
behavior.
Multiple drivers (invalid synthesizable pattern):
always @(posedge clk) A <= B & D;
always @(*) A = E | F; // same A driven twice!
One register/net should not have conflicting procedural drivers. Some course
MCQs call this wired-or; technically it is a multiple-driver error, not a
legitimate wor net.
Correct, NOT a latch/feedback:
always @(*) begin
C = A & B; // always assigned
if (E) C = C | F; // uses just-computed C
end
Blocking assignments execute in order inside this same block; synthesizes
C= (A&B)|(E&F).
Synthesis mistake checklist: multiple procedural drivers, forgotten else/de-
fault, missing sensitivity, incorrect reset, signed/width truncation, out-of-
range indexing, combinational loops, non-terminating loops, inappropriate
#delay
/
initial
for ASIC hardware.
initial
with time delays is testbench
simulation, not ordinary ASIC sequential logic; some FPGA initialization is
supported.
6. COMPACT OPERATORS / BIT-WIDTH TRAPS
&, |, ^, ~ Bitwise AND/OR/XOR/NOT
&&, ||, ! Logical operators (truth-value tests)
^a,~^a XOR reduction = odd parity; XNOR
reduction = even parity (1 if even # of
1s)
«, », «<, »> shifts; »> sign-extends only if left
operand is signed
{a,b},{3{a}} Concatenate; replicate a 3 times
a[i],a[hi:lo] Bit select; part select
==, != vs === logical equality (x may propagate) vs
exact case equality
Example: 4’b1011 & 4’b1100 = 4’b1000.4’b1011 = 11 decimal.
Priority MUX:
if(A)... else if(B)... else if(C)... else...
tests A
first; output of each branch must be assigned; use complete coverage.
casex
treats X/Z as wildcards (possible simulation masking); prefer
casez
plus
explicit don’t-care patterns when appropriate.
9. EVEN PARITY (CHOOSE ONE METHOD)
assign parity = ~^A; // 1 for EVEN number of 1s
integer i;
always @(*) begin
parity=1’b1;
for (i=0; i<8; i=i+1) parity=parity^A[i];
end
10. PRIORITY MUX AND ROTATE (PRACTICE Q4)
always @(*) begin
if(A) H=F&G; else if(B) H=F|G;
else if(C) H=F^G; else H=D&E;
end
always @(*) begin
casex({A,B,C})
3’b1xx:H=F&G; 3’b01x:H=F|G;
3’b001:H=F^G; default:H=D&E;
endcase
end
Q4 rotate:
{a[2],a[1],a[0],a[2]}
=
b=a«1; b[0]=b[3];
c,d.
«<
is a shift, not rotate.
pf2

Partial preview of the text

Download cheat sheet for ee564 and more Cheat Sheet Verilog and VHDL in PDF only on Docsity!

ECE 564 / 464 VERILOG MIDTERM FRONT: TIMING + RTL

Exam reference • delays in ns • bold numbers are worked example answers • use the course’s positive-skew-as-penalty convention

1. SETUP, HOLD, SKEW: MEMORIZE

tcq Clock edge until launching FF output Q changes. tlogic Gate propagation delay (count gates on a path). tsu Receiving D must be stable before edge. th Receiving D must remain stable after edge. tskew Different clock arrivals; course practice treats given positive uncertainty as a penalty. FF → FF setup (MAX delays, slowest path):

Tclk, min = tcq, max + tlogic, max + tsu, max + tskew

Setup slack = Tclk − Tclk, min, fmax = 1 /Tclk, min. FF → FF hold (MIN delays, fastest path):

tcq, min + tlogic, min ≥ th, max + tskew

Hold margin = tcq, min + tlogic, min − th − tskew. If negative: hold violation. A negative margin requires adding at least its magnitude as minimum delay. Remember: setup → too late → MAX delay; hold → too early → MIN delay. Longer clock period typically fixes setup, not hold. If a real problem gives signed capture-minus-launch skew rather than uncertainty, its effect can be opposite; follow the problem’s stated convention.

2. ALL FOUR PATH TYPES / SDC

FF → FF tcq + tlogic + tsu + U ≤ T. Input → FF tin + tlogic + tsu + U ≤ T. FF → output tcq + tlogic + tout + U ≤ T. Input → output Usually budget T − tin − tout − U (if constrained relative to one period). Solve unknown maximum logic delay: subtract every other delay/uncer- tainty from the clock period. U =clock uncertainty/skew penalty given. Boundary constraints: If a separate downstream module is driven by FF output Q, set_input_delay(max) = tcq, max + tlogic, max from source FF to port ; do not include downstream setup. If an upstream module feeds your FF D, set_output_delay(max) = tlogic, max + tsu + U from your input to FF (when no other external budget). Port-specific paths matter. Reports: report_timing (max) checks setup; report_timing -min checks hold. Reports analyze , not repair. compile synthesizes; compile -incremental refines an existing compilation.

3. WORKED TIMING PROBLEMS (LIKE QUIZZES)

A. Screenshot: tcq = (2 , 3 , 5) , tgate = (1 , 2 , 3) , tsu = (1 , 1 , 2) , th = (1 , 1 , 2) , U = 1. A <= (B&C)^D; B <= (A|C)&D; C <= (A^B)&D; D <= A^B; E <= A|D; Longest FF→FF path: 2 gates (AND/XOR, OR/AND, XOR/AND). Tmin =

5 + 2(3) + 2 + 1 = 14 ns.

Shortest register path: 1 gate ; earliest 2 + 1 = 3, hold need 2 + 1 = 3; hold margin 0, NO violation (False). Since outputs A–E are registered,

downstream module input_delay = tcq,max = 5 ns.

B. Two-gate FF path (P2 Q11): clock-Q max = 7, gate max = 5 each,

setup max = 3, U=2. Tmin = 7 + 2(5) + 3 + 2 = 22 ns. C. HOLD direct C → A (P2 Q14): clock-Q min = 4, no gates, hold=2,

U=1; 4 − (2 + 1) = +1 safety, signed “too fast” answer -.

D. Boundary/IO (P2 Q1, Q8): E directly captures into FF A; output-delay

budget = setup max 2+U1 = 3. FF→output adder: T=14, cq=2, out=1,

U=0 ⇒ max adder= 14 − 2 − 1 = 11. E. Input → FF (screenshot): T=10, in=2, U=2, setup=1 ⇒ allowed logic

10 − 2 − 2 − 1 = 5 ns.

11. SYNOPSYS / ASIC / PORTS

ASIC choice: 3000-unit, 30 MHz, time-to-market → FPGA. Full-custom: best physical control, very expensive/slow. Standard cell: automated ASIC, sizable NRE. Gate array: quicker traditional ASIC, limited flexibility. FPGA: reprogrammable/fast startup, higher per-unit cost/power. Synthesis aim: minimum feasible area while meeting timing ; compile maps RTL, compile -incremental improves mapped result. Multiplication D=A*B may use DesignWare library elements. Parent/child types: parent interconnect of child procedural output D = wire D; (Verilog); inside child, procedural D is output reg D.

4. READ RTL ⇒ IDENTIFY HARDWARE

assign y=a&b; AND gate; continuous combinational assign y=s?b:a; 2:1 MUX (s=1 chooses b) always @() Combinational procedural block (all outputs assigned in all paths) always @(posedge clk) Edge-triggered D FFs; no assignment means hold previous value if (rst_n==0) Assert an active-LOW reset x<=y Nonblocking: RHS old values, updates together x=y Blocking: RHS reads latest earlier blocking assignments in same procedure Equivalent 2:1 MUX styles (choose ONE, same hardware): assign y = sel? b : a; always @() begin if (sel) y = b; else y = a; end D flip-flop: Q after edge = D just before edge. always @( posedge clk) Q <= D; // rising-edge FF Four-state logic: 0, 1, x (unknown), z (high impedance). reg means proce- dural variable, not necessarily physical register. A port driven from a child module is typically wire in the parent; a signal assigned inside a procedural always block is reg (Verilog) or logic (SystemVerilog).

5. FIND THE ERROR (TOP EXAM TARGET)

Missing branch ⇒ unintended LATCH: always @() if (A) D = C | B; // no else When A=0, D must remember past value. Fix : begin with D=0; or add else D=.... A latch is level-sensitive; FF is edge-sensitive. Incomplete sensitivity ⇒ simulation mismatch: always @(A or B) if (A) D = C | B; else D = C ^ B; C omitted: simulation may fail to update when C changes. Fix: always @(). Complete if/else prevents a latch here. Glitchy latch enable / combinational loop: always @() if (A) D = B & C; assign A = E & (B | D); D latches when A=0, and its gate/enable A depends on D through logic. Danger : combinational glitches on level-sensitive latch enable, unpredictable behavior. Multiple drivers (invalid synthesizable pattern): always @( posedge clk) A <= B & D; always @() A = E | F; // same A driven twice! One register/net should not have conflicting procedural drivers. Some course MCQs call this wired-or ; technically it is a multiple-driver error , not a legitimate wor net. Correct, NOT a latch/feedback: always @(*) begin C = A & B; // always assigned if (E) C = C | F; // uses just-computed C end Blocking assignments execute in order inside this same block ; synthesizes C = ( A & B ) | ( E & F ). Synthesis mistake checklist: multiple procedural drivers, forgotten else/de- fault, missing sensitivity, incorrect reset, signed/width truncation, out-of- range indexing, combinational loops, non-terminating loops, inappropriate #delay/initial for ASIC hardware. initial with time delays is testbench simulation, not ordinary ASIC sequential logic; some FPGA initialization is supported.

6. COMPACT OPERATORS / BIT-WIDTH TRAPS

&, |, ^, ~ Bitwise AND/OR/XOR/NOT &&, ||,! Logical operators (truth-value tests) ^a, ~^a XOR reduction = odd parity; XNOR reduction = even parity (1 if even # of 1s) «, », «<, »> shifts; »> sign-extends only if left operand is signed {a,b}, {3{a}} Concatenate; replicate a 3 times a[i], a[hi:lo] Bit select; part select ==, != vs === logical equality (x may propagate) vs exact case equality Example: 4’b1011 & 4’b1100 = 4’b1000. 4’b1011 = 11 decimal. Priority MUX: if(A)... else if(B)... else if(C)... else... tests A first; output of each branch must be assigned; use complete coverage. casex treats X/Z as wildcards (possible simulation masking); prefer casez plus explicit don’t-care patterns when appropriate.

9. EVEN PARITY (CHOOSE ONE METHOD)

assign parity = ~^A; // 1 for EVEN number of 1s integer i; always @(*) begin parity=1’b1; for (i=0; i<8; i=i+1) parity=parity^A[i]; end

10. PRIORITY MUX AND ROTATE (PRACTICE Q4)

always @() begin if (A) H=F&G; else if (B) H=F|G; else if (C) H=F^G; else H=D&E; end always @() begin casex ({A,B,C}) 3’b1xx:H=F&G; 3’b01x:H=F|G; 3’b001:H=F^G; default :H=D&E; endcase end Q4 rotate: {a[2],a[1],a[0],a[2]} = b=a«1; b[0]=b[3]; c,d. «< is a shift, not rotate.

ECE 564 / 464 VERILOG MIDTERM BACK: TEMPLATES + PRACTICE

Exam practice prompts paired with answers. Full controller code at lower left; right side reserved for handwritten notes.

7. RESET, WAVEFORMS, CLOCK EDGES

Active-low reset (common, NOT mandatory): reset_n=0 means reset ON, reset_n=1 means normal. Why often used? Many FF cells have active-low clear pins and a default pull-up can leave reset inactive. Always follow the design spec ; active-high/synchronous resets are also valid. always @( posedge clk or negedge reset_n) if (!reset_n) q <= 0; // async active-low else q <= d; // Synchronous reset: always @(posedge clk) // if (!reset_n) q <= 0; else q <= d; Timing diagram recipe: (1) get initial state; (2) sample inputs just BE- FORE active edge; (3) compute all clocked RHS from OLD FF values; (4) apply all <= updates TOGETHER; (5) re-evaluate combinational outputs; (6) repeat. Never use newly updated FF in another <= RHS at same edge. // old A=0, B=1, C= always @( posedge clk) begin A <= B; B <= C; C <= A; end // after edge: A=1, B=1, C= Blocking order nuance (practice Q3): B=A; A=C; gives B=old A, A=old C; changing both to <= gives SAME resulting values for this order. Answer: True (not every blocking/nonblocking change is equivalent!). Testbench delays are relative/cumulative: initial begin A=0; #10 A=1; #20 A=0; end // times 0, 10, 30 (NOT 0,10,20)

8. FSM: 3-STATE MOORE TEMPLATE

module fsm( input clk,reset_n,go, output reg done); reg [1:0] s,ns; localparam WAIT=0,PROCESS=1,DONE=2; always @( posedge clk or negedge reset_n) if (!reset_n) s <= WAIT; else s <= ns; always @(*) begin ns=s; done=0; // defaults prevent latches case (s) WAIT: if (go) ns=PROCESS; PROCESS: ns=DONE; DONE: begin done=1; ns=WAIT; end default : ns=WAIT; endcase end endmodule

Moore outputs depend on state; Mealy on state + inputs. Binary N states: ⌈log 2 N ⌉ FFs; one-hot: N FFs. Workflow: identify I/O → datapath → controls → FSM → RTL.

12. QUESTIONS + ANSWERS: PRACTICE PDF AND

SCREENSHOTS

P = “Midterm Practice 2” PDF; S = provided screenshot. P1. Preceding module’s output delay when input E goes straight into A FF, setup=2, U=1? 3 ns P2. Child module assigns D procedurally; what net type connects its output in parent? wire P3. B=A; A=C; at clock edge: replacing both = with <= same behavior? True P4. Which snippets implement the same 4-bit rotate (concatenation vs shift+bit replace)? c,d P5. Verilog versus VHDL advantages? Not applicable (per quiz) P6. Difference between compile and compile -incremental? Refines compiled design P7. Why is initial B=2’b11; problematic in ASIC synthesis? Initial not ASIC reset P8. T=14, FF clock-Q=2, output delay=1, U=0: max A+B path? 11 ns P9. if(A) D=B&C; and A=E&(B|D): best reason for error? Glitchy latch enable P10. For In=4’b1011, {|In, In[In[1:0]], {2{In[2]}}} in decimal? 12 P11. Two gates max 5 each; FF clock-Q=7, setup=3, skew=2: min period? 22 ns P12. 10k portable medical units, power matters moderately: choose implementation? Tradeoff; likely FPGA P13.* C=A&B; if(E) C=C|F; has what error? Nothing wrong P14. Direct C-to-A FF hold: cq,min=4, hold=2, U=1; “too fast” signed answer? - ns P15. Clocked and combinational always both assign A: problem? Multiple drivers S1. 30 MHz, 8-bit controller, 3000 units, very fast market entry: best device? FPGA S2. Clock-Q max 5; 2 gates max 3; setup max 2; U=1: minimum T? 14 ns S3. Min Q=2, shortest gate=1, hold max 2, skew=1: hold violation? No (0 margin) S4. Prior module’s registered outputs have cq,max 5 and no output logic: next input delay? 5 ns S5. T=10, input delay 2, uncertainty 2, setup 1: max input-to-FF logic? 5 ns S6. Synopsys synthesis of D=AB;: maps multiplier using which library? DesignWare S7. What does report_timing -min check? Hold / min paths S8. A=0; #10 A=1; #20 A=0; changes at what times? 0,10, S9. When does continuous assign y=f(a,b) re-evaluate? RHS changes S10. always @(A or B) uses C too: what is wrong? Missing C sensitivity S11. always @() if(A) D=C|B; (no else) infers what? Latch S12. Main purpose of timing-constrained Synopsys compile? Min area; meet timing *P12 depends on actual price/power/qualification constraints; no unique technology follows from the prompt alone. Last-minute diagnostic: Determine which FF launches / captures , count real series gates (NOT number of operators in entire module), use MAX for setup/MIN for hold, account for skew and constraints, and separately distinguish “clocked reg”, “transparent latch”, and “combinational output”.

FULL CONTROLLER CODE (LEFT) & YOUR HANDWRITTEN NOTES (RIGHT).

COMPLETE 3-STATE FSM CONTROLLER (SYSTEMVERILOG)

module controller ( input logic clk, input logic reset_n, input logic go, output logic done );

localparam [1:0] WAIT = 2’d0, PROCESS = 2’d1, DONE = 2’d2;

logic [1:0] state, next_state;

// State register always @( posedge clk or negedge reset_n) begin if (!reset_n) state <= WAIT; else state <= next_state; end

// Next-state and output logic always @(*) begin next_state = state; done = 1’b0; case (state) WAIT: begin if (go) next_state = PROCESS; end PROCESS: begin next_state = DONE; end DONE: begin done = 1’b1; next_state = WAIT; end default : begin next_state = WAIT; end endcase end endmodule