偶分频(八分频)

八分频意味着时钟在一半的时刻就要取反(1~7的计数,在3就要判断发生翻转)

方式1 最常见的方式,但是在高精度情况使用容易出现误差

module oufenpin(
						input wire sys_clk,
						input wire rst_n,
						
						output reg clk
    );
parameter  M=4'd8;   //分频数


reg [2:0] count;     


always@(posedge sys_clk or negedge rst_n)
	if (!rst_n)
		count <=1'b0;
	else if (count == M/2-1'b1)
		count <= 1'b0;
	else
		count <= count +1'b1;
		
		
always @(posedge sys_clk or negedge rst_n)
	if (!rst_n)
		clk <= 0;
	else if (count == M/2-1'b1)
		clk <= ~clk;
	else
		clk <= clk;
		
endmodule

方式2 用标志位的形式做分频,具体有点像八分频,高低电平有不同占空比(7低1高)

module oufenpin(
						input wire sys_clk,
						input wire rst_n,
						
						output reg clk_flag
    );
parameter  M=4'd8;


reg [2:0] count;


always@(posedge sys_clk or negedge rst_n)
	if (!rst_n)
		count <=1'b0;
	else if (count == M-1)
		count <= 1'b0;
	else
		count <= count +1'b1;
		
		
always @(posedge sys_clk or negedge rst_n)   //在每一个计数周期的最后一个时钟周期clk_flag置为高电平
	if (!rst_n)
		clk_flag <= 0;
	else if (count == M-2)
		clk_flag <= 1'b1;
	else
		clk_flag <= 0;
		
endmodule
module vtf_oufenpin;

	// Inputs
	reg sys_clk;
	reg rst_n;

	// Outputs
	wire clk_flag;

	// Instantiate the Unit Under Test (UUT)
	oufenpin uut (
		.sys_clk(sys_clk), 
		.rst_n(rst_n), 
		.clk_flag(clk_flag)
	);

	initial begin
		// Initialize Inputs
		sys_clk = 0;
		rst_n = 0;

		// Wait 100 ns for global reset to finish
		#100;
		rst_n <= 1'b1;
		
		
        
		// Add stimulus here

	end
		always #10 sys_clk = ~sys_clk;
      
endmodule

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值