作者zxvc (執著)
看板Electronics
標題Re: [問題] Quartus_verilog 為什麼輸出的波型是錯的
時間Sat Apr 10 11:23:33 2010
Show一下SystemVerilog。
modtest應該是可合成的,
請用Design Compiler、Synplify、Precision RTL或Quartus II合看看。
建議原po把一樣的東西assign到一個變數,之後就可以很方便參考,
code也比較好維護。
例如原po的code重複出現這些東西:
(((abslution_xa<<4'b1010))>>bi)
假如你後來發現這段code有錯,哪種方式比較好改?
我模擬的結果是這樣:
bi=4, m=384
主要是計算這個式子:
512-(1024*|x-a|/b)
不確定是不是原po想要的。
~~~~~~~~~~~~~~~~~~~~~~ modtest.sv ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
module modtest(
output [12:0] m,
output logic [2:0] bi,
input [4:0] x,
input [4:0] a, b
);
logic [4:0] larger, smaller, absVal;
integer i;
// Encoder.
always_comb begin
for(i = 0; i < 5; i = i+1) begin: Encoder
if(b[i])
bi = i;
end
end
assign larger = (a>=x) ? a : x;
assign smaller = (a>=x) ? x : a;
assign absVal = larger-smaller;
assign m = 512-(((absVal)<<10)>>bi);
endmodule
program modtestTb(
output logic [4:0] x,
output logic [4:0] a, b
);
initial begin
a=19;
b=16;
x=21;
#100;
$finish;
end
endprogram
module Top;
logic [12:0] m;
logic [2:0] bi;
logic [4:0] x;
logic [4:0] a, b;
modtestTb modtestTbInst(.*);
modtest modtestInst(.*);
endmodule
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.168.8.249
1F:推 psw:謝謝Z大大回應...我學到很多東西. <(_ _)> 04/10 11:29
2F:→ zxvc:psw大,還有一點,Encoder只是一個combinational circuit, 04/10 12:19
3F:→ zxvc:你寫在always@(posedge clock)會多出不必要的flip-flop。 04/10 12:19
4F:推 psw:已解決囉...^^ 04/11 11:25