Forum Discussion
10 Replies
- Altera_Forum
Honored Contributor
Adding a little code here could help us help you.
Make sure you aren't trying to assign the same variable in two separate processes. - Altera_Forum
Honored Contributor
The code looks like this:
bit Array; initial begin byte i; for (i=20; i>=0; i--) Array = 1; end always @ (posedge PLL) begin // Array value returns 0 at all elements here end - Altera_Forum
Honored Contributor
"initial" is only used in test benches, it can not be used for code running in an FPGA.
Although I'm not much of a verilog guy, I think the for loop is constructed incorrectly. Trybit Array; initial begin byte i; for (i=20; i>=0; i--) begin Array = 1; end end always @ (posedge PLL) begin // Array value returns 0 at all elements here end - Altera_Forum
Honored Contributor
I am coding in SystemVerilog. Quartus does not report any syntax error, so I think the for loop structure is fine. The initial process affects some other variables except array type. :confused:
- Altera_Forum
Honored Contributor
Initial block will be synthesized as POR state for signals or possibly as initial values for block RAM.
In the present case, a nested loop would be necessary to initialize the complete array, only a diagonal is initialized now. - Altera_Forum
Honored Contributor
Thank you for the replies.
- Altera_Forum
Honored Contributor
I have created a nested loop to initial the array, but I failed to assign it's value.
bit Array ; initial begin byte i, j; for (i=20; i>=0; i--) for (j=20; j>=0; j--) Array = 0; for (i=20; i>=0; i--) Array = 1; end always @ (posedge PLL) begin // Array returns 0 at all elements here end - Altera_Forum
Honored Contributor
I could reproduce a Quartus problem with initial blocks. What I see is this:
- If the array is implemented in registers, initial blocks like in the present example are working without limitations. - If the array infers RAM, initial blocks should be converted to memory initialization files, as stated in the Quartus handbook: --- Quote Start --- In Verilog HDL, you can use an initial block to initialize the contents of an inferred memory. Quartus II integrated synthesis automatically converts the initial block into a .mif for the inferred RAM. Example 6–19 shows Verilog HDL code that infers a simple dual-port RAM block and corresponding .mif file. --- Quote End --- This works for the given example
But there seems to be a problem to convert multi-dimensional assignments as in your example. You can determine if the initial block has been converted correctly by reviewing the compilation messages. The INIT_FILE line will only appear if the initial block has been understood. --- Quote Start --- Info: Instantiated megafunction "altsyncram:ram_rtl_0" with the following parameter: Info: Parameter "INIT_FILE" = "db/test1.ram0_single_port_ram_7cbe84f1.hdl.mif" --- Quote End --- Knowing this limitation, you'll hopefully find a workaround. You also may want to report this as a bug to Altera support.module ram_with_init( output reg q, input d, input write_address, read_address, input we, clk ); reg mem ; integer i; initial begin for (i = 0; i < 32; i = i + 1) mem = i; end always @ (posedge clk) begin if (we) mem <= d; q <= mem; end endmodule - Altera_Forum
Honored Contributor
I have just contacted Altera Support, but they refused to file my request because my account was not registered under a company/university name, and my e-mail address was not associated with a company/university. :(
- Altera_Forum
Honored Contributor
I have a single dimension array implemented in register not working:
reg Array ; initial begin byte i, j; for (i=63; i>=0; i--) Array = 0; for (i=63; i>=0; i--) Array = 1; end always @ (posedge PLL) begin // Array returns 1 at Array only. end