Forum Discussion
Altera_Forum
Honored Contributor
10 years ago --- Quote Start --- You left out the most important part. The [NUMBER OF 1'S CALCULATED] is where the problem is. Please post that. Keep in mind that parameter values must be known at compile time. You can do calculations with them, but any inputs must be constants or other parameters. They cannot be variables, registers, wires etc. Verilog isn't like software languages. The hardware is created when the FPGA image is built and in general cannot be changed at runtime. --- Quote End --- Hi Galfonz, Thank you for your reply. What do you mean by "You can do calculations with them"? I saw that in System Verilog, one can use something which is called 'Parameter Type' - can it do what I want? Here's my code for calculating number of 1's in an input data: `resetall
`timescale 1ns/10ps
`define cct 10
module ones_counter
// port declarations
(input wire aclr_n,
input wire clk,
input wire [15:0] data,
input wire sync_n,
input wire fin_read,
output reg [2:0] ones_num
);
// internal declarations
wire equ;
reg [7:0] data_shift;
reg [2:0] ones_cnt;
// local declarations
// internal signal declarations
/* ---------------------------------------------------------------------------
****************** counting number of ones in a vector ***********************
--------------------------------------------------------------------------- */
always @ (posedge clk, negedge aclr_n)
begin
if (!aclr_n)
data_shift <= 8'b0;
else
if (sync_n)
data_shift <= data[13:6];
else
data_shift <= data_shift << 1;
end
assign equ = (data_shift[7] ^ 1'b0) & (!sync_n);
always @ (posedge clk, negedge aclr_n)
begin
if (!aclr_n)
ones_cnt <= 3'b0;
else
if (equ && data[15])
ones_cnt <= ones_cnt + 1'b1;
else
if (fin_read)
ones_cnt <= 3'b0;
end
always @ (posedge clk, aclr_n)
begin
if (!aclr_n)
ones_num <= 3'b0;
else
if (data_shift[7:0] == 8'b0)
ones_num <= ones_cnt;
else
ones_num <= 3'b0;
end
endmodule ones_num register holds the final result at the end, and I wish to instantiate this value to my main code. - Refael.