Professional Documents
Culture Documents
Current
State
State
Memory
Input Next
Inputs State D Q
Forming D Q
Logic
Output Outputs
Forming
Logic
module ff(
input wire logic clk, d,
D Q
output logic q
d q
);
endmodule
module ff(
input wire logic clk, load, d,
output logic q
0 );
D Q q
d 1
always_ff @(posedge clk)
if (load)
load
clk q <= d;
endmodule
C D
B
B
Q A
clk CLK
endmodule
logic[3:0] Q;
always_ff @(posedge clk)
begin Q[3] <= Q[2];
Q <= {Q[2:0],Q[3]} Q[2] <= Q[1];
Q[1] <= Q[0];
end Q[0] <= Q[3];
Without a reset or D Q D Q D Q D Q
load, this circuit can D Q D Q D Q D Q
never be initialized. CLK CLK CLK CLK
CLK CLK CLK CLK
clk
clk
parameter WID=8;
rst
logic[WID-1:0] count; clr
logic enable, reset; enable EN
module swapper (
input wire logic clk, load, swap,
0
0 input wire logic a, b,
1
D Q output logic out1, out2
a out1 );
1
swap
always_ff @(posedge clk)
load clk if (?)
begin
out1 <= a; A. !load
out2 <= b;
0
end B. load
0
D Q
else if (?)
begin C. !swap
1
b 1
out2 out1 <= out2;
out2 <= out1;
D. swap
end
swap
load clk endmodule
module swapper (
input wire logic clk, load, swap,
0
0 input wire logic a, b,
1
D Q output logic out1, out2
a out1 );
1
swap
always_ff @(posedge clk)
load clk if (load)
begin
out1 <= a;
out2 <= b;
end
0
0 else if (swap)
1
D Q begin
b out2 out1 <= out2;
1
out2 <= out1;
end
swap
load clk endmodule
clr
clk
module delay4 (
input wire logic clk, SerIn,
output logic[3:0] Q
Q[3] Q[2] Q[1] Q[0] );
module delay3 (
input wire logic clk,
input wire logic SerIn,
output logic Q
);
a b logic a, b;
SerIn D Q D Q D Q Q
always_ff @(posedge clk)
begin
CLK CLK CLK a <= SerIn;
b <= a;
Q <= b;
end
endmodule
module delay3 (
input wire logic clk,
input wire logic SerIn,
output logic Q
);
logic a, b;
a b
SerIn D Q D Q D Q Q
always_ff @(posedge clk)
begin
Q <= b;
CLK CLK CLK
b <= a;
a <= SerIn;
end
endmodule
Order of assignments DOES NOT MATTER…
8:1 MUX
Write Reg3 );
n
Decoder DataOut
Reg4 n n=16
logic [15:0] registers [8];
Reg5
n
Reg6
n
// The synchronous write logic
Reg7
always_ff @(posedge clk)
n if (regWE)
m=3 n=16 registers[Addr] <= ;
regWE DataIn clk
// The asynchronous read logic
Addr
assign DataOut = ;
endmodule
module regFile (
input wire logic clk, regWE,
Reg0 input wire logic [2:0] Addr,
n
Reg1
n input wire logic [15:0] DataIn,
Register write signals
endmodule
A Register File
input wire logic [2:0] Addr,
input wire logic [15:0] DataIn,
output logic[15:0] DataOut
);
logic[15:0] Reg0,Reg1,Reg2,Reg3,
Reg4,Reg5,Reg6,Reg7;
if (regWE)
Reg2 case(Addr)
n
8:1 MUX
Reg3 3’b000: Reg0 <= DataIn;
Write n
Decoder DataOut 3’b001: Reg1 <= DataIn;
Reg4 n n=16 3’b010: Reg2 <= DataIn;
Reg5 3’b011: Reg3 <= DataIn;
n
3’b100: Reg4 <= DataIn;
Reg6
n 3’b101: Reg5 <= DataIn;
Reg7 3’b110: Reg6 <= DataIn;
n
default: Reg7 <= DataIn;
m=3 n=16 endcase
regWE DataIn clk
// The asynchronous read logic
Addr assign DataOut = (Addr==3’000)? Reg0:
(Addr==3’001)? Reg1:
…….
reg7;
endmodule
© 2018 BYU ECEn 220 30