Beruflich Dokumente
Kultur Dokumente
Logistics
Variables
The rule
CSE370, Lecture 16
Example: A D flip-flop
CSE370, Lecture 16
CSE370, Lecture 16
always example
module and_gate
input
output
reg
always block
Sequential Verilog
Sequential Verilog
CSE370, Lecture 16
Saves a value
Today
reg
Last lecture
wire
CSE370, Lecture 16
Assignments
always @(a)
always
f = a & b;
CSE370, Lecture 16
CSE370, Lecture 16
2 rules:
1) Include all inputs in the sensitivity list
2) Use complete assignments
Every path must lead to an assignment for out
8
Otherwise out needs a state element
if
f = a & b;
f = a & b;
Same as C if statement
CSE370, Lecture 16
if (another way)
10
case
always @(sel or A or B or C or D)
if (sel[0] == 0)
if (sel[1] == 0) Y = A;
else
Y = B;
else
if (sel[1] == 0) Y = C;
else
Y = D;
endmodule
always @(sel
case (sel)
2b00: Y
2b01: Y
2b10: Y
2b11: Y
endcase
endmodule
CSE370, Lecture 16
11
CSE370, Lecture 16
or A or B or C or D)
=
=
=
=
A;
B;
C;
D;
default case
always @(A)
case (A)
8b00000001: Y = 0;
If you omit the default, the compiler will
8b00000010: Y = 1;
create a latch for Y
8b00000100: Y = 2;
Either list all 256 cases
8b00001000: Y = 3;
Or use a function (compiler will
8b00010000: Y = 4;
warn you of missing cases)
8b00100000: Y = 5;
8b01000000: Y = 6;
8b10000000: Y = 7;
default: Y = 3bx; // Dont care about other cases
endcase
endmodule
CSE370, Lecture 16
13
0;
1;
2;
3;
4;
5;
6;
7;
Y = 3bx;
// simple encoder
module encode (A, Y);
input [7:0] A;
output [2:0] Y;
reg
[2:0] Y;
integer i;
reg
[7:0] test;
CSE370, Lecture 16
forever statement
Example: Swap
16
Blocking assignments (Q = A)
//
//
//
//
Verilog while/repeat/forever
14
for
CSE370, Lecture 16
CSE370, Lecture 16
17
CSE370, Lecture 16
18
Swap
reg B, C, D;
always @(posedge clk)
begin
B = A;
C = B;
D = C;
end
reg B, C, D;
always @(posedge clk)
begin
B <= A;
C <= B;
D <= C;
end
CSE370, Lecture 16
19
CSE370, Lecture 16
20
assign E = A & D;
assign A = B & C;
21
CSE370, Lecture 16
E
D
CSE370, Lecture 16
22
Synthesis examples
wire [3:0] x, y, a, b, c, d;
assign apr = ^a;
assign y = a & ~b;
assign x = (a == b) ?
a + c : d + a;
a
c
+
x
+
c
d
d
==
==
b
b
CSE370, Lecture 16
23
CSE370, Lecture 16
24
Truncation
wire [7:0] a = 8hAB;
wire b;
wire [7:0] c;
assign c = a;
CSE370, Lecture 16
CSE370, Lecture 16
25
Simple rule:
within a block,
blocking
assignments,
are in order
CSE370, Lecture 16
29
27
CSE370, Lecture 16
26
CSE370, Lecture 16
28