在做一个60进制计数器,顶层模块调用数码管模块,在仿真的时候输出值一直是X
顶层模块代码:
module counter(
input clk,
input clear,
input en,
output [7:0] an,
output [6:0] sseg
);
reg[3:0] count0,count1;
reg[25:0]count00;
always@(posedge clk)
begin
if(clear)
begin
count1<=0;
count0<=0;
count00<=0;
end
else if(en)
begin
if(count00=='d9999999)
begin
count00<=0;
if(count0==4'b1001)
begin
count0<=4'b0;
if(count1==4'b0101)
count1<=4'b0;
else
count1<=count1+1;
end
else
count0<=count0+1;
end
else
count00<=count00+1;
end
end
pip pip_1(
.clk(clk),
.rst(clear),
.count0(count0),
.count1(count1),
.an(an),
.sseg(sseg)
);
endmodule
子模块代码:
```c
module pip(
input clk,
input rst,
input [3:0] count0,
input [3:0] count1,
output reg [7:0] an,
output reg [6:0] sseg
);
localparam N=20;
reg[N-1:0] cnt;
reg[3:0] hex;
always@(posedge clk)
begin
if(rst)
begin
cnt=0;
hex=4'd10;
end
else
begin
cnt=cnt+1;
case(cnt[N-1])
1'b0:
begin
hex=count0;
an=8'b11111110;
end
1'b1:
begin
hex=count1;
an=8'b11111101;
end
endcase
end
end
always@(*)
case(hex)
4'h0:sseg[6:0]=7'b0000001;
4'h1:sseg[6:0]=7'b1001111;
4'h2:sseg[6:0]=7'b0010010;
4'h3:sseg[6:0]=7'b0000110;
4'h4:sseg[6:0]=7'b1001100;
4'h5:sseg[6:0]=7'b0100100;
4'h6:sseg[6:0]=7'b0100000;
4'h7:sseg[6:0]=7'b0001111;
4'h8:sseg[6:0]=7'b0000000;
4'h9:sseg[6:0]=7'b0000100;
default:sseg[6:0]=7'b1111111;
endcase
endmodule
module counter_tb(
);
reg clear;
reg clk;
reg en;
wire [6:0]sseg;
wire [7:0]an;
counter uut(
.clk(clk),
.en(en),
.clear(clear),
.an(an),
.sseg(sseg)
);
pip tuu(
.clk(clk),
.rst(clear),
.an(an),
.sseg(sseg)
);
initial
begin
clk = 0;
clear = 0;
en = 1;
end
always #5 clk = ~clk;
endmodule
仿真代码:
```c
verilog的实验设计,属实是不会了