Error (12006): Node instance "" instantiates undefined entity "" - verilog

I want to compile a CPU written in Verilog, but for some reason I can't. The source code is this Github. Only system.v received an error that clk_out was covered with capital letters, so I changed it to clk_out_lower. I changed it to clk_out_lower.
Windows 10, Quartus 21.1.1, Verilog-2001.
Error (12006): Node instance "ibuf" instantiates undefined entity "IBUFGDS".
Error (12006): Node instance "obuf" instantiates undefined entity "BUFG".
Error (12006): Node instance "fbuf" instantiates undefined entity "BUFG".
Error (12006): Node instance "mmcm" instantiates undefined entity "MMCME2_ADV". .
system.v
`default_nettype none
`include "define.v"
module CLKGEN_DCM(CLK_IN, CLK_OUT, LOCKED);
input wire CLK_IN;
output wire CLK_OUT, LOCKED;
wire clk_ibuf;
wire clk_out_lower;
wire clk0, clk0_fbuf;
// input buffer
IBUFG ibuf (.I(CLK_IN),
.O(clk_ibuf));
// output buffer
BUFG obuf (.I(clk_out_lower),
.O(CLK_OUT));
// feedback buffer
BUFG fbuf (.I(clk0),
.O(clk0_fbuf));
// dcm instantiation
DCM_SP dcm (// input
.CLKIN (clk_ibuf),
.RST (1'b0),
// output
.CLKFX (clk_out_lower),
.LOCKED (LOCKED),
// feedback
.CLK0 (clk0),
.CLKFB (clk0_fbuf),
// phase shift
.PSEN (1'b0),
.PSINCDEC(1'b0),
.PSCLK (1'b0),
// digital spread spectrum
.DSSEN (1'b0));
defparam dcm.CLKIN_PERIOD = `DCM_CLKIN_PERIOD;
defparam dcm.CLKFX_MULTIPLY = `DCM_CLKFX_MULTIPLY;
defparam dcm.CLKFX_DIVIDE = `DCM_CLKFX_DIVIDE;
endmodule
/**************************************************************************************************/
module CLKGEN_MMCM(CLK_IN, CLK_OUT, LOCKED);
input wire CLK_IN;
output wire CLK_OUT, LOCKED;
wire clk_out_lower;
wire clkfb, clkfb_fbuf;
// output buffer
BUFG obuf (.I(clk_out_lower),
.O(CLK_OUT));
// feedback buffer
BUFG fbuf (.I(clkfb),
.O(clkfb_fbuf));
MMCME2_ADV mmcm (// input
.CLKIN1 (CLK_IN),
.CLKIN2 (1'b0),
.CLKINSEL (1'b1),
.RST (1'b0),
.PWRDWN (1'b0),
// output
.CLKOUT0 (clk_out_lower),
.CLKOUT0B (),
.CLKOUT1 (),
.CLKOUT1B (),
.CLKOUT2 (),
.CLKOUT2B (),
.CLKOUT3 (),
.CLKOUT3B (),
.CLKOUT4 (),
.CLKOUT5 (),
.CLKOUT6 (),
.LOCKED (LOCKED),
// feedback
.CLKFBOUT (clkfb),
.CLKFBIN (clkfb_fbuf),
.CLKFBOUTB (),
// dynamic reconfiguration
.DADDR (7'h0),
.DI (16'h0),
.DWE (1'b0),
.DEN (1'b0),
.DCLK (1'b0),
.DO (),
.DRDY (),
// phase shift
.PSCLK (1'b0),
.PSEN (1'b0),
.PSINCDEC (1'b0),
.PSDONE (),
// status
.CLKINSTOPPED (),
.CLKFBSTOPPED ());
defparam mmcm.CLKIN1_PERIOD = `MMCM_CLKIN1_PERIOD;
defparam mmcm.CLKFBOUT_MULT_F = `MMCM_VCO_MULTIPLY;
defparam mmcm.DIVCLK_DIVIDE = `MMCM_VCO_DIVIDE;
defparam mmcm.CLKOUT0_DIVIDE_F = `MMCM_CLKOUT0_DIVIDE;
defparam mmcm.CLKOUT1_DIVIDE = `MMCM_CLKOUT1_DIVIDE;
endmodule
/**************************************************************************************************/
module RSTGEN(CLK, RST_X_I, RST_X_O);
input wire CLK, RST_X_I;
output wire RST_X_O;
reg [7:0] cnt;
assign RST_X_O = cnt[7];
always #(posedge CLK or negedge RST_X_I) begin
if (!RST_X_I) cnt <= 0;
else if (~RST_X_O) cnt <= (cnt + 1'b1);
end
endmodule
/**************************************************************************************************/
module GEN_DCM(CLK_I, RST_X_I, CLK_O, RST_X_O);
input wire CLK_I, RST_X_I;
output wire CLK_O, RST_X_O;
wire LOCKED;
CLKGEN_DCM clkgen(.CLK_IN (CLK_I),
.CLK_OUT(CLK_O),
.LOCKED (LOCKED));
RSTGEN rstgen(.CLK (CLK_O),
.RST_X_I(RST_X_I & LOCKED),
.RST_X_O(RST_X_O));
endmodule
module GEN_MMCM(CLK_I, RST_X_I, CLK_O, RST_X_O);
input wire CLK_I, RST_X_I;
output wire CLK_O, RST_X_O;
wire clk_ibuf;
wire LOCKED;
// input buffer
IBUFG ibuf (.I(CLK_I),
.O(clk_ibuf));
CLKGEN_MMCM clkgen(.CLK_IN (clk_ibuf),
.CLK_OUT(CLK_O),
.LOCKED (LOCKED));
RSTGEN rstgen(.CLK (CLK_O),
.RST_X_I(RST_X_I & LOCKED),
.RST_X_O(RST_X_O));
endmodule
module GEN_MMCM_DS(CLK_P, CLK_N, RST_X_I, CLK_O, RST_X_O);
input wire CLK_P, CLK_N, RST_X_I;
output wire CLK_O, RST_X_O;
wire clk_ibuf;
wire LOCKED;
// input buffer
IBUFGDS ibuf (.I (CLK_P),
.IB(CLK_N),
.O (clk_ibuf));
CLKGEN_MMCM clkgen(.CLK_IN (clk_ibuf),
.CLK_OUT(CLK_O),
.LOCKED (LOCKED));
RSTGEN rstgen(.CLK (CLK_O),
.RST_X_I(RST_X_I & LOCKED),
.RST_X_O(RST_X_O));
endmodule
/**************************************************************************************************/
`default_nettype wire
/**************************************************************************************************/
The top entity is top.v. I checked IBUFGDS, etc. and found it only in this system.v.

IBUFGDS,BUFG,MMCME2_ADV are Xilinx library primitives.
Altera/Intel tools do not understand what these are.
If this code is built in a Xilinx Vivado then a synthesis tool (Vivado) will natively understand what these are.
The code can be simulated using standard simulation tools (Modelsim,Incisive etc), however the Xilinx Unisim & Simprim libraries will need to be compiled as part of that simulation.
This is getting into vendor specific territory; example for Modelsim.
https://electronics.stackexchange.com/questions/60319/how-to-add-the-xilinx-library-to-modelsim
Check with the author about what tools he used, and what libraries he needed to compile, and how he did the compilation. If he used Xilinx for simulation & synthesis it might all be native with nothing extra to do.
Behavioral models of these vendor models could be written for simulation. You would need to do homework on exactly what each one of these does.
An equivalent behavioral model of MMCME2_ADV will not work in Altera syntheses. Its a complex IP built into the Xilinx hardware. Its typical use is clock generation.
I looked at the linked github page found this regarding the target hardware & tools:
Our FPGA prototyping efforts have so far resulted in a prototype for Xilinx VC707 board. This prototype can operate at a clock frequency of 50MHz (Vivado 2015.2 is used for synthesizing and implementing the design).
Vivado 2015.2 was used for the github project you are trying to use.

Related

Declare vector ports without specifying their size in Verilog

When declaring a module in Verilog (2001?), is it possible to tell that some ports are vectors without indicating their size? The goal here is to handle vector ports of any size, without having to specify the sizes through parameters.
I know I can write something like what follows in Verilog, but I'd like to know if there's a way to get rid of the extra WIDTH_DATA parameter:
module my_module
#(
parameter WIDTH_DATA = 48
)
(
input Clk, En,
input [WIDTH_DATA-1:0] Data_in,
output Ready,
output reg [WIDTH_DATA-1:0] Data_out
);
This is possible in VHDL, using a declaration like that:
entity my_module is
port (
Clk : in std_ulogic;
En : in std_ulogic;
Data_in : in std_ulogic_vector;
Ready : out std_ulogic;
Data_out : out std_ulogic_vector
);
end entity;
The module implementation can then know the size of Data_in at compile time using Data_in'length (same for Data_out).
This is not possible in Verilog.
You can do something close to what you want in SystemVerilog using the interface construct. You can parameterize an interface, and connect that interface (or set of interfaces) to my_module.
interface my_intf #(int WIDTH);
logic [WIDTH-1:0] data;
endinterface
module my_module(input clk, en,
my_intf in, out,
output ready);
// $bits(in.data) - gives you the WIDTH
// typedef type(out.data) out_type // local typedef
endmodule
module top;
my_intf #(8) I1;
my_intf #(16) I2;
bit clk, en, ready;
my_module M1 (.clk,.en, .in(I1), .out(I2), .ready);
endmodule

Why does the following redeclaration error happen in verilog?

I'm trying to implement a simple verilog code as below:
module test1(
input ACLK,
input RST,
output test_output1,
output test_output2
);
//wire ACLK;
//wire RST;
reg test_output1;
reg test_output2;
assign test_output1 = ACLK;
always #(posedge ACLK or negedge RST)
begin
if(!RST)
begin
//test_output1 <=0;
test_output2 <=0;
end
else
begin
//test_output1 <=0;
test_output2 <=1;
end
end
endmodule
I get the following error message when I try to synthesize it in Xilinx ISE:
=========================================================================
* HDL Compilation *
=========================================================================
Compiling verilog file "test1.v" in library work
ERROR:HDLCompilers:27 - "test1.v" line 30 Illegal redeclaration of 'test_output1'
ERROR:HDLCompilers:27 - "test1.v" line 31 Illegal redeclaration of 'test_output2`
I am unable to resolve this error. Any help would be highly appreciated.
If you declare the directional of the port in the portlist, you must also declare the type. This is referred to as an ANSI style header.
There is also a non-ANSI style header that separates the portlist, directional, and type. If you are fallowing IEEE1364-1995 convention then you must use non-ANSI style and you cannot declare the type (e.g. output reg test_output2; is illegal, while output test_output2; reg test_output2; is legal). Since IEEE1364-2001 ANSI and non-ANSI style is supported (and the non-ANSI allows output reg test_output2;). All modern Verilog simulators are SystemVerilog (IEEE1800) simulators, therefore it is the designers choice. (ANSI style is more popular as it is less typing).
ANSI style header:
module test1(
input ACLK,
input RST,
output test_output1,
output reg test_output2 );
Non-ANSI style header:
module test1( ACLK, RST, test_output1, test_output2 );
input ACLK;
input RST;
output test_output1;
output test_output2;
reg test_output2;
Note: With IEEE1364, you can not drive a reg with an assign statement, it must be a net type. IEEE1800 has softened the rule the it is recommenced logic in stead of reg, but generally if you are going to use assign then you should be assigning a net (e.g. wire).
Add following modification:
You used test_output1 in assign statement so it should be of type wire.
module test1(
input wire ACLK,
input wire RST,
output wire test_output1,
output reg test_output2
);
You have already declared test_output1 and test_outpu2 as output and it is by default of type wire, so you just have to implicitly specify wire or reg according to usage,
// reg test_output1;
// reg test_output2;

Connect 5-bit bus to 32-bit output bus

My design needs multiple multiplexers, all of them have two inputs and most are 32 bits wide. I started with designing the 32 bit, 2:1 multiplexer.
Now I need a 5 bit, 2:1 multiplexer and I want to reuse my 32 bit design. Connecting the inputs is easy (see code below), but I struggle to connect the output.
This is my code:
reg [4:0] a, b; // Inputs to the multiplexer.
reg select; // Select multiplexer output.
wire [4:0] result; // Output of the multiplexer.
multiplex32_2 mul({27'h0, a}, {27'h0, b}, select, result);
When I run the code through iverilog, I get a warning that says that the multiplexer expects a 32 bit output, but the connected bus is only 5 bit wide. The simulation shows the expected results, but I want to get rid of the warning.
Is there a way to tell iverilog to ignore the 27 unused bits of the multiplexer output or do I have to connect a 32 bit wide bus to the output of the multiplexer?
I don't know of a #pragma or something like that (similar to #pragma argsused from C) that can be used in Verilog.
Xilinx ISE, for example, has a feature called "message filtering", which allows the designer to silence specific warning messages. You find them once, select them, choose to ignore, and subsequent synthesis won't trigger those warnings.
Maybe you can design your multiplexer in a way you don't need to "waste" connections (not actually wasted though, as the synthesizer will prune unused connections from the netlist). A more elegant solution would be to use a parametrized module, and instantiate it with the required width. Something like this:
module mux #(parameter WIDTH=32) (
input wire [WIDTH-1:0] a,
input wire [WIDTH-1:0] b,
input wire sel,
output wire [WIDTH-1:0] o
);
assign o = (sel==1'b0)? a : b;
endmodule
This module has been tested with this simple test bench, which shows you how to instantiate a module with params:
module tb;
reg [31:0] a1,b1;
reg sel;
wire [31:0] o1;
reg [4:0] a2,b2;
wire [4:0] o2;
mux #(32) mux32 (a1,b1,sel,o1);
mux #(5) mux5 (a2,b2,sel,o2);
// Best way to instantiate them:
// mux #(.WIDTH(32)) mux32 (.a(a1),.b(b1),.sel(sel),o(o1));
// mux #(.WIDTH(5)) mux5 (.a(a2),.b(b2),.sel(sel),.o(o2));
initial begin
$dumpfile ("dump.vcd");
$dumpvars (1, tb);
a1 = 32'h01234567;
b1 = 32'h89ABCDEF;
a2 = 5'b11111;
b2 = 5'b00000;
repeat (4) begin
sel = 1'b0;
#10;
sel = 1'b1;
#10;
end
end
endmodule
You can test it yourself using this Eda Playground link:
http://www.edaplayground.com/x/Pkz
I think the problem relates to the output of the multiplexer which is still 5 bits wide. You can solve it by doing something like this:
reg [4:0] a, b; // Inputs to the multiplexer.
reg select; // Select multiplexer output.
wire [31:0] temp;
wire [4:0] result; // Output of the multiplexer.
multiplex32_2 mul({27'h0, a}, {27'h0, b}, select, temp);
assign result = temp[4:0];
This can be easily tested in http://www.edaplayground.com/ using the code below:
( I have re-used #mcleod_ideafix's code)
// Code your testbench here
// or browse Examples
module mux #(parameter WIDTH=32) (
input wire [WIDTH-1:0] a,
input wire [WIDTH-1:0] b,
input wire sel,
output wire [WIDTH-1:0] o
);
assign o = (sel==1'b0)? a : b;
endmodule
module tb;
reg [31:0] a,b;
wire [31:0] o;
wire [4:0] r;
reg sel;
initial begin
$dumpfile("dump.vcd"); $dumpvars;
a = 10; b = 20; sel = 1;
end
mux MM(a,b,sel,o);
assign r = o[4:0];
endmodule
Let me know if you are still getting a warning.

localparam after wire declaration

For a very strange reason (scripts we use) I need to be able to declare a localparam AFTER I declare wires and regs in a module:
module blah (clk, rst, in, out);
input clk;
input rst;
input [2:0] in;
output [3:0] out;
wire res;
localparam NUMBER=5;
...
is this legal verilog code? I would also appreciate a link to the relevant seciton in the documentation. Thanks!
This is valid Verilog (2001). Verilog 2001 saw the introduction of localparam, for all versions it is still syntactically valid to use parameter in this context. localparam indicates that it can not be overridden.
Usage can be seen in section 23.10 Overriding module parameters of SystemVerilog IEEE Std 1800-2012.
From IEEE 1800-2012:
For example:
module generic_fifo
#(MSB=3, LSB=0) // parameter port list parameters
(input wire [MSB:LSB] in,
input wire clk, read, write, reset,
output logic [MSB:LSB] out,
output logic full, empty );
parameter DEPTH=4; // module item parameter
localparam FIFO_MSB = DEPTH*MSB;
localparam FIFO_LSB = LSB;
// These constants are local, and cannot be overridden.
// They can be affected by altering the value parameters above
logic [FIFO_MSB:FIFO_LSB] fifo;
logic [LOG2(DEPTH):0] depth;
always #(posedge clk or posedge reset) begin
casez ({read,write,reset})
// implementation of fifo
endcase
end
endmodule
Exactly. As per the Verilog IEEE Std 1364-2001, you can use localparam in your Verilog code. It can be declared after wire declaration, no problem for that.

How can i make my verilog shifter more general?

Here i have a shifter but as of rite now it only works for up to 3 bits. I've been looking and i can't find out how to make it work for up to 8 bits.
module shifter(a,b,out);
input [7:0] a, b;
output [7:0] out;
wire [7:0] out1, out2, out3;
mux_8b_2to1 first(a[7:0], {a[3:0],a[7:4]}, b[2], out1);
mux_8b_2to1 second(out1[7:0], {out1[5:0],out1[7:6]}, b[1], out2);
mux_8b_2to1 third(out2[7:0], {out2[6:0],out2[7]}, b[0], out);
endmodule
What you have is a Barrel Shifter. Two ways to make it more generic are make it a functional model (still synthesis-able) or structural model with a generate block. Both approaches follow IEEE Std 1364-2001 (aka Verilog-2001).
The functional generic approach for a barrel shifter only needs a down-shifter. The general function is out = {in,in} >> (WIDTH-shift) where leftover bits can be ignored. To protect for double-roll (i.e. shift > WIDTH ), use the mod operator on the shift (WIDTH-(shift%WIDTH)).
module barrel_shifter_functional #( parameter CTRL=3, parameter WIDTH=CTRL**2 )
( input wire [WIDTH-1:0] in,
input wire [ CTRL-1:0] shift,
output wire [WIDTH-1:0] out );
assign out = {2{in}} >> (WIDTH-(shift%WIDTH));
endmodule
The structural generic approach for a barrel shifter needs a generate block. The for loop in the generate block will unravel at compile time, not run time like a for loop like in an always block. To keep it generic also have have the 2-to-1 mux have a parametrized width. FYI, you can use the generate block with functional code too, for example comment out the mux_2to1 instantiation and uncomment the assign statement below it. Learn more about the generate block by reading IEEE Std 1800-2012 ยง 27. Generate constructs.
module barrel_shifter_structeral #( parameter CTRL=3, parameter WIDTH=CTRL**2 )
( input wire [WIDTH-1:0] in,
input wire [ CTRL-1:0] shift,
output wire [WIDTH-1:0] out );
wire [WIDTH-1:0] tmp [CTRL:0];
assign tmp[CTRL] = in;
assign out = tmp[0];
genvar i;
generate
for (i = 0; i < CTRL; i = i + 1) begin : mux
mux_2to1 #(.WIDTH(WIDTH)) g(
.in0(tmp[i+1]),
.in1({tmp[i+1][WIDTH-(2**i)-1:0],tmp[i+1][WIDTH-1:WIDTH-(2**i)]}),
.sel(shift[i]),
.out(tmp[i]) );
// assign tmp[i] = shift[i] ? {tmp[i+1][WIDTH-(2**i)-1:0],tmp[i+1][WIDTH-1:WIDTH-(2**i)]} : tmp[i+1];
end : mux
endgenerate
endmodule
module mux_2to1 #( parameter WIDTH=8 )
( input wire [WIDTH-1:0] in0, in1,
input wire sel,
output wire [WIDTH-1:0] out );
assign out = sel ? in1 : in0;
endmodule
Both examples are functionally equivalent and synthesize provided CTRL is less than or equal to the ceiling of log2(WIDTH). Synthesis will likely give different results. The generate method will exclusively use 2-to-1 muxes while the pure functional method will depend on the quality of the optimizer.
Working example # http://www.edaplayground.com/s/6/500
I've used the >> and << operators to generate a synthetizable design using ISEWebPack, as this:
module shifter(
input wire [7:0] a,
input wire [7:0] b,
input wire leftright, // 0=shift right, 1=shift left
output reg [7:0] out
);
always #* begin
if (leftright==0)
out = a>>b;
else
out = a<<b;
end
endmodule
This way, the symthesis tool will know that you want to implement a shifter and can use its own macros to best synthetize it:
Synthesizing Unit <shifter>.
Related source file is "shifter.v".
Found 8-bit shifter logical right for signal <out$shift0002> created at line 30.
Found 8-bit shifter logical left for signal <out$shift0003> created at line 32.

Resources