你似乎在这个项目上失去了绝望(任务?),我很惊讶鲍勃
还没有建议你和老师一起一对一的时间
助教/导师。
你不太可能知道你需要知道的东西
在这个论坛上。
包括鲍勃和我在内的很多人都可以做到这一点
在睡眠中分配,但这并不能真正帮助你学习如何描述
Verilog中的硬件。
但是既然你发布了一些代码,我会添加一些批评:
总是@(ena,clr)开始
在这里你已经陷入困境了。
对于组合过程,您需要
在灵敏度列表中包含所有右侧信号。
Verilog 2001有一个
简单的解决方案,以确保您没有错过任何:
总是@ *开始
在你的情况下,你在灵敏度列表中错过了“q”。
if(clr == 1)开始
忘记了这一点并没有真正做到你想要的那一刻,它表明了这一点
您正在尝试编写Verilog代码,就好像它是VHDL一样。
两者之间没有区别
Verilog中的一位reg,wire或“boolean”。
我发现写起来更清楚:
if(clr)开始
现在问题的关键。
您正在为顺序进行分配
组合过程中的变量“q”。
这是错的。
唯一的任务
“q”应该在计时过程中。
如果你已经走得太远,试图合成
这段代码,您还会发现在分配变量时出错
不止一个过程。
如果你坚持使用这个计数器的两个进程,你需要
另一个变量代表你将在下一个分配“q”的值
时钟边缘。
您的模块没有定义内部变量。
很简单
如果没有一些,就不能使用双进程状态机
额外的中间变量。
基本的双进程状态机看起来像(伪代码)
reg [3:0] q_next;
总是@ *
q_next = q的一些函数和模块输入;
永远@(posedge clk)
q
如果clear输入是异步的,则第二部分看起来像:
永远@(posedge clk,posedge clr)
if(clr)q
否则q
但是说真的,从老师那里得到一些帮助。
这就是他付出的代价。
- Gabor
- Gabor
以上来自于谷歌翻译
以下为原文
You seem to be hopelessly lost on this project (assignment?) and I'm surprised that Bob
hasn't already suggested that you get some one-on-one time with your teacher or a
teaching assistant / tutor. It's not likely that you will be able to learn what you need to know
on this forum. There are many people including Bob and myself who could do this
assignment in their sleep, but that doesn't really help you learn how to describe
hardware in Verilog.
But since you went so far as to post some code, I'll add a few critiques:
always @(ena, clr) begin
Here you're already getting in trouble. For a combinatorial process you need to
have all of the right-hand-side signals in the sensitivity list. Verilog 2001 has a
simple solution to make sure you didn't miss any:
always @* begin
In your case you missed "q" in the sensitivity list.
if (clr==1) begin
Forgetting that this doesn't really do what you want for the moment, it shows that
you are trying to write Verilog code as if it were VHDL. There is no difference between
a one-bit reg, wire, or "boolean" in Verilog. I find it much clearer to just write:
if (clr) begin
Now to the meat of the problem. You are making assignments to the sequential
variable "q" in a combinatorial process. This is wrong. The only assignments to
"q" should be in the clocked process. If you had gone so far as to try to synthesize
this code, you would also find that you get an error for assigning the variable in
more than one process.
If you
insist on using two processes for this counter, you need to have
another variable to represent the value you will assign "q" on the next
clock edge. Your module has no internal variables defined. Quite simply
put you cannot use a two-process state machine without having some
additional intermediate variables.
The basic two-process state machine looks like (pseudo code)
reg [3:0] q_next;
always @*
q_next = some function of q and the module inputs;
always @ (posedge clk)
q <= q_next;
If the clear input is asynchronous the second part looks like:
always @ (posedge clk, posedge clr)
if (clr) q <= 0;
else q <= q_next;
But seriously, get some help from your teacher. That's what he's paid for.
-- Gabor
-- Gabor