看板 Electronics 關於我們 聯絡資訊
小弟目前在學習使用verilog寫一些電路 但最近寫影像處理Mean Filter,需要算九宮格的平均值 但電路模擬後卻無法產生Output 以下是我的code module Mean( input [9:0] DAGray, input CLKin, input iRES_N, input iDVAL, output reg oDVAL, output [9:0] oDATA); reg [7:0] pos [800*3-1:0]; reg [11:0] count; reg chg; integer i; always@(posedge CLKin or negedge iRES_N) begin if(!iRES_N) begin oDVAL<=0; chg<=0; end else begin oDVAL <= iDVAL; if(iDVAL) begin for(i=2399;i>=1;i=i-1) begin pos[i]<=pos[i-1]; end pos[0]<=DAGray[9:2]; end if(count < 12'b011001000010) //1602 chg<=1'b0; else begin if(count > 12'b100101011111) //2399 begin count<=12'b011001000001; //1601 end chg<=1'b1; end count<=count+1; end end reg [11:0] a; reg [11:0] b; reg [11:0] sub; reg [9:0] out; always@(posedge CLKin or negedge chg) begin if(!chg) out<=10'b0; else begin /////////下面是將9個pixel相加除以9 a<=pos[1602]+pos[1602-1]+pos[1602-2]+pos[1602-800]+pos[1602-801]+pos[1602-802]+pos[1602-1600]+pos[1602-1601]+pos[1602-1602]; b<={3'b0,a[11:3]}; sub<=a-b; out={1'b0,sub[11:3]}; end end assign oDATA=out; endmodule 請各位大大幫幫小弟!!!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.116.234.232 ※ 文章網址: https://www.ptt.cc/bbs/Electronics/M.1506672320.A.9D1.html
e1090128: 程式碼還不太會排版請見諒 09/29 16:09
ericute: counter沒reset值? 09/29 19:02
e1090128: 有喔,超過2399變回1601 09/29 20:45
e1090128: 但我是模擬時連輸出都沒有,上面標示叉叉 09/29 20:46
hsucheng: count沒給初執 09/29 21:42
ericute: 這樣就是沒初始值 10/02 21:36
e1090128: verilog記得沒有設初始它會自動設為0 10/03 13:44
e1090128: 我後來有加初始後,在time simulation也是跑不出來 10/03 13:45
qxxrbull: 給初始之後跑出來的變成如何? 10/04 00:33
e1090128: 跟原本一樣,沒有差別 10/04 11:51
mmonkeyboyy: 沒有初值不一定是會變零 你沒有 reset 10/04 20:26
mmonkeyboyy: 你把模塊再分開跑@_@~再分成更小跑看看 10/04 20:27
mmonkeyboyy: 沒看到你error什麼的 這是隔空抓藥了 10/04 20:27
mmonkeyboyy: 標xx還有就是你根本沒有跑通程式...這也是一種可能性 10/04 20:28
Jielolz: 你的pos不會有值吧... 10/06 01:26
e1090128: 各位我解決了,是計算的問題,用assign 就可以運作了 10/07 12:34