Advertisement
potterhead2003

Digital Clock YT

Jul 27th, 2021 (edited)
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer:
  5. //
  6. // Create Date:    12:31:50 11/22/2016
  7. // Design Name:
  8. // Module Name:    clock
  9. // Project Name:
  10. // Target Devices:
  11. // Tool versions:
  12. // Description:
  13. //
  14. // Dependencies:
  15. //
  16. // Revision:
  17. // Revision 0.01 - File Created
  18. // Additional Comments:
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////
  21. module clock(
  22.     input           clk,
  23.     input           reset,
  24.     output reg [6:0]    segments,
  25.     output reg [3:0]    anodes
  26.     );
  27.  
  28. reg [32:0]  count;
  29. reg         clr_count;
  30. reg [5:0]   mins;
  31. reg         clr_mins;
  32. reg [4:0]   hrs;
  33. reg         clr_hrs;
  34.  
  35. wire [6:0] mins_mss;
  36. wire [6:0] mins_lss;
  37. wire [6:0]  hrs_mss;
  38. wire [6:0]  hrs_lss;
  39.  
  40. reg  [31:0] seg_count;
  41.  
  42. // Count   
  43. always@(posedge clk)
  44.     if(reset || clr_count)  count <= #1 0;
  45.     else                    count <= #1 count+1;
  46.  
  47. always@* clr_count = count == 33'd5_999_999_999;
  48. //always@* clr_count = count == 33'd99_999_999;
  49. // Minutes Counter
  50. always@(posedge clk)
  51.     if(reset || clr_mins)   mins <= #1 0;
  52.     else if(clr_count)      mins <= #1 mins+1;
  53.  
  54. always@* clr_mins = clr_count & (mins == 6'd59);
  55.  
  56. // Hrs Counter
  57. always@(posedge clk)
  58.     if(reset || clr_hrs)    hrs <= #1 0;
  59.     else if(clr_mins)       hrs <= #1 hrs+1;
  60.  
  61. always@* clr_hrs = clr_mins & (hrs == 5'd23);
  62.  
  63. // Segments
  64. segments mins_seg(
  65.     .number     (mins),
  66.     .segments   ({mins_mss,mins_lss})
  67.     ); 
  68.    
  69. segments hrs_seg(
  70.     .number     ({1'b0,hrs}),
  71.     .segments   ({hrs_mss,hrs_lss})
  72.     ); 
  73.    
  74. // Segments counter
  75. always@(posedge clk)
  76.     if(reset)   seg_count <= #1 0;
  77.     else        seg_count <= #1 seg_count+1;
  78.    
  79. always@*
  80.     case(seg_count[19:18])
  81.     2'd0: segments = ~mins_lss;
  82.     2'd1: segments = ~mins_mss;
  83.     2'd2: segments =  ~hrs_lss;
  84.     2'd3: segments =  ~hrs_mss;
  85.     endcase
  86.    
  87.    
  88. always@*
  89.     case(seg_count[19:18])
  90.     2'd0: anodes = 4'b1110;
  91.     2'd1: anodes = 4'b1101;
  92.     2'd2: anodes = 4'b1011;
  93.     2'd3: anodes = 4'b0111;
  94.     endcase
  95.    
  96.    
  97.    
  98.    
  99.    
  100.    
  101.    
  102.    
  103.    
  104.    
  105.    
  106.    
  107.  
  108. endmodule
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement