问题:如何在低频率的周期信号产生一个短脉冲信号?
1)首先利用时钟计数产生一个周期信号;
2)其次利用计数器产生一个短脉冲信号。
代码如下:
module Adv(clk_5m,rst,clk_25hz,trigger);
input clk_5m;
input rst;
output clk_25hz;
output trigger;
reg [17:0]cnt;
reg clk_25hz;
//reg trigger;
wire trigger;
always @(posedge clk_5m or negedge rst)
if(!rst)
cnt <= 0;
else if(cnt<199999)
cnt <= cnt+1;
else
cnt <= 0;
always @(posedge clk_5m or negedge rst)
if(!rst)
clk_25hz <= 0;
else if(cnt<99999)
clk_25hz <= 1;
else
clk_25hz <= 0;
assign trigger = ((cnt>=0)&&(cnt<10))?1:0;
endmodule
仿真代码如下:
`timescale 1ns/1ns
`define clk_period 200 //200ns=5Mhz
//定义模块
module Adv_tb;
//定义激励接口(信号发生器接口)
reg clk_5m_tb;
reg rst_tb;
wire clk_25hz_tb;
wire trigger_tb;
//连线(信号发生器信号接入