Glitch free safe clock switching 

From: http://www.vlsi-world.com/content/view/64/47/1/2/

Safe and Glitch free clock switching
Digital circuits are often running in different clock domains. In many circumstances the clock of these circuits need to be switched while the logic (circuit) is running. The clock switching can be done in analog circuit or in digital circuit. The Implementations in this page give details of clock switching digitally. The simplest way of clock switching can be done with simple multiplexers.
Simple clock switch
Two clocks are multiplexed and selected by a signal which is generated from the internal logic. The following circuit shows the clock switching using a multiplexer. Above circuit can be described in Verilog as follows.

Glitch free safe clock switching
Clock Switch with simple Mux

In the above circuit when select is ‘1’ clk_b forwarded to the output and when select is ‘0’ clk_b forwarded to the output. The switching of these clock are combination to the select signal that is selects signals immediately (on-the-fly) switches the clock with out respect of the state of the both clocks. This is not safe some time, like the following simulation of the above circuit.
Glitch free safe clock switching
Simulation Output with Simple Mux (Note the Glitch)

The simulation output shows a Glitch on the clock path. It is due to the ‘select’ signal goes up just before the clk_b is going down. These glitches are very hazardous for any circuits. If the width of the glitch is too small they are sensed by some flip-flops and some will not. Due to this problem the output of the complete circuit is undetermined. These glitches are also leads into Metastability problems. Since glitches are very short pulses it may violate the setup and hold time of the flip-flops and output of these flip-flops are in quasi state (outputs are not determined as ‘1’ or ‘0’). Verilog realization of proceeded circuit follows.

 

 1Glitch free safe clock switching`timescale 1ns/10ps
 2Glitch free safe clock switchingmodule clk_switch (
 3Glitch free safe clock switching  // Outputs
 4Glitch free safe clock switching    out_clk,   
 5Glitch free safe clock switching  // Inputs  
 6Glitch free safe clock switching    clk_a,
 7Glitch free safe clock switching    clk_b,
 8Glitch free safe clock switching    select    );  
 9Glitch free safe clock switching   input clk_a;  
10Glitch free safe clock switching   input clk_b;  
11Glitch free safe clock switching   input select;  
12Glitch free safe clock switching   output out_clk; 
13Glitch free safe clock switching   reg out_clk;
14Glitch free safe clock switching   always @ (select or clk_a or clk_b)
15Glitch free safe clock switching   begin   
16Glitch free safe clock switching       if select == 1
17Glitch free safe clock switching          out_clk <= clk_a;   
18Glitch free safe clock switching       else      
19Glitch free safe clock switching          out_clk <= clk_b;
20Glitch free safe clock switching       end
21Glitch free safe clock switchingendmodule

 Glitch free safe clock switch implementation

The logic is little complex than the simple clock switch, the clock switching will not happen immediately after switching the select signal. This circuit allows both clock settle down and switches the new clock to the circuit. It eliminates glitch or spikes in the clock signal. The safe clock switch circuit is implemented as in the following diagram.

Glitch free safe clock switching
Safe Clock switch circuit

Following figure shows the simulation of glitch free safe clock switch. For both implementations same test bench is used. Code for the test bench is available at end of the article.
Glitch free safe clock switching

Above circuit works well with related and unrelated clock. Related clocks means both clocks come from the same clock source (they are in phase) un-related clocks (they are not in the phase) are not come from the same clock source.
In this implementation the select signal registered it makes sure that the there will not be any change in the output while both clocks are high. First stage flip-flops remove the meta-stability problem. Verilog implementation for glitch free clock switch.

 

 1Glitch free safe clock switching`timescale 1ns/100ps
 2Glitch free safe clock switchingmodule clk_switch (
 3Glitch free safe clock switching   // Outputs
 4Glitch free safe clock switching   out_clk,
 5Glitch free safe clock switching   // Inputs
 6Glitch free safe clock switching   clk_a, clk_b, select
 7Glitch free safe clock switching   );
 8Glitch free safe clock switching
 9Glitch free safe clock switching   input clk_a;
