arrays - Converting a fixed point Matlab code to Verilog -
i have fixed point matlab code , needs converted verilog. below matlab code. yfftshift
5000x0 , y2shape
100x50.
rows=100; colms=50; r=1; m=0:colms-1 n=0:rows-1 y2shape(n+1,m+1)=yfftshift(r,1); r=r+1; end end
how can create memories in verilog , call them inside for
loop?
the easiest way handle fixed precision in verilog introduce scale factor , allocate sufficiently large registers hold maximum value. example, if know maximum value of numbers 40, , 3 digits of precision right of decimal place ok, scaling factor of 1000 can used 16-bit registers. verilog treats unsigned numbers, if values can negative, it's necessary add "signed" declarations. verilog be:
`define number_rows 100 `define number_cols 50 `define max_row (`number_rows-1) `define max_col (`number_cols-1) module movememory(); reg clk; reg [15:0] y2shape [`max_row:0][`max_col:0]; reg [15:0] yfftshift [`number_rows * `number_cols:0]; integer rownumber, colnumber; @(posedge clk) begin (rownumber = 0; rownumber < `number_rows; rownumber = rownumber + 1) (colnumber = 0; colnumber < `number_cols; colnumber = colnumber + 1) y2shape[rownumber][colnumber] <= yfftshift[rownumber * `number_cols + colnumber]; end endmodule
this ok fpga or simulation project, full custom work, sram macro used avoid die area associated 16,000 registers. fpga implementation, you've paid 16k registers, or may able work synthesizer map registers on-chip sram.
the test bench:
// testing code integer loadcount, rowshownumber, colshownumber; initial begin // initialize array data (loadcount=0; loadcount < (number_rows *
number_cols); loadcount = loadcount + 1) yfftshift[loadcount] <= loadcount; clk <= 0;
// clock block #1 clk <= 1; // display results #1 $display("y2shape has these values @ time ", $time); (rowshownumber = 0; rowshownumber < `number_rows; rowshownumber = rowshownumber + 1) (colshownumber = 0; colshownumber < `number_cols; colshownumber = colshownumber + 1) $display("y2shape[%0d][%0d] %d ", rowshownumber, colshownumber, y2shape[rowshownumber][colshownumber]); end
the simulation results number_rows=10, number_cols=5
y2shape has these values @ time 2 y2shape[0][0] 0 y2shape[0][1] 1 y2shape[0][2] 2 y2shape[0][3] 3 y2shape[0][4] 4 . . . y2shape[9][2] 47 y2shape[9][3] 48 y2shape[9][4] 49
Comments
Post a Comment