Re: [問題] VERILOG 時脈問題
※ 引述《zx33571163 (mm)》之銘言:
: always@(posedge clk or negedge reset )
: begin
: if(!reset)
: begin
: count=0;
: end
: else
: begin
: count1<=0;
: buffer<=bufin;
: count <=count+1;
: begin
: if(count==n)
: begin
: 判斷<=1;
: end
: end
: end
: end
: end
: always@(posedge clk )
: begin
: if(判斷==0)
: begin
: bufout<= 1'bz;
: end
: else if(判斷==1)
: begin
: count <=0;
: bufout<= buffer;
: count1<=count1+1;
: begin
: if(count1==n)
: 判斷<=0;
: end
: end
: end
: endmodule
: 我這樣寫
: 實際的輸出結果會比我想要的輸出 "慢1個CLOCK"
: 請問是哪出問題?
: 也就是判斷==1 但bufout晚1個CLOCK出來
把你的code看過一下
大概覺得你的function應該是下面我打的那樣吧
一種output是flip-flop 所以在output讀到input值的時候
會在下一個clk出現
另一種不是flip-flop的就單純接一個MUX
直接讀input值 同時出現在ouput
因為verilog和C語言很不一樣 你每個code寫出來就是硬體的一部份
所以建議要寫verilog 先把電路架構都想一下 再寫會比較好
還有combinational和sequential最好要分開寫 不要混在一起@@
1.output 為flip-flop
always@(count or bufin) //combinational
begin
if(count==4'd9)
begin
count_tmp=0;
bufout_tmp=bufin;
end
else
begin
count_tmp=count+1;
bufout_tmp=1b'z;
end
end
always@(posedge clk or negedge rst_n) //sequential
begin
if(~rst_n)
begin
count<=0;
bufout<=0;
end
else
begin
count<=count_tmp;
bufout<=bufout_tmp;
end
end
2.output 接MUX
always@(count or bufin) //com
begin
if(count==4'd9)
begin
count_tmp=0;
bufout=bufin;
end
else
begin
count_tmp=count+1;
bufout=1'dz;
end
end
always@(posedge clk or negedge rst_n) //seq
begin
if(~rst_n)
count<=0;
else
count<=count_tmp;
end
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.115.116.88
→
08/16 11:57, , 1F
08/16 11:57, 1F
推
08/16 12:44, , 2F
08/16 12:44, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):