10Glitch free safe clock switching   input clk_b;
11Glitch free safe clock switching   input select;
12Glitch free safe clock switching
13Glitch free safe clock switching   output out_clk;
14Glitch free safe clock switchingwire   out_clk;
15Glitch free safe clock switching
16Glitch free safe clock switchingreg q1,q2,q3,q4;
17Glitch free safe clock switchingwire or_one, or_two,or_three,or_four;
18Glitch free safe clock switching
19Glitch free safe clock switchingalways @ (posedge clk_a)
20Glitch free safe clock switchingbegin
21Glitch free safe clock switching    if (clk_a == 1'b1)
22Glitch free safe clock switching    begin
23Glitch free safe clock switching       q1 <= q4;
24Glitch free safe clock switching       q3 <= or_one;
25Glitch free safe clock switching    end
26Glitch free safe clock switchingend
27Glitch free safe clock switching
28Glitch free safe clock switchingalways @ (posedge clk_b)
29Glitch free safe clock switchingbegin
30Glitch free safe clock switching    if (clk_b == 1'b1)
31Glitch free safe clock switching    begin
32Glitch free safe clock switching        q2 <= q3;
33Glitch free safe clock switching        q4 <= or_two;
34Glitch free safe clock switching    end
35Glitch free safe clock switchingend
36Glitch free safe clock switching
37Glitch free safe clock switchingassign or_one   = (!q1) | (!select);
38Glitch free safe clock switchingassign or_two   = (!q2) | (select);
39Glitch free safe clock switchingassign or_three = (q3)  | (clk_a);
40Glitch free safe clock switchingassign or_four  = (q4)  | (clk_b);
41Glitch free safe clock switching
42Glitch free safe clock switchingassign out_clk  = or_three & or_four;
43Glitch free safe clock switching
44Glitch free safe clock switchingendmodule                         

 TestBench

 1Glitch free safe clock switching`timescale 1ns/10ps
 2Glitch free safe clock switching
 3Glitch free safe clock switchingmodule tb_clk_switch;
 4Glitch free safe clock switching
 5Glitch free safe clock switching   reg  clk_a;
 6Glitch free safe clock switching   reg  clk_b;
 7Glitch free safe clock switching   wire out_clk;
 8Glitch free safe clock switching
 9Glitch free safe clock switching   reg select;
10Glitch free safe clock switching
11Glitch free safe clock switching   initial
12Glitch free safe clock switching     begin
13Glitch free safe clock switching        select <= 1'b0;
14Glitch free safe clock switching        clk_a   <= 1'b1;
15Glitch free safe clock switching        clk_b   <= 1'b1;
16Glitch free safe clock switching        #87.2
17Glitch free safe clock switching        select <= 1'b1;
18Glitch free safe clock switching        #81.9
19Glitch free safe clock switching        select <= 1'd0;
20Glitch free safe clock switching        #50
21Glitch free safe clock switching        $stop;
22Glitch free safe clock switching     end
23Glitch free safe clock switching
24Glitch free safe clock switching   always #5.7   clk_a = ~clk_a;
25Glitch free safe clock switching   always #2.5   clk_b = ~clk_b;
26Glitch free safe clock switching
27Glitch free safe clock switchingclk_switch ins1 (
28Glitch free safe clock switching   .clk_a(clk_b),
29Glitch free safe clock switching   .clk_b(clk_a),
30Glitch free safe clock switching   .select(select),
31Glitch free safe clock switching   .out_clk(out_clk)
32Glitch free safe clock switching   );
33Glitch free safe clock switchingendmodule

 

 


 

相关文章:

  • 2021-08-28
  • 2021-12-15
  • 2021-10-16
  • 2021-07-04
  • 2022-12-23
  • 2021-07-25
  • 2021-06-10
  • 2021-09-11
猜你喜欢
  • 2022-01-15
  • 2022-01-06
  • 2022-12-23
  • 2021-12-27
  • 2021-09-23
  • 2021-07-08
  • 2022-12-23
相关资源
相似解决方案