一个数字倍频电路

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

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 declaration

11 reg temp_mul ;

12 //////////////////////////////////////////////////////////////////////////////

13 // logic

14 always @(posedge clk_out or negedge rst_n) begin

15 if(~rst_n) temp_mul <= 1'b0 ;

16 else temp_mul <= #2 ~temp_mul ;

17 end

18 assign clk_out = ~(clk ^ ~temp_mul) ;

19 //////////////////////////////////////////////////////////////////////////////

20

21 endmodule // CREATED by poiu_elab@1207

22

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 generation

13 initial forever #(`CLK_CYCLE/2) clk = ~clk;

14 initial begin

15 rst_n = 1'b0 ;

16 clk = 1'b1 ;

17 #500;

18 rst_n = 1'b1 ;

19 #5000;

20 $stop;

21 end

22 ///////////////////////////////////////////////////////////////////////////////

23 // module instaniation

24 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@1207

32

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倍频时钟。

Copyright © 2022 九州天命装备站 - 装备获取&角色养成活动 All Rights Reserved.