Verilog 在always块中生成语句,是否可能?

Verilog 在always块中生成语句,是否可能?,verilog,Verilog,我想知道更多关于Generate语句的信息我知道你可以复制模块,并且总是阻塞(就像在另一篇文章中一样),但是, 有可能创建这样一个参数化案例吗 always @ (negedge clk) begin if (state==1) begin case(CS_sel) begin generate genvar i; for (i=0; i<N_DACS; i=i+1) begin: fo

我想知道更多关于Generate语句的信息我知道你可以复制模块,并且总是阻塞(就像在另一篇文章中一样),但是, 有可能创建这样一个参数化案例吗

always @ (negedge clk) 
 begin
if (state==1)
  begin
     case(CS_sel)
    begin
        generate
           genvar i;
           for (i=0; i<N_DACS; i=i+1)
         begin: for1
            i:begin
               num <= mod_in[(i+1)*BITS-1:i*BITS];
               div <= mod_out[(i+1)*BITS-1:i*BITS];
            end // i:
             end    // for1
        endgenerate
        default: begin
           num <= mod_in[BITS-1:0];
           div <= mod_out[BITS-1:0];
        end // default
    end  // case (CS_sel)
     endcase // case (CS_sel)
  end // if (state==1)
  end // always
始终@(negedge clk)
开始
如果(状态==1)
开始
个案(政务司司长)
开始
生成
genvar i;

对于(i=0;i生成块不能在always块内使用,而必须放在always块外。因此,实际上可以构建多个不同的always块,并通过generate if构造在它们之间进行选择

但仅通过查看给定的代码,我建议使用不同的方法,使用固定宽度和灵活偏移的适当切片:

if(CS_sel < N_DACS) begin
    num <= mod_in[BITS*CS_sel +:BITS];
    div <= mod_out[BITS*CS_sel +:BITS];
end else begin 
    //default stuff
    num <= mod_in[BITS-1:0];
    div <= mod_out[BITS-1:0];
end
if(CS_sel谢谢,我以前看过那篇文章,但它并没有解决我的疑问。我真的不明白“预期用途场景”。你能详细说明一下“在verilog中创建同步多路复用器”吗?通过看这段代码,我想知道为什么你不使用类似于
if(CS_selwire [BITS-1:0] subset0;

assign subset0 = mod_in >> (BITS*CS_sel);
[...]
num <= subset0[BITS-1:0];