SystemVerilog/Verilog的實數輸入輸出和常數:Cordic或者直接unsynthesizable的C表達

因爲在圖像處理的時候需要用到很多filter,其中Gaussian filter是一個是exponential function,所以要用到e和**。

正規的做法是用Cordic或者xilinx/altera的math lib。


cordic核貌似只能對以e爲底的數計算,e^x=coshx+sinhx,選擇雙曲計算sinh and cosh選項,然後把兩個輸出相加就是e^x結果.

可以參考http://verilog.openhpsdr.org/。上面有Cordic的分析和test,用的modelsim。路徑是:E:\verilog\thesis_2014\Apr6_Conv\cordic\CORDIC Test



但爲了快速檢驗設計,看看neural network對不對,所以暫時先不考慮cordic的設計。當然,要記住RTL是設計電路而不是程序。


參考的資料是:SystemVerilog and verilog gotcha 101 和 http://billauer.co.il/blog/2009/07/verilog-standard-short-port-declaration-output-reg-autoarg/

看到了對於input的實數要定義成:var real 2.718,而output只要real 3.14就行。

//`define ee = 2.718281828;
module exp(input clk, input var real in, output real out);
	parameter ee = 2.718281828;
	always @ (posedge clk) begin
		out <= (ee)**(in);
	end
endmodule


module exp_tb;
 
reg clock;
//reg [15:0] d;
//wire [15:0] q;
real d;
real q;

initial begin
  $dumpfile ("exp_tb.vcd");
  $dumpvars (0, exp_tb);
  //$monitor ("clock=%b, d=%b, q=%b", clock, d, q);
  clock = 0;
  d = 16'd0;
  #10 d = 1;
  #10 d = -1;
  #10 d = 10;
  #20 $finish;
end
 
always begin
  #5 clock = !clock;
end
 
exp d0(
.clk (clock),
.in (d),
.out (q)
);
 
endmodule



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章