一个数字倍频电路

来源:互联网 发布:nba费舍尔数据 编辑:程序博客网 时间:2024/05/24 06:41

这个就是原理图,奉上代码

复制代码
 1 ///////////////////////////////////////////////////////////////////////////// 2 //  DATE    :   Wed Jun  6 22:58:17 CST 2012 3 ///////////////////////////////////////////////////////////////////////////// 4 module clk_mul( 5     input   wire            clk 6 ,   input   wire            rst_n 7 ,   output  wire            clk_out 8 ); 9 //////////////////////////////////////////////////////////////////////////////10 // variable declaration11 reg     temp_mul    ;12 //////////////////////////////////////////////////////////////////////////////13 // logic14 always @(posedge clk_out or negedge rst_n) begin15     if(~rst_n)                      temp_mul    <=  1'b0            ;16     else                            temp_mul    <=  #2 ~temp_mul    ;17 end18 assign  clk_out =   ~(clk ^ ~temp_mul)  ;19 //////////////////////////////////////////////////////////////////////////////20 21 endmodule   //          CREATED by poiu_elab@120722 23 //////////////////////////////////////////////////////////////////////////////
复制代码

 

这个东西很简单的,但是要注意,它的核心是第16行的#2,这里的延时(占空比)可以通过电路的Tco和经过反相器的时间来搞定(其中可以插入一些buffer来调节时间),testbench这么来写(很简单,但是便于下面解释延时对占空比的影响还是附上)。

复制代码
 1 /////////////////////////////////////////////////////////////////////////////// 2 //  DATE    :   Wed Jun  6 23:00:31 CST 2012 3 /////////////////////////////////////////////////////////////////////////////// 4 `define CLK_CYCLE   20 5 module tb(); 6 /////////////////////////////////////////////////////////////////////////////// 7 // variable declaration 8 reg             clk         ; 9 reg             rst_n       ;10 wire            clk_out     ;11 ///////////////////////////////////////////////////////////////////////////////12 // stimulation generation13 initial forever #(`CLK_CYCLE/2) clk = ~clk;14 initial begin15     rst_n           =   1'b0            ;16     clk             =   1'b1            ;17 #500;18     rst_n           =   1'b1            ;19 #5000;20 $stop;21 end22 ///////////////////////////////////////////////////////////////////////////////23 // module instaniation24 clk_mul u_clk_mul(25     .clk        (   clk     )26 ,   .rst_n      (   rst_n   )27 ,   .clk_out    (   clk_out )28 );29 ///////////////////////////////////////////////////////////////////////////////30 31 endmodule   //          CREATED by poiu_elab@120732 33 ///////////////////////////////////////////////////////////////////////////////
复制代码

 

下面给出仿真图,当#2的时候,是这样的,其中你要关心的其实是~temp_mul & clk, 当你要是q端经过反相器的信号与接入的clk信号相同的时候你的clk_out就会起来,之后你的q端翻转了的话,你的clk_out就会落下来,这时候在下一个clk翻转的时候,你的~temp_mul & clk就会又要把clk_out拉起来,q端又翻转,以此类推,就可以继续在每个clk的跳变沿出现你的clk_out的高电平,调整你的Tco和反相器延时就可以调整你的高电平时间,由于周期又是固定的,这样就可以调整你的占空比。

 

而当#5的时候,是这样的

看出什么端倪了没,当你的延时,正好是时钟周期的1/4的时候,你就可以得到一个占空比是50%的2倍频时钟。



原创粉丝点击