作者vapaa (...)
看板Electronics
标题Re: [问题] VERILOG 时脉问题
时间Mon Aug 16 11:52:35 2010
※ 引述《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
1F:→ vapaa:combinational里面的count==4'd9可以改到自己想要的值出现 08/16 11:57
2F:推 rabird:印象中1'bz没有办法合成, 应该随便给个0或1吧 08/16 12:44