HDLbits 刷题 --Truthtable1

In the previous exercises, we used simple logic gates and combinations of several logic gates. These circuits are examples of combinational circuits. Combinational means the outputs of the circuit is a function (in the mathematics sense) of only its inputs. This means that for any given input value, there is only one possible output value. Thus, one way to describe the behaviour of a combinational function is to explicitly list what the output should be for every possible value of the inputs. This is a truth table.

For a boolean function of N inputs, there are 2N possible input combinations. Each row of the truth table lists one input combination, so there are always 2N rows. The output column shows what the output should be for each input value.

RowInputsOutputs
numberx3x2x1f
00000
10010
20101
30111
41000
51011
61100
71111

The above truth table is for a three-input, one-output function. It has 8 rows for each of the 8 possible input combinations, and one output column. There are four inputs combinations where the output is 1, and four where the output is 0.

Synthesizing a circuit from a truth table

Suppose we want to build the above circuit, but we're limited to using only the set of standard logic gates. How would you build arbitrary logic functions (expressed as a truth table)?

One simple method to create a circuit that implements the truth table's function is to express the function in sum-of-products form. Sum (meaning OR) of products (meaning AND) means using one N-input AND gate per row of the truth table (to detect when the input matches each row), followed by an OR gate that chooses only those rows that result in a '1' output.

For the above example, the output is '1' if the input matches row 2 or row 3 or row 5 or row 7 (This is a 4-input OR gate). The input matches row 2 if x3=0 and x2=1 and x1=0 (This is a 3-input AND gate). Thus, this truth table can be implemented in canonical form by using 4 AND gates that are ORed together.

译:

在之前的练习中,我们使用了简单的逻辑门和几个逻辑门的组合。这些电路是组合电路的例子。组合意味着电路的输出仅是其输入的函数(在数学意义上)。这意味着对于任何给定的输入值,只有一个可能的输出值。因此,描述组合函数行为的一种方法是显式列出输入的每个可能值的输出。这是一个真值表。

对于有N个输入的布尔函数,有2的N次方 种可能的输入组合。真值表的每一行列出一个输入组合,所以总是有2的N次方 行。输出列显示了每个输入值的输出。

上面的真值表适用于三输入一输出函数。它有8行对应8种可能的输入组合,还有一个输出列。有四种输入组合输出为1,还有四种输出为0。

从真值表合成电路

假设我们想要构建上述电路,但我们仅限于使用一组标准逻辑门。如何构建任意逻辑函数(表示为真值表)?

创建实现真值表功能的电路的一种简单方法是将函数表示为积和形式。 Sum(意思是OR) 或者 products(意思是AND)意味着在真值表的每行使用一个n输入的AND门(检测输入是否与每行匹配),后跟一个OR门,只选择那些输出为“1”的行。

对于上面的示例,如果输入匹配第2行或第3行或第5行或第7行,则输出为'1'(这是一个4输入or门)。如果x3=0, x2=1, x1=0,则输入匹配第2行(这是一个3输入与门)。因此,这个真值表可以通过使用4个与门来实现。

创建一个实现以上真值表的电路:

        

module top_module( 
    input x3,
    input x2,
    input x1,  // three inputs
    output f   // one output
);
    assign f = (!x3 & x2 & !x1) | (!x3 & x2 & x1) | (x3 & !x2 &x1) | (x3 & x2 &x1);
endmodule

分析:

在数字逻辑设计中,实现一个逻辑函数的一种方法是通过使用真值表来指导电路的设计。真值表列出了所有可能的输入组合以及对应的输出结果。要从真值表创建一个电路,我们可以使用一种称为“析取-并集”(sum-of-products)的形式来表达这个函数。

“析取-并集”形式意味着:

  • 并集(Products):对于真值表中的每一行,如果输出为'1',我们需要找到一个表达式来表示这个条件。这个表达式是由输入变量通过AND门组合而成的,每个这样的组合就是一个“产品项”(product term)。每个产品项对应于真值表中的一行,表示当输入满足这行的条件时,输出为'1'。

  • 析取(Sum):有了所有输出为'1'的产品项后,我们使用OR门将它们相加。这个过程称为“析取”,因为OR门的作用是将多个条件合并为一个单一的输出。只有当至少有一个产品项为'1'时,最终的输出才会为'1'。

例如,假设我们有一个2变量的逻辑函数,其真值表如下:

abOutput
000
011
101
110

为了实现这个逻辑函数,我们可以创建以下析取-并集表达式:

Output = (a AND NOT b) OR (NOT a AND b)

在这个表达式中,(a AND NOT b) 是第一个产品项,对应于真值表中输出为'1'的第二和第四行。(NOT a AND b) 是第二个产品项,对应于真值表中输出为'1'的第一和第三行。然后我们使用OR门将这两个产品项结合起来,得到最终的输出。

在硬件电路中,这个表达式可以通过使用AND门和OR门来实现。每个产品项由一个AND门实现,而所有的产品项通过一个OR门连接起来。这样,只有当真值表中对应于'1'的任一行的条件满足时,最终的输出才会为'1'。

简单来说: 实现真值表的方法就是,将输出为1的那一行,用多个与门表示出来,(如果输入是0 ,则取反,若输入为1 则直接与),然后再把各项或起来,就是完整的真值表了;

  • 16
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

刚及格的陆拾伍

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

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

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

打赏作者

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

抵扣说明:

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

余额充值