I am fairly new to Verilog and FPGA development and have noticed that there are various differences you have to be aware of between simulation and synthesis. I am using the Altera DE1 board with Quartus II Software.
Here is something I cannot figure out. I have code as follows to instantiate a module:
reg [9:0] x0;
initial begin
x0 = 10'd200;
end
linepro linedrawer1
(.CLOCK(I_CLK),
.RST(reset_drawer),
.done(drawer_done),
.x0(x0),
.y0(10'd200),
.x1(10'd500),
.y1(10'd100),
.outx(x),
.outy(y));
As you can see, I am hooking an initialized reg directly to the port of my linepro module. This code appears to work under simulation, but does NOT correctly initialize x0 on the fpga board.
To make this code work properly, and the linepro module be instantiated correctly, I make the following slight modification:
reg [9:0] x0reg;
wire [9:0] x0;
assign x0=x0reg;
initial begin
x0reg = 10'd200;
end
linepro linedrawer1
(.CLOCK(I_CLK),
.RST(reset_drawer),
.done(drawer_done),
.x0(x0),
.y0(10'd200),
.x1(10'd500),
.y1(10'd100),
.outx(x),
.outy(y));
In this example, I assign the reg to a wire and hook the wire into the linepro module.
What is the difference, if any, between using a reg directly to instantiate a module and assigning a reg to a wire and using that wire to instantiate the module? What are some reasons one method might work and the other might not?
Thanks in advance for any assistance.
x0
port onlinepro
an input or output? – user1902824200
, it's because theinitial
blocks are not synthesizable. – Eugene Sh.initial
blocks are an accepted way of setting defaults for FPGA. they are not synthesizable for ASIC. The Second example uses initial and it does synthesis. – Morgan