0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NANDだけでCPUを設計②NOTとは

0
Posted at

目次

NOTとは

入力が1の時に0となり、0の時に1となります。

真理値表

a y
0 1
1 0

入力をNANDの2つの入力に繋ぐと実現できます。
a=b=0 の行を見ると y=1(0が反転して1)、a=b=1 の行を見ると y=0(1が反転して0)となっています。

NANDの真理値表を見てみます。

a b y
0 0 1
0 1 1
1 0 1
1 1 0

a=bの時はyがaとbを反転させた結果になっています。

動きを見てみる

/opt/simulide-110sr0/simulide not.sim1
  • a=0 時、出力が1となりLEDが光る
0
  • a=1 時、出力が0となりLEDは光らない
1

回路のXML

not.sim1
not.sim1
<circuit version="1.1.0-SR0" rev="1917" stepSize="1000000" stepsPS="1000000" NLsteps="100000" reaStep="1000000" animate="0" >

<item itemtype="Fixed Voltage" CircId="Fixed Voltage-1" mainComp="false" Show_id="false" Show_Val="false" Pos="52,-4" rotation="0" hflip="1" vflip="1" label="Fixed Voltage-1" idLabPos="-64,-24" labelrot="0" valLabPos="-16,8" valLabRot="0" Voltage="5 V" Out="false" />

<item itemtype="And Gate" CircId="And Gate-4" mainComp="false" Show_id="false" Show_Val="false" Pos="104,-4" rotation="0" hflip="1" vflip="1" label="And Gate-4" idLabPos="-16,-24" labelrot="0" valLabPos="-16,20" valLabRot="0" Input_High_V="2.5 V" Input_Low_V="2.5 V" Input_Imped="1000 MΩ" Num_Inputs="2" Invert_Inputs="false" Out_High_V="5 V" Out_Low_V="0 V" Out_Imped="40 Ω" initHigh="false" Inverted="true" Open_Collector="false" Tpd_ps="10 ns" Tr_ps="3 ns" Tf_ps="4 ns" />

<item itemtype="Led" CircId="Led-5" mainComp="false" Show_id="false" Show_Val="false" Pos="192,-4" rotation="0" hflip="1" vflip="1" label="Led-5" idLabPos="-16,-24" labelrot="0" valLabPos="-16,20" valLabRot="0" Color="Yellow" Grounded="false" Threshold="2.4 V" MaxCurrent="30 mA" Resistance="0.6 Ω" />

<item itemtype="Ground" CircId="Ground-6" mainComp="false" Show_id="false" Show_Val="false" Pos="216,28" rotation="0" hflip="1" vflip="1" label="Ground-6" idLabPos="-16,8" labelrot="0" valLabPos="-16,20" valLabRot="0" />

<item itemtype="Resistor" CircId="Resistor-12" mainComp="false" ShowProp="Resistance" Show_id="false" Show_Val="true" Pos="148,-4" rotation="0" hflip="1" vflip="1" label="Resistor-12" idLabPos="-16,-24" labelrot="0" valLabPos="-16,6" valLabRot="0" Resistance="50 Ω" />

<item itemtype="Resistor" CircId="Resistor-18" mainComp="false" ShowProp="Resistance" Show_id="false" Show_Val="true" Pos="96,-48" rotation="0" hflip="1" vflip="1" label="Resistor-18" idLabPos="-16,-24" labelrot="0" valLabPos="-16,6" valLabRot="0" Resistance="70 Ω" />

<item itemtype="Led" CircId="Led-19" mainComp="false" Show_id="false" Show_Val="false" Pos="140,-48" rotation="0" hflip="1" vflip="1" label="Led-19" idLabPos="-16,-24" labelrot="0" valLabPos="-16,20" valLabRot="0" Color="Yellow" Grounded="false" Threshold="2.4 V" MaxCurrent="30 mA" Resistance="0.6 Ω" />

<item itemtype="Ground" CircId="Ground-21" mainComp="false" Show_id="false" Show_Val="false" Pos="164,-16" rotation="0" hflip="1" vflip="1" label="Ground-21" idLabPos="-16,8" labelrot="0" valLabPos="-16,20" valLabRot="0" />

<item itemtype="Node" CircId="Node-13" mainComp="false" Pos="88,-4" />

<item itemtype="Node" CircId="Node-22" mainComp="false" Pos="80,-4" />

<item itemtype="Connector" uid="Connector-26" startpinid="And Gate-4-out" endpinid="Resistor-12-lPin" pointList="120,-4,132,-4" />

<item itemtype="Connector" uid="Connector-27" startpinid="Resistor-12-rPin" endpinid="Led-5-lPin" pointList="164,-4,176,-4" />

<item itemtype="Connector" uid="Connector-28" startpinid="Led-5-rPin" endpinid="Ground-6-Gnd" pointList="208,-4,216,-4,216,12" />

<item itemtype="Connector" uid="Connector-31" startpinid="And Gate-4-in1" endpinid="Node-13-0" pointList="88,0,88,-4" />

<item itemtype="Connector" uid="Connector-32" startpinid="Node-13-2" endpinid="And Gate-4-in0" pointList="88,-4,88,-8" />

<item itemtype="Connector" uid="Connector-33" startpinid="Resistor-18-rPin" endpinid="Led-19-lPin" pointList="112,-48,124,-48" />

<item itemtype="Connector" uid="Connector-35" startpinid="Led-19-rPin" endpinid="Ground-21-Gnd" pointList="156,-48,164,-48,164,-32" />

<item itemtype="Connector" uid="Connector-36" startpinid="Resistor-18-lPin" endpinid="Node-22-1" pointList="80,-48,80,-4" />

<item itemtype="Connector" uid="Connector-37" startpinid="Fixed Voltage-1-outnod" endpinid="Node-22-0" pointList="68,-4,80,-4" />

<item itemtype="Connector" uid="Connector-38" startpinid="Node-22-2" endpinid="Node-13-1" pointList="80,-4,88,-4" />

</circuit>

VerilogでNOT素子を作る

コンパイル及び実行

iverilog -o not_tb.out nand.v not.v tb_not.v
vvp not_tb.out

波形の確認

gtkwave nand.vcd

ファイル構成

nandcpu/
├── nand.v     # NAND素子(最小単位)
├── not.v      # NANDで作ったNOT
└── tb_not.v   # NOTの動作確認
nand.v
`timescale 1ns/1ps

// NAND素子の定義(これを最小単位とする)
module nand_gate (
    input a,
    input b,
    output y
);

    nand(y,a,b);
endmodule
not.v
`timescale 1ns/1ps

module not_gate (
    input a, // 入力
    output y // 出力
);

    nand_gate u_not (
        .a(a), // 入力aをNANDのAに繋ぐ
        .b(a), // 同じくNANDのBにも繋ぐ
        .y(y)
    );

endmodule
tb_not.v
`timescale 1ns/1ps

module tb_not;
    reg a;
    wire y;
    
    not_gate uut ( .a(a), .y(y)); //notを一個配置
    
    initial begin
        $dumpfile("not.vcd"); // 出力する波形
        $dumpvars(0, tb_not); // 全階層の波形を記録
        
        $display("A | Y");
        $monitor("%d | %d", a, y);
        
        a=0;#10
        a=1;#10
        
        $finish;
    end
endmodule

動作結果

test@test-fujitsu:~/kaihatsu/nandcpu$ vvp not_tb.out
VCD info: dumpfile not.vcd opened for output.
A | Y
0 | 1
1 | 0

波形を確認します。

test@test-fujitsu:~/kaihatsu/nandcpu$ gtkwave not.vcd
wave
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?