Advertisement
seethesatyrrise

Untitled

Jun 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module cnt ( clk , clrn , ena , out) ;
  2.     input clk , clrn , ena;
  3.     output logic [3:0] out;
  4.     enum logic [0:3] {s0,s1,s2,s3,s4,s5,s6,s7} state, next_state;
  5.    
  6.     always_ff @ (posedge clk or negedge clrn) begin
  7.         if (!clrn) state <= s0;
  8.         else state <= next_state;
  9.     end
  10.    
  11.     always_comb begin
  12.     case (state)
  13.         s0: next_state = s5;
  14.         s1: next_state = s6;
  15.         s2: next_state = s7;
  16.         s3: next_state = s0;
  17.         s4: next_state = s1;
  18.         s5: next_state = s2;
  19.         s6: next_state = s3;
  20.         s7: next_state = s4;
  21.     endcase
  22.     end
  23.    
  24.     always @ (state) begin
  25.         case (state)
  26.             s0: out = 3'b000;
  27.             s1: out = 3'b001;
  28.             s2: out = 3'b010;
  29.             s3: out = 3'b011;
  30.             s4: out = 3'b100;
  31.             s5: out = 3'b101;
  32.             s6: out = 3'b110;
  33.             s7: out = 3'b111;
  34.             default: out= 3'b000;
  35.         endcase
  36.     end
  37. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement