Advertisement
redsees

Untitled

Feb 3rd, 2016
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // D-Flip Flop implementation
  2.  
  3. module dff(input clk,rst,d, output reg q);
  4. always@(posedge clk or posedge rst)
  5. begin
  6.     if (rst)
  7.         q = 1'b0;
  8.     else
  9.         q = d;
  10. end
  11. endmodule
  12.  
  13. // 4x1 Multiplexer
  14.  
  15. module mux4x1(input wire[3:0] x, input wire[1:0] cnt, output out);
  16.  
  17. assign out = (cnt == 2'b00)?(x[0]):((cnt == 2'b01)?(x[1]):((cnt == 2'b10)?(x[2]):(x[3]))) ;
  18.  
  19. endmodule
  20.  
  21. // Clock Divider Circuit with controlling switch
  22.  
  23. module clkdiv(input clk,rst, input wire[1:0] sw, output out);
  24.  
  25. wire[26:0] clkdiv;
  26. wire[26:0] din;
  27.  
  28.  
  29. dff dff_int0(.clk(clk),.rst(rst),.d(din[0]),.q(clkdiv[0]));
  30.  
  31. genvar i;
  32. generate
  33.     for(i=1;i<26;i=i+1)
  34.         dff dff_inst(.clk(clkdiv[i-1]),.rst(rst),.d(din[i]),.q(clkdiv[i]));
  35. endgenerate
  36.  
  37. mux4x1 mux_inst(.x({clkdiv[23],clkdiv[24],clkdiv[25],clkdiv[26]}),.cnt(sw),.out(out));
  38.  
  39. assign din = ~clkdiv;
  40.  
  41. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement