net8 if-else case 作业

 

 

 

有负的值就离谱 为啥啊。。。

原来是 8的时候为1000 首位为1所以显示成负数了 好家伙。。。

那没事了

module net8(
    input    wire    clk,
    input    wire     rst,
    output    reg        [3:0]po_cnt);

always @(posedge clk or posedge rst) begin
    if (rst) begin
        // reset
        po_cnt<=0;
    end
    else 
        begin
        if (po_cnt==15)           这个if  else删掉的话仿真结果一样  因为设置的最大值4位为  15  大于这个的为10000  但是显示不出来 只能显示0000  所以注意这个错误 要严谨。
        po_cnt<=0;
        
        else 
            po_cnt<=po_cnt+1'b1;
        end    
    
end

endmodule
`timescale    1ns/1ns
module    tb_net8();
reg    clk;
reg    rst;
wire    [3:0]po_cnt;

initial
begin
    clk=0;
    rst=1;
    #10    rst=0;
end

always #5    clk=~clk;

net8 tb_net8_inst(
    .clk(clk),
    .rst(rst),
    .po_cnt(po_cnt));

endmodule

 

posted @ 2021-07-21 22:43  涛大林  阅读(83)  评论(0)    收藏  举报