[Verilog21]HDLBits习题_Karnaugh Map to Circuit

HDLBits习题讲解_Karnaugh Map to Circuit

真值表转为标准式

  • 真值表是表征逻辑事件输入和输出之间全部可能状态的表格。以1表示真,0表示假。
  • 标准式分为SOP标准式与POS标准式,其中:SOP标准式为找出真值表中所有输出为1的表项,按照输入的情况,为1用变量表示,为0则用反变量表示,得出若干乘积项,然后求和。POS标准式为,找出真值表中所有输出为0的表项,按照输入的情况,为1用反变量表示,为0则用原变量表示,得出若干求和项,然后求积。
  • 举例说明,如有以下真值表:
A B C out
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
  • 若针对所有F=1的表项,可轻松写出SOP标准式如下:
F=ABC+AB~C+A~(BC)+~ABC
  • 若针对所有F=0的表项,可轻松写出POS标准式如下:
F=(~A+B+~C)(A+~B+C)(A+B+~C)(A+B+C)

3-variable

BC\A 0 1
00 0 1
01 1 1
11 1 1
10 1 1
  • 实现上面卡诺图所描述的电路,代码如下:
module top_module(
    input a,
    input b,
    input c,
    output out  ); 
    assign out = ~((~a)&(~b)&(~c));
endmodule

4-variable(1)

CD\AB 00 01 11 10
00 1 1 0 1
01 1 0 0 1
11 0 1 1 1
10 1 1 0 0
  • 实现上面卡诺图所描述的电路,代码如下:
module top_module(
    input a,
    input b,
    input c,
    input d,
    output out  ); 
    assign out = ~a & ~d | ~b & ~c | b & c & d | a & c & d;
endmodule

4-variable(2)

CD\AB 00 01 11 10
00 d 0 1 1
01 0 0 d d
11 0 1 1 1
10 0 1 1 1
  • 实现上面卡诺图所描述的电路,其中,无关项d可以根据化简需求自己制定为0或是1,代码如下:
module top_module(
    input a,
    input b,
    input c,
    input d,
    output out  ); 
    assign out =  a | (~a&~b&c);
endmodule

4-variable(3)

CD\AB 00 01 11 10
00 0 1 0 1
01 1 0 1 0
11 0 1 0 1
10 1 0 1 0
  • 实现上面卡诺图所描述的电路,代码如下:
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

Minimum SOP and POS

  • 题目要求,实现一个有四输入(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格式的输出out_sop和最小POS格式的输出out_pos。代码如下:
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 | ~d) & (a | b | ~c));
endmodule

Karnaugh map(1)

CD\AB 00 01 11 10
00 d 0 d d
01 0 d 1 0
11 1 1 d d
10 1 1 0 d
  • 实现上面卡诺图所描述的电路,代码如下:
module top_module (
    input [4:1] x, 
    output f );
    assign f = ~x[1]&x[3] | x[2]&x[4];
endmodule

Karnaugh map(2)

CD\AB 00 01 11 10
00 1 0 0 1
01 0 0 0 0
11 1 1 1 0
10 1 1 0 1
  • 实现上面卡诺图所描述的电路,代码如下:
module top_module (
    input [4:1] x,
    output f
); 
    assign f = ~x[2]&~x[4] | ~x[1]&x[3] | x[2]&x[3]&x[4];
endmodule

K-map implemented with a multiplexer

  • 对于上面的卡诺图,用一个4-1多路选择器和不限的2-1多路选择器,但2-1多路选择器的使用要尽可能少。你不允许使用任何其他逻辑门,你必须使用a和b作为多路复用器选择器的输入,如上图中的4- 1多路复用器所示。代码如下:
module top_module (
    input c,
    input d,
    output [3:0] mux_in
);
    
    always @(*) begin
        case({c,d})
            2'b0:
                mux_in = 4'b0100;
            2'b1:
                mux_in = 4'b0001;
            2'b11:
                mux_in = 4'b1001;
            default:
                mux_in = 4'b0101;
        endcase
    end

endmodule

参考:
HDLBits
HDLBits答案(9)_卡诺图与最简SOP式