3/6交替计数器(奕斯伟数字IC实习面试)
//面试官要求写出3和6交替的计数器,第一次计数3,第二次计数6,这样交替计数 module cnt( input clk_80MHz, input rst_n ); //3和6的计数器 reg [2:0] cnt; reg [1:0] c_state, n_state; parameter state_0 = 0; parameter state_1 = 1; always @(posedge clk_80MHz&nbs***bsp;negedge rst_n) begin if (!rst_n) begin c_state <= state_0; end else begin c_state <= n_state; end end always @(*) begin case (c_state) state_0 : n_state = (cnt == 3'd3) ? state_1 : state_0; state_1 : n_state = (cnt == 3'd6) ? state_0 : state_1; default: ; endcase end always @(posedge clk_80MHz&nbs***bsp;negedge rst_n) begin if (!rst_n) begin cnt <= 3'd0; end case (c_state) state_0 : begin if (cnt == 3'd3) begin cnt <= 3'd0; end else begin cnt <= cnt + 1'b1; end end state_1 : begin if (cnt == 3'd6) begin cnt <= 3'd0; end else begin cnt <= cnt + 1'b1; end end default: ; endcase end endmodule
#数字IC实习生#