【verilog每日一练】generate-for语句的使用 - FPGA开发者技术社区 - 电子技术william hill官网 - 广受欢迎的专业电子william hill官网 - 威廉希尔官方网站
分享 收藏 返回

Mill 关注 私信
[问答]

【verilog每日一练】generate-for语句的使用

若信号test_in[7:0]表示8bit测试信号,需定义8个计数器对每1bit输入信号进行计数,若其中1bit测试信号为高电平,则对应的计数器累加1,若输入为低电平则停止计数

image.png

回帖(6)

hehung

2023-8-24 13:33:19
reg [7:0] test_in;  
reg [31:0] test_in_cnt[7:0];

genvar i;
generate
  for(i=0; i<8; i=i+1) begin
    always @(posedge clk) begin
      if (test_in[i])
        test_in_cnt[i] <= test_in_cnt[i] + 1;
      else
        test_in_cnt[i] <= test_in_cnt[i];
    end
  end
endgenerate

jf_84491108

2023-8-24 16:34:43
reg [7:0] test_in;  
reg [31:0] test_in_cnt[7:0];

genvar i;
generate
  for(i=0; i<8; i=i+1) begin
    always @(posedge clk) begin
      if (test_in[i])
        test_in_cnt[i] <= test_in_cnt[i] + 1;
      else
        test_in_cnt[i] <= test_in_cnt[i];
    end
  end
endgenerate

zealsoft

2023-8-24 16:37:40
begin
      if (test_in[i])
        test_in_cnt[i] <= test_in_cnt[i] + 1;
      else
        test_in_cnt[i] <= test_in_cnt[i];
end

jf_99074111

2023-8-24 21:02:35
      if (test_in[i])
          test_in_cnt[i] <= test_in_cnt[i] + 1'b1;
      else
          test_in_cnt[i] <= test_in_cnt[i];

更多回帖

×
发帖