This module defines a state machine with 4 states (S0, S1, S2, S3) that cycles through each state every 4 milliseconds. It uses a clock counter, change signal, and current/next state registers to sequence through the states. Based on the current state, it assigns a value to the an output to activate one of 4 7-segment displays.
This module defines a state machine with 4 states (S0, S1, S2, S3) that cycles through each state every 4 milliseconds. It uses a clock counter, change signal, and current/next state registers to sequence through the states. Based on the current state, it assigns a value to the an output to activate one of 4 7-segment displays.
This module defines a state machine with 4 states (S0, S1, S2, S3) that cycles through each state every 4 milliseconds. It uses a clock counter, change signal, and current/next state registers to sequence through the states. Based on the current state, it assigns a value to the an output to activate one of 4 7-segment displays.
begin if (btn[0]) begin clock_count <= 32'd0; change <= 1'b0; end else if (clock_count != n) begin clock_count <= clock_count + 1'b1; change <= 1'b0; end else begin clock_count <= 32'd0; change <= 1'b1; end end
always@(posedge mclk) // sequential part
begin if (btn[0]) state <= `S0; else state <= n_state; end
always@(state or change) // combinational part
begin if (change == 1'b1) begin case(state) `S0: n_state <= `S1; `S1: n_state <= `S2; `S2: n_state <= `S3; `S3: n_state <= `S0; default: n_state <= `S0; endcase end else begin case(state) `S0: n_state <= `S0; `S1: n_state <= `S1; `S2: n_state <= `S2; `S3: n_state <= `S3; default: n_state <= `S0; endcase end end
always@(state) // output part
begin case(state) `S0: an <= 4'b1110; `S1: an <= 4'b1101; `S2: an <= 4'b1011; `S3: an <= 4'b0111; default: an <= 4'b1111;