verilog程序——模块化,parameter和localparam的使用,Generate使用

本文通过脉冲计数器的例子,介绍了Verilog中模块化的实现,探讨了parameter和localparam在参数化设计中的应用,以及Generate语句在自动生成结构中的使用,展示了如何在FPGA设计中提高代码复用性和灵活性。
摘要由CSDN通过智能技术生成

脉冲计数器,

实验一:进行模块化复用

pulse_counter为基础脉冲计数器,为被复用模块

`timescale 1ns/1ps

module pulse_counter(
	input clk,
	input rst_n,
	output reg[3:0] pulse_cnt,
	output reg pulse
    );
	
localparam CNT_MAX=10;
always@(posedge clk)begin
	if(!rst_n) pulse_cnt=0;
	else if(pulse_cnt<CNT_MAX)begin
		pulse_cnt=pulse_cnt+1'b1;
	end
	else pulse_cnt=0;
end

always@(posedge clk)begin
	if(!rst_n) pulse<=0;
	else if(pulse_cnt==CNT_MAX) pulse<=1;
	else pulse<=0;
end

endmodule

 

multi_pulse.v


`timescale 1ns/1ps

module multi_pulse(
	input clk1,
	input clk2,
	input rst_n,
	output [3:0] pulse_cnt1,
	output [3:0] pulse_cnt2
    );

wire pulse1;
wire pulse2;

pulse_counter pulse_counter1(
	.clk(clk1),
	.rst_n(rst_n),
	.pulse_cnt(pulse_cnt1),
	.pulse(pulse1)
    );

pulse_counter pulse_counter2(
	.clk(clk2),
	.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值