野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 293|回复: 0

[altera] 疑惑求解

[复制链接]
发表于 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 [3:0] led_out
);
reg [24:0] cnt;
reg cnt_flag;
reg [3:0] led_out_reg;
always@(posedge clk or  negedge 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 or  negedge 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 or  negedge 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)有和区别?(求大佬解答)

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-4-29 09:35 , Processed in 0.112344 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表