昨夜风 发表于 2023-10-30 22:08:15

疑惑求解

本帖最后由 昨夜风 于 2023-10-30 22:13 编辑



module water_led
#(parameter CNT_MAX=25'd24_999_999)
(
input wire clk,
input wire rst_n,
output wire led_out
);
reg cnt;
reg cnt_flag;
reg led_out_reg;
always@(posedge clk ornegedge rst_n)
if(rst_n==1'b0)
cnt<=25'd0;
else if(cnt==CNT_MAX)
cnt<=25'd0;
else
cnt<=cnt+25'd1;

always@(posedge clk ornegedge rst_n)
if(rst_n==1'b0)
cnt_flag<=1'b0;
else if(cnt==(CNT_MAX-25'd1))
cnt_flag<=~cnt_flag;
else
cnt_flag<=cnt_flag;

always@(posedge clk ornegedge rst_n)
if(rst_n==1'b0)
led_out_reg<=4'b0001;
else if((led_out_reg==4'b1000) && (cnt_flag==1'b1))
led_out_reg<=4'b0001;
else if(cnt_flag==1'b1)
led_out_reg<=led_out_reg <<1'b1;
else
led_out_reg<=led_out_reg;

assign led_out=~led_out_reg;
endmodule

上述代码中,如果去除cnt_flag的那部分代码,然后把 else if((led_out_reg==4'b1000) && (cnt_flag==1'b1))其中的(cnt_flag==1'b1)替换成(CNT_MAX-25'd1)有和区别?(求大佬解答)

页: [1]
查看完整版本: 疑惑求解