寒くなってきたような気がする。
カウンター回路?っぽいものを使おうとして、
わざわざcntを何度も呼び出す必要ないよなぁ
とか考えていじったけど大して効率が良くなったわけではなく…。
state 2'h2 がいらない子っぽいんだよねぇ
このままだと、1clock分無駄にしてるし。
module count28( input clk, input reset, output [3:0] cnt ); reg [27:0] count; reg [1:0] state; // reg [3:0] cnt; assign cnt[3:0] = count[27:24]; always @ (posedge clk or negedge reset) if (!reset) begin // cnt <= 4'h0; count <= 28'h0000000; state <= 2'h0; end else begin case(state) 2'h0: begin count <= 28'h0000000; // cnt <= 4'h0; state <= 2'h1; end 2'h1: begin count <= count + 28'h0000001; // cnt[3:0] <= count[27:24]; if(count == 28'hfffffff) begin state <= 2'h2; end end 2'h2: begin // cnt <= 4'h0; state <= 2'h0; end endcase end endmodule
追記
module count28( input clk, input reset, output [3:0] cnt // output sys_clk ); reg [27:0] count; // reg [1:0] state; // reg [3:0] cnt; assign cnt[3:0] = count[27:24]; // assign sys_clk = count[24]; always @ (posedge clk or negedge reset) if (!reset) begin count <= 28'h0000000; end else begin count <= count + 28'h0000001; end endmodule
結局こうなった。