Advertisement
Krystian102

Untitled

Apr 1st, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module zad3(
  2.     input [0:0] KEY,
  3.     input CLOCK_50,
  4.     output [0:6] HEX0);
  5.    
  6.     wire [3:0] out;
  7.     counter_mod_M(KEY[0],CLOCK_50,out);
  8.     decoder_hex_16(out,HEX0);
  9.    
  10. endmodule
  11.  
  12. module counter_mod_M
  13.     #(parameter M=10)
  14.     (input aclr, clk,
  15.     output [3:0] h);
  16.    
  17.     localparam N=clogb2(M-1);
  18.     function integer clogb2(input [31:0] v);
  19.     for(clogb2=0;v>0;clogb2=clogb2+1)
  20.         v=v>>1;
  21.     endfunction
  22.    
  23.    
  24.     wire clockTact;
  25.    
  26.     reg [N-1:0] Q;
  27.     assign h=Q;
  28.    
  29.     counter_to_make_delay ex0(clk, aclr, clockTact);
  30.    
  31.     always@(posedge clockTact, negedge aclr)
  32.         if(!aclr) Q<=1'd0;
  33.         else
  34.             begin
  35.                 if(Q==M-1) Q<=1'd0;
  36.                 else Q<=Q+1;
  37.             end
  38.    
  39. endmodule
  40.  
  41. module counter_to_make_delay(
  42.     input clk, aclr,
  43.     output reg clockTact);
  44.    
  45.     reg [25:0] i;
  46.    
  47.     always@(posedge clk, negedge aclr)
  48.         if(!aclr)
  49.             begin
  50.                 i<=0;
  51.                 clockTact<=0;
  52.             end
  53.         else
  54.             begin
  55.                 if(i==3)
  56.                     begin
  57.                         i<=0;
  58.                         clockTact<=1;
  59.                     end
  60.                 else
  61.                     begin
  62.                         i<=i+1;
  63.                         clockTact<=0;
  64.                     end
  65.             end
  66.    
  67. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement