module clk_div #(
parameter DIVIDE_NUM = 3
)(
input wire sys_clk,
input wire sys_rst_n,
output wire div_clk
);
reg [7:0] count;
reg clk_rise, clk_fall, clk_even;
wire clk_odd;
always@(posedge sys_clk or negedge sys_rst_n)
if(!sys_rst_n)
count <= 0;
else if(count == DIVIDE_NUM-1)
count <= 0;
else
count <= count + 1;
/***********用于产生奇数分频的上升沿下降沿控制时钟*********/
always@(posedge sys_clk or negedge sys_rst_n)
if(!sys_rst_n)
clk_rise <= 0;
else if(count < (DIVIDE_NUM+1)/2)
clk_rise <= 1;
else
clk_rise <= 0;
always@(negedge sys_clk or negedge sys_rst_n)
if(!sys_rst_n)
clk_fall <= 0;
else if(count < (DIVIDE_NUM+1)/2)
clk_fall <= 1;
else
clk_fall <= 0;
assign clk_odd = clk_rise & clk_fall;
/************
Verilog实现任意数值时钟分频(50%占空比)
最新推荐文章于 2024-04-20 14:54:57 发布