| 网站首页 | 新闻 | SOPC | FPGA | DSP | ARM | 嵌入式操作系统 | 下载 | 网上商城 | 芯片价格参考 | 留言 | 论坛 | 网络协议 | 驱动设计 | 购买指南-HowtoBuy | 
您现在的位置: FPGA开发板&SOPC开发板-嵌入式控制研究室 >> FPGA >> FPGA应用 >> 文章正文 用户登录 新用户注册
Verilog HDL常见问题         ★★★ 【字体:
Verilog HDL常见问题
作者:周俊峰 陈…    文章来源:互联网    点击数:    更新时间:2006-9-26

问题:在使用case语句建模组合逻辑的时候,综合工具提示会出现latch
原因:产生这个错误时候可以从下面三个方面检查:
            1. 看看这个语句块的敏感列表是否完备,也就是是否所有的“输入”信号都位于敏感列表内;
            2. case语句是否覆盖了所有可能的条件;
            3. “输出”信号是否在每个分支上都进行了赋值操作;
例如:
always @(sel or in1 or in2) begin
    case (sel)
        2'b00 : begin // out2在这个分支没有赋值
                out1 = in1;
        end
        2'b01 : begin
                out2 = in2;
        end
        default : begin
            out1 = in1;
            out2 = in2;
        end
    endcase
end

引申:实际上这个问题还经常出现在使用if...else建模组合逻辑当中。

问题:如何使用Verilog语言描述一个双向口。
答案:

对双向口,我们可以将其理解为2个分量:一个输入分量,一个输出分量。另外还需要一个控制信号控制输出分量何时输出。此时,我们就可以很容易地对双向端口建模。

例子:


CODE:
module dual_port (
    ....
    inout_pin,
    ....
);

inout inout_pin;

wire inout_pin;

wire input_of_inout;
wire output_of_inout;
wire out_en;

assign input_of_inout = inout_pin;

assign inout_pin = out_en ? output_of_inout : z;

endmodule
可见,此时input_of_inout和output_of_inout就可以当作普通信号使用了。

在仿真的时候,需要注意双向口的处理。如果是直接与另外一个模块的双向口连接,那么只要保证一个模块在输出的时候,另外一个模块没有输出(处于高阻态)就可以了。
如果是在ModelSim中作为单独的模块仿真,那么在模块输出的时候,不能使用force命令将其设为高阻态,而是使用release命令将总线释放掉。


问题:4‘b1011&&4'b0100=?? 结果应该是多少啊?

答案:
上面的运算结果为1。&&是逻辑与操作,4'b1011不为0,因此它的逻辑值为“真”,同样的原因4'b0100的逻辑值也为“真”,因此逻辑与的结果为“真”,根据Verilog-2001:

 

1 (defined as true), 0 (defined as false),


因此问题的操作结果为1。

引申:
Verilog-2001中有关逻辑操作符的描述:

 

4.1.9 Logical operators

The operators logical and (&&) and logical or (||) are logical connectives. The result of the evaluation of a logical comparison shall be 1 (defined as true), 0 (defined as false), or, if the result is ambiguous, the unknown value (x). The precedence of && is greater than that of ||, and both are lower than relational and equality operators.

A third logical operator is the unary logical negation operator (!). The negation operator converts a nonzero or true operand into 0 and a zero or false operand into 1. An ambiguous truth value remains as x.

Examples:

Example 1—If reg alpha holds the integer value 237 and beta holds the value zero, then the following examples perform as described:

regA = alpha && beta; // regA is set to 0
regB = alpha || beta; // regB is set to 1

Example 2—The following expression performs a logical and of three subexpressions without needing any parentheses:

a < size-1 && b != c && index != lastone

However, it is recommended for readability purposes that parentheses be used to show very clearly the precedence intended, as in the following rewrite of this example:

(a < size-1) && (b != c) && (index != lastone)

Example 3—A common use of ! is in constructions like the following:

if (!inword)

In some cases, the preceding construct makes more sense to someone reading the code than this equivalent construct:

if (inword == 0)

文章录入:fengfeiyi    责任编辑:fengfeiyi 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    用FPGA实现DSP远程在线编程
    FPGA验证技术
    用CPU配置FPGA(一)概 述
    用CPU配置FPGA(二)硬件设计
    用CPU配置FPGA(三)软件操作
    用CPU配置FPGA (四) 应用实例
    在Modelsim se中创建altera仿…
    N奇数分频方法总结
    Altera FPGA、CPLD 学习笔记
    在PLD开发中提高VHDL的综合质…
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)