HDLBits学习------Problem 72~79

127 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。​ ​

参考链接:HDLBits导学


Problem 72 3-variable

问题: 根据卡诺题来实现电路:

​编辑

         思路: 使用卡洛图得到表达式

​编辑

第一个方框中,只有b的值保持不变且为1,所以这个框化简出来是b

第二个方框中,只有c的值都保持不变且为1,所以这个框化简出来是c

第三个方框中,只有a的值保持不变且为1,所以这个框化简出来是a

最后三个表达式加起来就是最后的表达式,转换到verilog中就是或‘|’的关系

         解决:

module top_module(
    input a,
    input b,
    input c,
    output out  ); 
	
assign out = a | b | c;

endmodule


Problem 73 4-variable

        问题: 根据卡诺图来设计电路

File:Kmap2.png​编辑

        思路: 可以画出四个圈,化简后如下

​编辑

第一个框:a非d非

第二个框:c非b非

第三个框:a非bc

第四个框:acd

转换到verilog就是

(!a&!d) | (!c&!b) | (!a&b&c) | (a&c&d)

        解决:

module top_module(
    input a,
    input b,
    input c,
    input d,
    output out  ); 
	
assign out = (!a&!d) | (!c&!b) | (!a&b&c) | (a&c&d);

endmodule


Problem 74 4-variable

问题: 根据卡诺图来设计电路

Kmap3.png​编辑

        思路:使用卡洛图化简表达式,d是无关项,可以代表0或1,但不一定要全部圈中

​编辑

第一个框:a

第二个框:a非b非c

转换到verilog

a | (!a&!b&c)

解决:

module top_module(
    input a,
    input b,
    input c,
    input d,
    output out  );

assign out = a | (!a&!b&c);	

endmodule


Problem 75 4-variable

问题: 根据卡诺图来设计电路

Kmap4.png​编辑

思路: 化简不了了,只能硬写了

解决:

module top_module(
    input a,
    input b,
    input c,
    input d,
    output out  ); 

assign out = (~a&b&~c&~d) | (a&~b&~c&~d) | (~a&~b&~c&d) |  (a&b&~c&d) |  (~a&b&c&d) |  (a&~b&c&d) |  (~a&~b&c&~d) |  (a&b&c&~d); //借用大佬代码  写不动了,,,

endmodule


Problem 76 Minimum SOP and POS

问题: 一个4输入a, b, c, d和一输出的逻辑电路,当输入为2, 7或15时,输出为1, 当输入为0, 1, 4, 5, 6, 9, 10, 13, 或 14 时,输出为0,当输入为3,8,11或12时输出为任意值。举例来说,7对应输入abcd为0,1,1,1

思路: 还是借用卡洛图来化简

SOP:

​编辑

第一个框:cd

第二个框:a非b非c

POS:

​编辑

第一个框:c非

第二个框:ab非

第三个框:bd非 

然后整体取反

解决:

module top_module (
    input a,
    input b,
    input c,
    input d,
    output out_sop,
    output out_pos
); 

assign out_sop = (c&d) | (!a&!b&c);
assign out_pos = ~((!c) | (a&!b) | (b&!d));

endmodule


Problem 77 Karnaugh map

问题: 根据卡诺图来设计电路

Exams m2014q3.png​编辑

        思路:用卡洛图化简

​编辑

第一个框:x1非x3

第二个框:x3 x4

第三个框:x1 x2 x3非

解决:

module top_module (
    input [4:1] x, 
    output f );
	
assign f = (!x[1]&x[3]) | (x[3]&x[4]) | (x[1]&x[2]&!x[3]);

endmodule


Problem 78 Karnaugh map

问题: 根据卡诺图来设计电路

​编辑

思路: 用卡洛图化简表达式

​编辑

第一个框:x1非x3

第二个框:x2非x4非

第三个框:x2 x3 x4

解决:

module top_module (
    input [4:1] x, 
    output f );
	
assign f = (!x[1]&x[3]) | (!x[2]&!x[4]) | (x[2]&x[3]&x[4]);

endmodule


Problem 79 K-map implemented with a multiplexer

问题: 根据题目给出的卡诺图,用一个4-1的多路选择器和尽可能多的2-1多路选择器来实现电路,不允许使用其他逻辑门,必须使用ab作为选择器的输入

Ece241 2014 q3.png​编辑

Ece241 2014 q3mux.png​编辑

思路: 相当于把原来4*4的卡洛图拆分成了四分

​编辑

解决:

module top_module (
    input c,
    input d,
    output [3:0] mux_in
); 

assign mux_in = {c&d, !d ,1'b0 ,c|d}; 

endmodule

        注意: 输出高低位别弄错,卡洛图中是按格雷码排布的