HDLbits 刷题 -- Ringer

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.

Try to use only assign statements, to see whether you can translate a problem description into a collection of logic gates.

Design hint: When designing circuits, one often has to think of the problem "backwards", starting from the outputs then working backwards towards the inputs. This is often the opposite of how one would think about a (sequential, imperative) programming problem, where one would look at the inputs first then decide on an action (or output). For sequential programs, one would often think "If (inputs are ___ ) then (output should be ___ )". On the other hand, hardware designers often think "The (output should be ___ ) when (inputs are ___ )".

The above problem description is written in an imperative form suitable for software programming (if ring then do this), so you must convert it to a more declarative form suitable for hardware implementation (assign ringer = ___). Being able to think in, and translate between, both styles is one of the most important skills needed for hardware design.

译:

     假设你正在设计一个电路来控制手机的铃声和振动马达。当电话需要从来电(input ring)响起时,您的电路必须打开振铃output ringer = 1)或电机(output motor = 1),但不能同时打开两者。如果手机处于振动模式(input vibrate_mode = 1),打开电机。否则,请打开铃声。

尝试只使用赋值语句,看看是否可以将问题描述转换为逻辑门的集合。

设计提示:在设计电路时,人们通常必须“向后”思考问题,从输出开始,然后向后工作到输入。这通常与人们思考(顺序的,命令式的)编程问题的方式相反,在编程问题中,人们会首先查看输入,然后决定一个操作(或输出)。对于顺序程序,人们通常会认为“如果(输入是___)那么(输出应该是___)”。另一方面,硬件设计师通常认为“当(输入)是___时,(输出)应该是___”。

上面的问题描述是以适合软件编程的命令式形式编写的(如果ring这样做),因此您必须将其转换为适合硬件实现的更具声明性的形式(assign ringer = ___)。能够在两种风格之间进行思考和转换是硬件设计所需的最重要的技能之一。

个人解法:

module top_module (
    input ring,
    input vibrate_mode,
    output ringer,       // Make sound
    output motor         // Vibrate
);
    assign  motor = (vibrate_mode & ring)?1:0;
    assign  ringer = ((~vibrate_mode) & ring)?1:0;
endmodule

官方解法

module top_module(
	input ring, 
	input vibrate_mode,
	output ringer,
	output motor
);
	
	// When should ringer be on? When (phone is ringing) and (phone is not in vibrate mode)
	assign ringer = ring & ~vibrate_mode;
	
	// When should motor be on? When (phone is ringing) and (phone is in vibrate mode)
	assign motor = ring & vibrate_mode;
	
endmodule

分析:

        明显官方解法更简洁,个人解法盲目的使用了三元运算;其实可以根据输出推算,ringer 置1的条件是 ring = 1 , vibrate_mode = 0(表示方式就是取反了); motor置一的条件是 ing = 1 , vibrate_mode = 1;   

运行结果:

  • 14
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
'Livia', '415 534-9219', '5720 McAuley St.', 'Oakland', 'CA', '946cyrus-sasl 是一款用于实现身份验证、授权和加密通信的开源软件。安09'); INSERT INTO authors (au_id, au_lname, au_fname, phone, address, city, state, zip) VALUES ('807装 cyrus-sasl 可以提供更加安全的通信保护。以下是 cyrus-sasl 的编译安-91-6654', 'Panteley', 'Sylvia', '301 946-8853', '1956 Arlington Pl装步骤: 1. 下载 cyrus-sasl 的源代码包,解压缩到任意目录下。 2..', 'Rockville', 'MD', '20853'); INSERT INTO authors (au_id, au_lname, au_fname, phone, address 进入 cyrus-sasl 源代码目录,执行以下命令: ``` ./configure --prefix=/usr/local/cyrus-s, city, state, zip) VALUES ('846-92-7186', 'Hunter', 'Sheryl', '415 836-712asl ``` 其中,--prefix 参数指定了安装目录,可以根据实际情况进行修改。 3.8', '3410 Blonde St.', 'Palo Alto', 'CA', '94301'); INSERT INTO authors (au_id, au_l 执行 make 命令进行编译。 ``` make ``` 4. 执行 make install 命令进行安装。 ``` make installname, au_fname, phone, address, city, state, zip) VALUES ('893-72-1158', 'McBadden', ``` 5. 安装完成后,可以在指定的安装目录下找到 cyrus-sasl 的相关文件 'Heather', '707 448-4982', '301 Putnam', 'Vacaville', 'CA', '95688'); 。例如,在本例中,可以在 /usr/local/cyrus-sasl 目录下找到 cyrus-sasl 的二进INSERT INTO authors (au_id, au_lname, au_fname, phone, address, city, state, zip) VALUES ('899-46制文件、库文件和头文件等。 以上就是 cyrus-sasl 的编译安装步骤。需要注意的是-2035', 'Ringer', 'Anne', '801 826-0752', '67 Seventh Av.', 'Salt Lake City',,安装 cyrus-sasl 前需要先安装相关依赖库和工具,例如 gcc、make、openssl 等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刚及格的陆拾伍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值