鱼C论坛

 找回密码
 立即注册
查看: 1509|回复: 0

流水灯testbench激励

[复制链接]
发表于 2021-11-8 15:26:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
module ledwater(
input clk,
input rst_n,
input x,
output  reg [7:0] Y
);


reg [2 : 0] state;
reg [31 : 0]cnt;
reg clk_div;

parameter
                        S0=0,
                        S1=1,
                        S2=2,
                        S3=3,
                        S4=4,
                        S5=5,
                        S6=6,
                        S7=7;

//******************分频模块************************//
always@(posedge clk or negedge rst_n)
begin
        if(!rst_n)
        begin
                cnt<=0;
                clk_div<=0;
        end
        else if(cnt==32'd5_000_000)
                        begin
                        clk_div<=~clk_div;
                        cnt<=0;
                        end
        else
                        cnt<=cnt+1;
end

always@(posedge clk_div or negedge rst_n)
begin
        if(!rst_n)
        begin
        Y[7:0]<=8'b0000_0000;
        state<=S0;
        end
        else
        case(state)
        S0:
          begin
            Y[7:0]<=8'b0000_0001;
                 if(x==1)
                   state<=S0;
                 else
                   state<=S1;
          end
        S1:
          begin
            Y[7:0]<=8'b0000_0010;
                 if(x==1)
                   state<=S1;
                 else
                   state<=S2;
          end
        S2:
          begin
            Y[7:0]<=8'b0000_0100;
                 if(x==1)
                   state<=S2;
                 else
                   state<=S3;
          end  
        S3:
          begin
            Y[7:0]<=8'b0000_1000;
                 if(x==1)
                   state<=S3;
                 else
                   state<=S4;
          end
        S4:
          begin
            Y[7:0]<=8'b0001_0000;
                 if(x==1)
                   state<=S4;
                 else
                   state<=S5;
          end
        S5:
          begin
            Y[7:0]<=8'b0010_0000;
                 if(x==1)
                   state<=S5;
                 else
                   state<=S6;
          end
        S6:
          begin
                 Y[7:0]<=8'b0100_0000;
                 if(x==1)
                   state<=S6;
                 else
                   state<=S7;
          end
        S7:
          begin
            Y[7:0]<=8'b1000_0000;
                 if(x==1)
                   state<=S7;
                 else
                   state<=S0;
          end
        default: begin Y[7:0]<=8'b0000_0000;state<=S0; end
        endcase
end


endmodule
这是Verilog代码,testbench的激励怎么写?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-28 16:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表