fpga入门 10位计数器

本文详细介绍了Verilog语言中设计的一个计数器模块(counter.v),包括输入信号、输出信号以及计数逻辑。同时提供了测试模块(counter_test.v)来验证计数器功能,通过时钟和复位信号控制计数过程。

一、 counter.v

module counter
(
    input       wire            sclk,
    input       wire            rst_n,
    output      wire    [9:0]   cnt
);


reg     [9:0]   cnt_r = 0;


always@(posedge sclk or negedge rst_n)
    if(rst_n == 1'b0)
        cnt_r <= 10'd0;
    else
        cnt_r <= cnt_r +1'b1;

assign cnt = cnt_r;

endmodule


*/
    
endmodule

二、 counter_test.v

`timescale 1ns/100ps

module counter_test();

//==========================================
//定义reg型输入变量
reg sclk;
reg rst_n;
//输出
wire [9:0] cnt;


initial
    begin
        sclk    <= 1'b0;
        rst_n   <= 1'b1;
        #100
        rst_n   <= 1'b0;
        #100
        rst_n   <= 1'b1;
    end

always #10 sclk = ~sclk;

counter counter_inst
(
    .sclk(sclk),
    .rst_n(rst_n),
    .cnt(cnt)
);


endmodule

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值