1

我一直在尝试获取我一时兴起的代码。在大多数情况下,我认为我确信模块本身是好的。它是抛出所有错误的测试台。

这是完整的代码:

/*
Primitive code to control a stepper motor using FPGA
It will run as a seconds hand
9 June 2016
dwiref024
*/

module clock_divider(clock, reset, clock_div);

input clock;
input reset;

output clock_div;
reg [25:0]counter = 26'd0;

// Assuming a clock frequency of 40Mhz
// log2(40M) = 25.25
// Therefore 40MHz corresponds to MOD25
always@(posedge clock, negedge reset)   begin
    if(!reset) begin
        counter <= 26'd0;   
    end

    if(counter == 26'd40000000) begin
        counter <= 26'd0;
    end

    else begin
    counter <= counter + 1;
    end

end

assign clock_div = counter[24]; // Gives you a clock signal 'clock_div'of approximate frequency 1Hz

initial begin
    $dumpvars(0, clock, reset, counter);
end
endmodule

module count_seconds (
input clock_div, reset
);
reg [5:0]seconds = 6'd0;

always@(posedge clock_div, negedge reset) begin
    if (!reset) begin
        seconds <= 0;
    end
    else if (seconds == 6'd60) begin
        seconds <= 0;
    end

    else begin
        seconds <= seconds + 1;
    end
end
initial begin
    $dumpvars (0, clock_div, seconds);
end

endmodule

module get_servo(
input clock_div,
output reg servoPin = 0, 
output reg ding
);

always@(posedge clock_div)  begin
    if(clock_div)
        ding <= 1;
    else
        ding <= 0;
end
always@(ding)   begin

    if (ding) begin
        servoPin = 1'b1;
    end
    else servoPin = 1'b0;
end


initial begin
    $dumpvars (0, servoPin);
end

endmodule

module clk_tb;
reg clock;
reg reset;
reg servoPin;
reg clock_div;
reg ding;
initial begin
    clock = 0;
    reset = 0;  
    repeat(2) #10 clock = ~clock;
    reset = 1;
    forever #10 clock = ~clock; 
end

clock_divider DUT1 (clock, reset, clock_div);
get_servo DUT2 (clock_div, servoPin, ding);

initial begin
    servoPin = 1'b1;
    #1 clock_div = 1'b0;
    $finish;
end

endmodule

运行时

$ icarusverilog -o servo servo.v

我收到以下错误:

servo.v:105: error: reg clock_div; cannot be driven by primitives or continuous assignment.
servo.v:105: error: Output port expression must support continuous assignment.
servo.v:105:      : Port 3 (clock_div) of clock_divider is connected to clock_div
servo.v:106: error: reg servoPin; cannot be driven by primitives or continuous assignment.
servo.v:106: error: Output port expression must support continuous assignment.
servo.v:106:      : Port 2 (servoPin) of get_servo is connected to servoPin
servo.v:106: error: reg ding; cannot be driven by primitives or continuous assignment.
servo.v:106: error: Output port expression must support continuous assignment.
servo.v:106:      : Port 3 (ding) of get_servo is connected to ding
6 error(s) during elaboration.

我在这里查看了所有问题,并看到了一些问题,这些问题指定了您在测试台模块中何时何地使用 reg 以避免这种情况:

<variable name> is not a valid l-value in foo

这是我遇到的第一个错误之一。为了避免它,我最终得到了这些。如果有人能指出这些错误的根本原因以及它们的来源,我也许可以解决这个问题并在此过程中学到一些新东西。

4

1 回答 1

2

这些信号由多个驱动器clock_div驱动。您已经作为模块和测试台本身的输出进行了驱动。这是非法的。servoPinservoPinget_servoclk_tb

关于clock_div,请参考下图:

端口连接规则

模块的输出必须连接到电线。这里,clock_divclock_divider模块的输出端口,必须是线型。然后,该输出线可以用作驱动servoPin模块的逻辑的输入。以下是您的测试平台代码的片段:

reg clock;
reg reset;
reg servoPin;
// reg clock_div; // remove this
wire clock_div_w, clock_div_w2;
assign clock_div_w2 = clock_div_w; // drive output from one module to input to another
//...
clock_divider DUT1 (clock, reset, clock_div_w); // wire output
get_servo DUT2 (clock_div_w2, servoPin, ding);  // another wire input
//...
initial begin
    // servoPin = 1'b1; // donot drive from here, module output
    #1 clock_div = 1'b0;
    $finish;
end

类似的评论适用于ding端口。

参考IEEE 1800-2012,第 23.3.3 节:

每个端口连接应是 source 到 sink 的连续分配其中一个连接项应为信号源,另一个应为信号接收器。对于输入或输出端口,分配应是从源到宿的连续分配。

当端口在实例中连接到任何其他端口时,它是一个常量分配,因此它总是要求目标端口是一个 net

有关详细信息,请参阅端口连接规则问题

于 2016-06-09T07:02:21.560 回答