Verilog 代码片段


//********************hujsq

    reg [()-1:0]        cnt_hu;
    wire                add_cnt_hu;
    wire                end_cnt_hu;
always @(posedge sys_clk or negedge sys_rst_n)begin
    if (!sys_rst_n)
        cnt_hu <=0;
    else if(add_cnt0)    begin
        if(end_cnt)
            cnt_hu<=0;
        else
            cnt_hu<=cnt_hu+1;
        end
end
    
assign add_cnt_hu=;
assign end_cnt_hu=add_cnt_hu && (cnt== max_cnt_hu-1);

//********************hushixu
always @(posedge sys_clk or negedge sys_rst_n)begin
    if (!sys_rst_n)begin
        
    end
    else if() begin
        
    end
    else if() begin

    end
end


//********************
    


//********************hufsm
//hufsm
    parameter    IDLE    =4'b0000;
    parameter    S1        =4'b0001;
    parameter    S2        =4'b0010;
    parameter    S3        =4'b0100;
    reg [3:0]    state_cur;
    reg [3:0]    state_next;
    wire idle_to_s1;
    wire s1_to_s2;
    wire s2_to_idl;
    
//状态迁移
    always@(posedge clk or negedge rst_n)begin
        if(!rst_n)begin
            state_cur<= IDLE;
        end
        else begin
            state_cur<= state_next;
        end
    end
    
//组合逻辑,状态改变的判定条件
    always@(*)begin
        case(state_cur)
            IDLE:begin
                    if(idle_to_s1)begin
                        state_next = S1;
                    end
                    else begin
                        state_next = state_cur;
                        end
                end
            S1:begin
                    if(s1_to_s2)begin
                        state_next = S2;
                    end
                    else begin
                        state_next = state_cur;
                    end
                end
            S2:begin
                if(s2_to_idl)begin
                    state_next = IDLE;
                end
                else begin
                    state_next = state_cur;
                end
            end
            default:begin
                state_next = IDLE;
                end
        endcase
    end
    
    //转移条件
    assign idle_to_s1 = state_cur==IDLE && ();
    assign s1_to_s2 =state_cur==S1 && ();
    assign s2_to_idl =state_cur==S2 && ();
    
    //执行输出
    always @(posedge clk or negedge rst_n)begin
        if(!rst_n)begin
            out1 <=1'b0
            end
        else if(state_cur==S1)begin
            out1 <= 1'b1;
            end
        else begin
            out1 <= 1'b0;
            end
    end
//********************

//********************hutb
`timescale 1 ns/1 ns
 
module testbench_name();
    reg sys_clk  ;
    reg sys_rst_n;
 
    reg[3:0]  din0  ;
    reg       din1  ;
 
 
//uut的输出信号
    wire      dout0;
    wire[4:0] dout1;
 
 
//时钟周期,单位为ns,可在此修改时钟周期。
    parameter CYCLE    = 20;
 
//复位时间,此时表示复位3个时钟周期的时间。
    parameter RST_TIME = 3 ;
 
//待测试的模块例化
module_name uut(
    .clk          (clk     ), 
    .rst_n        (rst_n   ),
    .din0         (din0    ),
    .din1         (din1    ),
    .dout0        (dout0   ),
    .dout1        (dout1   )
 
);
 
 
//生成本地时钟50M
initial begin
    clk = 0;
    forever
    #(CYCLE/2)
    clk=~clk;
end
 
//产生复位信号
initial begin
    rst_n = 1;
    #2;
    rst_n = 0;
    #(CYCLE*RST_TIME);
    rst_n = 1;
end
 
//输入信号din0赋值方式
initial begin
    #1;
    //赋初值
    din0 = 0;
    #(10*CYCLE);
    //开始赋值
 
end
 
//输入信号din1赋值方式
initial begin
    #1;
    //赋初值
    din1 = 0;
    #(10*CYCLE);
    //开始赋值
 
end

endmodule
//********************

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值