Verilog Slides 2 PDF
Verilog Slides 2 PDF
▪ Structure (Plumbing)
• Verilog program build from modules with I/O interfaces
• Modules may contain instances of other modules
• Modules contain local signals, etc.
• Module configuration is static and all run concurrently
▪ 0, 1
• Obvious
▪ Z
• Output of an undriven tri-state driver
• Models case where nothing is setting a wire’s value
▪ X
• Models when the simulator can’t decide the value
• Initial state of registers
• When a wire is being driven to 0 and 1 simultaneously
• Output of a gate with Z inputs
0 1 X Z
▪ look like
initial always
begin begin
… imperative statements … … imperative statements …
end end
initial begin
#10 a = 1; b = 0;
#10 a = 0; b = 1;
end
sum = a + b + cin;
case (op)
2’b00: y = a + b;
2’b01: y = a – b;
2’b10: y = a ^ b;
default: y = ‘hxxxx;
endcase
i = 0;
while (I <= 15) begin
output = i;
#10 i = i + 1;
end
reg q;
▪ Fundamental problem:
• In a synchronous system, all flip-flops sample
simultaneously
• In Verilog, always @(posedge clk) blocks run in some
undefined sequence
a = 1; a <= 1;
b = a; b <= a;
c = b; c <= b;
a = 1;
b = a; “ 1
a b c
”
c = b;
1 a
a <= 1;
b <= a; “ b ”
c <= b;
c
Stimulus
▪ #42
• Schedule process to resume 42 time units from now
▪ wait(cf & of)
• Resume when expression “cf & of” becomes true
▪ @(a or b or y)
• Resume when a, b, or y changes
▪ @(posedge clk)
• Resume when clk changes from 0 to 1
while (~ready)
count = count + 1;
▪ Instead, use
wait(ready);
▪ Sequential:
reg q;
always @(d or clk) q only assigned when
if (clk) q = d; clk is 1
always @(a or b)
f is not assigned
case ({a, b}) when {a,b} = 2b’11
2’b00 : f = 0;
2’b01 : f = 1;
2’b10 : f = 1;
endcase
always @(a or b)
case ({a, b})
2’b00: f = 0; f is always assigned
2’b01: f = 1;
2’b10: f = 1;
default: f = 0;
endcase