Logic Gates
Nand
Description:
Your task is to connect inputs to output through wires and relays such that when both a and b inputs are 1, the output is 0.
1 represents electrical current, 0 represents no current.
The V input carries constant current, i.e. always 1.
任务描述:
你的第一个任务,是使用继电器做出一个 与非门 元件。
与非门元件,只有当两个输入 a 和 b 均为1时,才输出0。
1 代表电路中有电流,0 代表没有电流。
输入 V 是一个恒定电流,就是一直保持为1的意思。
有2种不同类型的继电器:一种在平常(默认)状态下是导通的,需要电流来把它关断。另一种平常状态是关断的,需要电流来开通。
a
b
out
0
0
1
1
0
1
0
1
1
1
1
0
其逻辑可以使用 out = (not c) and in 描述. 当输入 in 为 1 时,可以充当 Not 门.
其逻辑可以使用 out = c and in 描述 可以充当 And 门
Nand 门的逻辑描述为 out = not (a and b)
经过数学推理:
o u t = ¬ ( a ∧ b ) = r e l a y o n ( r e l a y o f f ( a , b ) , V ) \begin{aligned}
out & = \neg (a \wedge b) \\
& = relay_{on}(relay_{off}(a,b),V)
\end{aligned}
o u t = ¬ ( a ∧ b ) = r e l a y o n ( r e l a y o f f ( a , b ) , V )
故解法的VHDL描述为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 library ieee;use ieee.std_logic_1164.all ;entity nand_gate is port ( a, b : in std_logic ; y : out std_logic ); end nand_gate;architecture struct of nand_gate is function relay_default_on(a_in, b_in : std_logic ) return std_logic is begin return (not a_in) and b_in; end function ; function relay_default_off(a_in, b_in : std_logic ) return std_logic is begin return a_in and b_in; end function ; signal temp : std_logic ; begin temp <= relay_default_off(a, b); y <= relay_default_on(temp, '1' ); end struct;
Invert
Description:
The next task is to build an inverter (inv ) component.
An inv -component has a single input and a single output.
The output should be the opposite of the input, so 0 for 1 and vice versa.
任务描述:
你的任务是做一个非门(inv )。
非门(inv )有一个输入和一个输出
输出和输入总是相反的:0得到1,1得到0。
元件的要求通常会被列在一个表中。
Inv 门的逻辑描述为 out = not in
经过数学推理:
o u t = ¬ i n = ¬ ( i n ∧ i n ) = n a n d ( i n , i n ) \begin{aligned}
out & = \neg in \\
& = \neg (in \wedge in) \\
& = nand(in,in)
\end{aligned}
o u t = ¬ i n = ¬ ( i n ∧ i n ) = n a n d ( i n , i n )
故解法的VHDL描述为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 library ieee;use ieee.std_logic_1164.all ;entity inv_gate is port ( a : in std_logic ; y : out std_logic ); end inv_gate;architecture struct of inv_gate is begin y <= a nand a; end struct;
And
Description:
An and gate’s output is 1 when both inputs are 1.
任务描述:
与门 只有在2个输入都是1的情况下,输出才是1.
a
b
out
0
0
0
1
0
0
0
1
0
1
1
1
And 门的逻辑描述为 out = a and b
经过数学推理:
o u t = a ∧ b = ¬ ( ¬ ( a ∧ b ) ) = i n v ( n a n d ( i n , i n ) ) \begin{aligned}
out & = a \wedge b \\
& = \neg(\neg(a \wedge b))\\
& = inv(nand(in,in))
\end{aligned}
o u t = a ∧ b = ¬ ( ¬ ( a ∧ b ) ) = i n v ( n a n d ( i n , i n ) )
故解法的VHDL描述为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 library ieee;use ieee.std_logic_1164.all ;entity and_gate is port ( a, b : in std_logic ; y : out std_logic ); end and_gate;architecture struct of and_gate is begin y <= not (a nand b); end struct;
Or
Description:
An or gate output is 1 when at least one input is 1.
a
b
out
0
0
0
1
0
1
0
1
1
1
1
1
Or 门的逻辑描述为 out = a or b
经过数学推理:
o u t = a ∨ b = ¬ ( ¬ ( a ∨ b ) ) = ¬ ( ¬ a ∧ ¬ b ) = n a n d ( i n v ( a ) , i n v ( b ) ) \begin{aligned}
out & = a \vee b \\
& = \neg(\neg(a \vee b))\\
& = \neg(\neg a \wedge \neg b)\\
& = nand(inv(a),inv(b))
\end{aligned}
o u t = a ∨ b = ¬ ( ¬ ( a ∨ b ) ) = ¬ ( ¬ a ∧ ¬ b ) = n a n d ( i n v ( a ) , i n v ( b ) )
故解法的VHDL描述为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 library ieee;use ieee.std_logic_1164.all ;entity or_gate is port ( a, b : in std_logic ; y : out std_logic ); end or_gate;architecture struct of or_gate is begin y <= (not a) nand (not b); end struct;
Xor
Description:
An xor gate’s output is 1 when the two inputs are different.
a
b
out
0
0
0
1
0
1
0
1
1
1
1
0
Xor 门的逻辑描述为 out = ((not a) and b) or (a and (not b))
经过数学推理:
o u t = ( ¬ a ∧ b ) ∨ ( a ∧ ¬ b ) = ( a ∧ ¬ a ) ∨ ( ¬ a ∧ b ) ∨ ( a ∧ ¬ b ) ∨ ( b ∧ ¬ b ) = ( a ∨ b ) ∧ ( ¬ a ∨ ¬ b ) = ¬ ( ¬ a ∧ ¬ b ) ∧ ¬ ( a ∧ b ) = ¬ ( ( ¬ a ∧ ¬ b ) ∨ ( a ∧ b ) ) = ¬ ( ( ¬ a ∧ ¬ b ) ∨ ( ( a ∧ b ) ∧ ( ¬ a ∨ ¬ b ∨ 1 ) ) ) = ¬ ( ( ¬ a ∧ ¬ b ) ∨ ( ( a ∧ b ) ∧ ¬ a ) ) ∨ ( ( a ∧ b ) ∧ ¬ b ) ∨ ( a ∧ b ) = ¬ ( ( ¬ a ∧ ¬ b ) ∨ ( ( a ∧ b ) ∧ ¬ a ) ) ∨ ( ( a ∧ b ) ∧ ¬ b ) ∨ ( ( a ∧ b ) ∧ ( a ∧ b ) ) = ¬ ( ( ¬ a ∨ ( a ∧ b ) ) ∧ ( ¬ b ∨ ( a ∧ b ) ) ) = ¬ ( ¬ ( a ∧ ¬ ( a ∧ b ) ) ∧ ¬ ( b ∧ ¬ ( a ∧ b ) ) ) = n a n d ( n a n d ( a , n a n d ( a , b ) ) , n a n d ( b , n a n d ( a , b ) ) ) \begin{aligned}
out & = (\neg a \wedge b) \vee (a \wedge \neg b) \\
& = (a \wedge \neg a) \vee (\neg a \wedge b) \vee (a \wedge \neg b) \vee (b \wedge \neg b)\\
& = (a \vee b) \wedge (\neg a \vee \neg b)\\
& = \neg (\neg a \wedge \neg b) \wedge \neg(a \wedge b)\\
& = \neg ((\neg a \wedge \neg b) \vee (a \wedge b))\\
& = \neg ((\neg a \wedge \neg b) \vee ((a \wedge b) \wedge (\neg a \vee \neg b \vee 1)))\\
& = \neg ((\neg a \wedge \neg b) \vee ((a \wedge b) \wedge \neg a)) \vee ((a \wedge b) \wedge \neg b) \vee (a \wedge b)\\
& = \neg ((\neg a \wedge \neg b) \vee ((a \wedge b) \wedge \neg a)) \vee ((a \wedge b) \wedge \neg b) \vee ((a \wedge b) \wedge (a \wedge b))\\
& = \neg ((\neg a \vee (a \wedge b)) \wedge (\neg b \vee (a \wedge b)))\\
& = \neg (\neg (a \wedge \neg (a \wedge b)) \wedge \neg (b \wedge \neg (a \wedge b)))\\
& = nand(nand(a,nand(a,b)),nand(b,nand(a,b)))
\end{aligned}
o u t = ( ¬ a ∧ b ) ∨ ( a ∧ ¬ b ) = ( a ∧ ¬ a ) ∨ ( ¬ a ∧ b ) ∨ ( a ∧ ¬ b ) ∨ ( b ∧ ¬ b ) = ( a ∨ b ) ∧ ( ¬ a ∨ ¬ b ) = ¬ ( ¬ a ∧ ¬ b ) ∧ ¬ ( a ∧ b ) = ¬ ( ( ¬ a ∧ ¬ b ) ∨ ( a ∧ b ) ) = ¬ ( ( ¬ a ∧ ¬ b ) ∨ ( ( a ∧ b ) ∧ ( ¬ a ∨ ¬ b ∨ 1 ) ) ) = ¬ ( ( ¬ a ∧ ¬ b ) ∨ ( ( a ∧ b ) ∧ ¬ a ) ) ∨ ( ( a ∧ b ) ∧ ¬ b ) ∨ ( a ∧ b ) = ¬ ( ( ¬ a ∧ ¬ b ) ∨ ( ( a ∧ b ) ∧ ¬ a ) ) ∨ ( ( a ∧ b ) ∧ ¬ b ) ∨ ( ( a ∧ b ) ∧ ( a ∧ b ) ) = ¬ ( ( ¬ a ∨ ( a ∧ b ) ) ∧ ( ¬ b ∨ ( a ∧ b ) ) ) = ¬ ( ¬ ( a ∧ ¬ ( a ∧ b ) ) ∧ ¬ ( b ∧ ¬ ( a ∧ b ) ) ) = n a n d ( n a n d ( a , n a n d ( a , b ) ) , n a n d ( b , n a n d ( a , b ) ) )
推导过程让我回忆起了:a + b = 1 a+b=1 a + b = 1 ,求1 a + 1 b \frac{1}{a}+\frac{1}{b} a 1 + b 1 的最小值。
故解法的VHDL描述为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 library ieee;use ieee.std_logic_1164.all ;entity xor_gate is port ( a, b : in std_logic ; y : out std_logic ); end xor_gate;architecture struct of xor_gate is signal s,m,n : std_logic ;begin s <= a nand b; m <= a nand s; n <= b nand s; y <= m nand n; end struct;
文章完
你完成了NandGame-Computer-Logic_gates章节!