标签:区别 ringer 电路图 mode motor input output 默认值
题目来自: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
一、assign写法
module top_module (
input ring,
input vibrate_mode,
output ringer, // Make sound
output motor // Vibrate
);
assign ringer = ring & !vibrate_mode;
assign motor = ring & vibrate_mode;
endmodule
elab电路图
黄色的图是Vivado的elaborate步骤出的电路图;
蓝色的图是Quartus的RTL Viewer出来的图;
Vivado和Quartus的电路图区别:Quartus的图看起来会稍微简洁一点点;
synth电路图
黄色的图是Vivado的synthesis步骤出的图;
紫色这张图是Quartus的Technology Map Viewer (Post-Mapping)出来的图;
图里的IBUF和OBUF可以忽略掉,这是综合工具自动加上去的。
二、always @(*)组合逻辑写法
module top_module (
input ring,
input vibrate_mode,
output reg ringer, // Make sound
output reg motor // Vibrate
);
always @(*) begin
ringer = 0; motor = 0;
if (ring)
if (vibrate_mode)
motor = 1;
else
ringer = 1;
end
endmodule
elab电路图
synth电路图
这两个电路图是第一种写法的图是一样的。
小结论:elaborate和synthesis电路图的区别
对比一和二两种写法,可以看到elab阶段的电路图是从RTL代码分析的,所以两个电路图看起来有点不一样(仔细看可以发现功能是一样的),而综合synth阶段的电路图是一样的,因为综合的确是分析了电路的功能,用具体的器件来实现功能了。
三、latch问题
module top_module (
input ring,
input vibrate_mode,
output reg ringer, // Make sound
output reg motor // Vibrate
);
always @(*) begin
// ringer = 0; motor = 0;
if (ring)
if (vibrate_mode)
motor = 1;
else
ringer = 1;
end
endmodule
elab电路图
Quartus出的这个图很简洁,直接给了输出1。两个工具都发现了Latch的存在,报了Warning。
synth电路图
小结论:latch问题、always组合逻辑默认值写法
可以看到,如果不把 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 @(*) begin
left = 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;
endcase
end
endmodule
注:CSDN博客竟然不支持Verilog的高亮???其他语言,例如C/C++可以
标签:区别,ringer,电路图,mode,motor,input,output,默认值 来源: https://blog.csdn.net/hujy23/article/details/110773941
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。