我想學習的Verilog ,我得到了我的代碼的問題: 當我試圖加我的號碼,如 第一個值CLK問題>第二個值CLK> 3值clk>第四值clk>這裏應該是我的平均值,但由於某些未知的原因,我需要再次按下時鐘2次以獲得大幅值 ,我不知道爲什麼。 (我認爲這是在我的avereger代碼有問題) 爲什麼我有這樣的延遲 我avereger必須得到4 - 10位的號碼,告訴我它的averege(我的發光二極管)的Verilog(註冊代碼延遲或錯誤?)
這裏是我的代碼 和我包括我的矢量形式[
]
module avereger (data_in,Led1,Led2,Led3,clk,rst);
input clk,rst;
input [9:0]data_in;
output[6:0] Led1,Led2,Led3;
reg [9:0] data[3:0];
reg [11:0] sum,avg_reg;
always @ (posedge clk)
begin
if(rst==1'b1)
begin //all values will be 0
data[0]<=0;
data[1]<=0;
data[2]<=0;
data[3]<=0;
sum<=0;
avg_reg<=0;
end
else
begin
data[3]<=data[2];
data[2]<=data[1];
data[1]<=data[0];
data[0]<=data_in;
sum<= data[0] + data[1] + data[2] + data[3];
avg_reg<=sum[11:2];
end
end
decoder_driver BCD(avg_reg,Led1,Led2,Led3);
endmodule
module decoder_driver(A,Led1,Led2,Led3);
input [9:0] A;
output [6:0] Led1,Led2,Led3;
reg [3:0] B,C,D;
wire [3:0] wireB,wireC,wireD;
assign wireB=B;
assign wireC=C;
assign wireD=D;
display1 HUN(wireB,Led1);
display1 TEN(wireC,Led2);
display1 ONE(wireD,Led3);
always @ (A)
begin
B=A/7'd100;
C=A%7'd100/7'd10;
D=A%7'd100%7'd10;
end
endmodule
module display1 (a,Led);
input [3:0] a;
output [6:0] Led;
reg [6:0] Led;
always @ (a)
begin
case(a)
4'b0000: Led <= 7'b1000000; //0
4'b0001: Led <= 7'b1111001; //1
4'b0010: Led <= 7'b0100100; //2
4'b0011: Led <= 7'b0110000; //3
4'b0100: Led <= 7'b0011001; //4
4'b0101: Led <= 7'b0010010; //5
4'b0110: Led <= 7'b0000010; //6
4'b0111: Led <= 7'b1111000; //7
4'b1000: Led <= 7'b0000000; //8
4'b1001: Led <= 7'b0010000; //9
4'b1010: Led <= 7'b0001110; //F
default: Led <= 7'b1111111; //-
endcase
end
endmodule
歡迎來到Stackoverflow。我希望你能得到一個快速的答案。 –