题目来自:Ringer - HDLBits
Suppose you are designing a circuit to control a cellphone’s ringer and vibration motor. Whenever the phone needs to ring from an incoming call (input ring), your circuit must either turn on the ringer (output ringer = 1) or the motor (output motor = 1), but not both. If the phone is in vibrate mode (input vibrate_mode = 1), turn on the motor. Otherwise, turn on the ringer.
下面使用Vivado来elaborate(详细描述)和synthesis(综合),也是用Quartus来Analysis & Synthesis
module top_module (input ring,input vibrate_mode,output ringer, // Make soundoutput motor // Vibrate
);assign ringer = ring & !vibrate_mode;assign motor = ring & vibrate_mode;
endmodule
黄色的图是Vivado的elaborate步骤出的电路图;
蓝色的图是Quartus的RTL Viewer出来的图;
Vivado和Quartus的电路图区别:Quartus的图看起来会稍微简洁一点点;
黄色的图是Vivado的synthesis步骤出的图;
紫色这张图是Quartus的Technology Map Viewer (Post-Mapping)出来的图;
图里的IBUF和OBUF可以忽略掉,这是综合工具自动加上去的。
module top_module (input ring,input vibrate_mode,output reg ringer, // Make soundoutput reg motor // Vibrate
);always @(*) beginringer = 0; motor = 0;if (ring)if (vibrate_mode)motor = 1;elseringer = 1;end
endmodule
这两个电路图是第一种写法的图是一样的。
对比一和二两种写法,可以看到elab阶段的电路图是从RTL代码分析的,所以两个电路图看起来有点不一样(仔细看可以发现功能是一样的),而综合synth阶段的电路图是一样的,因为综合的确是分析了电路的功能,用具体的器件来实现功能了。
module top_module (input ring,input vibrate_mode,output reg ringer, // Make soundoutput reg motor // Vibrate
);always @(*) begin// ringer = 0; motor = 0;if (ring)if (vibrate_mode)motor = 1;elseringer = 1;end
endmodule
Quartus出的这个图很简洁,直接给了输出1。两个工具都发现了Latch的存在,报了Warning。
可以看到,如果不把 if else 或 case 写完整的话,会产生latch。
always @(*)组合逻辑写法中,默认值的写法可以学一下。下面再举一个默认值写法的例子:Always nolatches - HDLBits。
module top_module (input [15:0] scancode,output reg left,output reg down,output reg right,output reg up ); always @(*) beginleft = 0; down = 0; right = 0; up = 0; // 这里是默认值,节省了很多default写法case (scancode)16'he06b: left = 1;16'he072: down = 1;16'he074: right = 1;16'he075: up = 1;endcaseend
endmodule
注:CSDN博客竟然不支持Verilog的高亮???其他语言,例如C/C++可以
本文发布于:2024-02-04 05:21:57,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170700038052493.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |