【问题标题】:verilog- assign statement reg to output variable not being assignedverilog-将语句 reg 分配给未分配的输出变量
【发布时间】:2014-10-11 22:59:13
【问题描述】:

我正在尝试将 FPGA 用作带有 pwm 的某些 LED 的移位寄存器,但在尝试分配包含移入输出变量的值的 reg 时遇到错误。当我将它上传到 FPGA 时(我正在使用嵌入式 micro 的 mojo),它什么也不做。当我使用模拟器时,它报告所有输出变量都没有被赋值并且具有 X 的值,而模块内的所有其他变量都可以正常工作。这是我的移位模块代码:

module shifting(
    input clk,
    input shiftingpin,//data to be shifted in
    input rst,
    output done,
    output [3:0]data//pwm compare value output
    );
reg [2: 0] ctr_d, ctr_q;
reg don;
reg [3:0]datas;
always @(*) begin
     if(ctr_q == 3'b100) begin
        ctr_d[2:0] = 3'b0;
        don = 1'b1;
     end else begin
       ctr_d = ctr_q + 1'b1;
        don = 1'b0;
     end
end
always @(posedge clk) begin
     datas[ctr_q] = shiftingpin;// assign value to the output
    if (rst) begin
        ctr_q <= 1'b0;
    end else begin
        ctr_q <= ctr_d;
    end
end
assign data = datas;
assign done = don;
endmodule 

done 告诉包含模块何时更新并将值分配给 pwm。

【问题讨论】:

  • 您可以添加模拟输入的 tb 代码吗? (另请注意,将 shiftpin 存储到数据的行应该是非阻塞的:datas[ctr_q] &lt;= shiftingpin;

标签: verilog fpga assign shift-register


【解决方案1】:

如果我正确理解了这个问题,那么您在尝试从 always 块内驱动端口时会遇到语法错误。

在声明端口时,默认情况下它们通常是有线的,只能由端口驱动或分配。导致下面的代码

module shifting(
    input        clk,
    input        shiftingpin,
    input        rst,
    output       done,
    output [3:0] data
);
reg           don; 
reg [3:0]     datas;
assign done = don;    
assign data = datas;

解决方案

解决方案是将端口定义为reg,如果您可以支持System Verilog,则首选逻辑。 logic 将根据需要有效地在 wire 和 reg 之间切换,以使重构代码更容易。

module shifting(
    input             clk,
    input             shiftingpin,
    input             rst,
    output reg        done,
    output reg  [3:0] data
);
always @(posedge clk) begin
 data[ctr_q] <= shiftingpin; // <-- data port used directly
//...

注意:移位寄存器只需

always @(posedge clk) begin
  datas[3:0] <= {datas[2:0], shiftingpin};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    • 2018-04-02
    • 2017-01-07
    • 1970-01-01
    相关资源
    最近更新 更多