【HDLBits习题详解 5】CS450(更新中......)

1. Cs450/timer

module top_module (
    output 	reg			tc,
	input 				clk, 
	input 				load, 
	input 		[9:0] 	data
);
    reg [9:0] counter;
    
    always @(posedge clk) begin
        if (load == 1'b1) begin
            if (data == 10'd0) begin
                tc <= 1'b1;
            end else begin
            	tc <= 1'b0;
            end
        end else if (counter == 10'd1) begin
            tc <= 1'b1;
        end else begin
            tc <= tc;
        end
    end
    
    always @(posedge clk) begin
        if (load == 1'b1) begin
            counter <= data;
        end else if (counter == 10'd0) begin
            counter <= counter;
        end else begin
            counter <= counter + 10'h3ff;
        end
    end
endmodule

2. Cs450/counter 2bc

module top_module
#(
	parameter SNT	= 0,
    parameter WNT	= 1,
    parameter WT	= 2,
    parameter ST	= 3
)
(
    output 	[1:0] 	state,
    input 			clk,
    input 			areset,
    input 			train_valid,
    input 			train_taken
);
    reg [1:0] sta;
    reg [1:0] nex_sta;
    
    // 状态值更新
    always @(posedge clk, posedge areset) begin
        if (areset == 1'b1) begin
            sta <= ;
        end else begin
            sta <= nex_sta;
        end
    end
    
    // 状态转移表
    always @(*) begin
        case (sta)
            
        endcase
    end
    
    // 输出赋值
    
endmodule

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值