1/2占空比的五分频电路实现

方法:先实现一个按时钟上升沿的五分频器,同样的分频方法,实现一个以下降沿触发的五分频器,然后把两个分频器的输出相或,就可以得到占空比为50%的五分频电路。

`timescale 1ns / 1ps
//
// Company: 
// Engineer: 
// 
// Create Date:    09:56:59 07/09/2012 
// Design Name: 
// Module Name:    fre 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//
module fre(
    input clk,
    input reset,
    output clko ,
	 output clk1 ,
	 output clk2 
    );
	 reg out1=0, out2=0 ;
	 reg [2:0] count1= 0 ,count2 = 0   ;
	 
 always @ (posedge clk or posedge reset)
 begin
 if (reset)
     count1 <= 0 ;
 else begin
			count1 <= count1 + 1 ; 
			if (count1 == 2)  
				out1 <= ~out1 ;
			if (count1 == 4) begin
			   out1 <= ~out1 ;
				count1 <=0 ;
			   end   
		end
 end
 
 
 always @ (negedge clk or posedge reset)
 begin
 if (reset)
     count2 <= 0 ;
 else begin
			count2 <= count2 + 1 ; 
			if (count2 == 2)  
				out2 <= ~out2 ;
			if (count2 == 4) begin
			   out2 <= ~out2 ;
				count2 <=0 ;
			   end   
		end
 end
 assign clk1 = out1 ;
 assign clk2 = out2 ;
 assign clko = out1|out2 ;
 

endmodule



你可能感兴趣的:(硬件编程,dependencies,output,input,comments,module,date)