added a transmission gate

This commit is contained in:
hneemann 2017-05-17 15:39:22 +02:00
parent 0de15ae196
commit 3667c073e5
8 changed files with 298 additions and 64 deletions

View File

@ -1,7 +1,37 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<circuit> <circuit>
<version>1</version> <version>1</version>
<attributes>
<entry>
<string>isDIL</string>
<boolean>true</boolean>
</entry>
<entry>
<string>pinCount</string>
<int>8</int>
</entry>
</attributes>
<visualElements> <visualElements>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>Q</string>
</entry>
</elementAttributes>
<pos x="520" y="140"/>
</visualElement>
<visualElement>
<elementName>TransGate</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="3"/>
</entry>
</elementAttributes>
<pos x="420" y="160"/>
</visualElement>
<visualElement> <visualElement>
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
@ -9,38 +39,22 @@
<string>Label</string> <string>Label</string>
<string>D</string> <string>D</string>
</entry> </entry>
</elementAttributes>
<pos x="380" y="40"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry> <entry>
<string>Label</string> <string>Default</string>
<string>C</string> <int>1</int>
</entry> </entry>
</elementAttributes> </elementAttributes>
<pos x="380" y="120"/> <pos x="300" y="140"/>
</visualElement> </visualElement>
<visualElement> <visualElement>
<elementName>Not</elementName> <elementName>TransGate</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<string>rotation</string> <string>rotation</string>
<rotation rotation="2"/> <rotation rotation="2"/>
</entry> </entry>
</elementAttributes> </elementAttributes>
<pos x="520" y="120"/> <pos x="380" y="140"/>
</visualElement>
<visualElement>
<elementName>Driver</elementName>
<elementAttributes>
<entry>
<string>flipSelPos</string>
<boolean>true</boolean>
</entry>
</elementAttributes>
<pos x="420" y="40"/>
</visualElement> </visualElement>
<visualElement> <visualElement>
<elementName>Not</elementName> <elementName>Not</elementName>
@ -50,17 +64,17 @@
<rotation rotation="3"/> <rotation rotation="3"/>
</entry> </entry>
</elementAttributes> </elementAttributes>
<pos x="540" y="60"/> <pos x="500" y="160"/>
</visualElement> </visualElement>
<visualElement> <visualElement>
<elementName>Out</elementName> <elementName>Not</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<string>Label</string> <string>rotation</string>
<string>Q</string> <rotation rotation="2"/>
</entry> </entry>
</elementAttributes> </elementAttributes>
<pos x="560" y="40"/> <pos x="480" y="220"/>
</visualElement> </visualElement>
<visualElement> <visualElement>
<elementName>Out</elementName> <elementName>Out</elementName>
@ -70,17 +84,27 @@
<string>~Q</string> <string>~Q</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
<pos x="560" y="120"/> <pos x="520" y="220"/>
</visualElement> </visualElement>
<visualElement> <visualElement>
<elementName>DriverInvSel</elementName> <elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>C</string>
</entry>
</elementAttributes>
<pos x="300" y="220"/>
</visualElement>
<visualElement>
<elementName>Not</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<string>rotation</string> <string>rotation</string>
<rotation rotation="1"/> <rotation rotation="1"/>
</entry> </entry>
</elementAttributes> </elementAttributes>
<pos x="460" y="80"/> <pos x="320" y="200"/>
</visualElement> </visualElement>
<visualElement> <visualElement>
<elementName>Testcase</elementName> <elementName>Testcase</elementName>
@ -95,73 +119,107 @@ C 1 1 0
C 0 0 1 C 0 0 1
0 0 0 1 0 0 0 1
0 1 0 1 0 1 0 1
C 1 1 0
C 0 0 1
</dataString> </dataString>
</testData> </testData>
</entry> </entry>
</elementAttributes> </elementAttributes>
<pos x="540" y="160"/> <pos x="480" y="240"/>
</visualElement> </visualElement>
</visualElements> </visualElements>
<wires> <wires>
<wire> <wire>
<p1 x="420" y="80"/> <p1 x="320" y="100"/>
<p2 x="440" y="80"/> <p2 x="360" y="100"/>
</wire> </wire>
<wire> <wire>
<p1 x="380" y="40"/> <p1 x="360" y="100"/>
<p2 x="400" y="40"/> <p2 x="460" y="100"/>
</wire> </wire>
<wire> <wire>
<p1 x="440" y="40"/> <p1 x="360" y="180"/>
<p2 x="460" y="40"/> <p2 x="400" y="180"/>
</wire> </wire>
<wire> <wire>
<p1 x="460" y="40"/> <p1 x="440" y="180"/>
<p2 x="540" y="40"/> <p2 x="460" y="180"/>
</wire> </wire>
<wire> <wire>
<p1 x="540" y="40"/> <p1 x="300" y="140"/>
<p2 x="560" y="40"/> <p2 x="340" y="140"/>
</wire> </wire>
<wire> <wire>
<p1 x="380" y="120"/> <p1 x="380" y="140"/>
<p2 x="420" y="120"/> <p2 x="420" y="140"/>
</wire> </wire>
<wire> <wire>
<p1 x="520" y="120"/> <p1 x="420" y="140"/>
<p2 x="540" y="120"/> <p2 x="500" y="140"/>
</wire> </wire>
<wire> <wire>
<p1 x="460" y="120"/> <p1 x="500" y="140"/>
<p2 x="480" y="120"/> <p2 x="520" y="140"/>
</wire> </wire>
<wire> <wire>
<p1 x="540" y="120"/> <p1 x="480" y="220"/>
<p2 x="560" y="120"/> <p2 x="500" y="220"/>
</wire> </wire>
<wire> <wire>
<p1 x="420" y="60"/> <p1 x="420" y="220"/>
<p2 x="420" y="80"/> <p2 x="440" y="220"/>
</wire> </wire>
<wire> <wire>
<p1 x="420" y="80"/> <p1 x="300" y="220"/>
<p2 x="420" y="120"/> <p2 x="320" y="220"/>
</wire> </wire>
<wire> <wire>
<p1 x="460" y="40"/> <p1 x="500" y="220"/>
<p2 x="460" y="60"/> <p2 x="520" y="220"/>
</wire>
<wire>
<p1 x="320" y="220"/>
<p2 x="360" y="220"/>
</wire>
<wire>
<p1 x="320" y="200"/>
<p2 x="320" y="220"/>
</wire>
<wire>
<p1 x="320" y="100"/>
<p2 x="320" y="160"/>
</wire>
<wire>
<p1 x="420" y="200"/>
<p2 x="420" y="220"/>
</wire>
<wire>
<p1 x="420" y="140"/>
<p2 x="420" y="160"/>
</wire>
<wire>
<p1 x="500" y="140"/>
<p2 x="500" y="160"/>
</wire>
<wire>
<p1 x="500" y="200"/>
<p2 x="500" y="220"/>
</wire>
<wire>
<p1 x="360" y="100"/>
<p2 x="360" y="120"/>
</wire>
<wire>
<p1 x="360" y="160"/>
<p2 x="360" y="180"/>
</wire>
<wire>
<p1 x="360" y="180"/>
<p2 x="360" y="220"/>
</wire> </wire>
<wire> <wire>
<p1 x="460" y="100"/> <p1 x="460" y="100"/>
<p2 x="460" y="120"/> <p2 x="460" y="180"/>
</wire>
<wire>
<p1 x="540" y="40"/>
<p2 x="540" y="60"/>
</wire>
<wire>
<p1 x="540" y="100"/>
<p2 x="540" y="120"/>
</wire> </wire>
</wires> </wires>
</circuit> </circuit>

View File

@ -0,0 +1,78 @@
package de.neemann.digital.core.switching;
import de.neemann.digital.core.*;
import de.neemann.digital.core.element.Element;
import de.neemann.digital.core.element.ElementAttributes;
import de.neemann.digital.core.element.ElementTypeDescription;
import de.neemann.digital.core.element.Keys;
import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.lang.Lang;
import static de.neemann.digital.core.element.PinInfo.input;
/**
* Transmission Gate
* Created by hneemann on 17.05.17.
*/
public class TransGate extends Node implements Element {
/**
* The transmission gate description
*/
public static final ElementTypeDescription DESCRIPTION = new ElementTypeDescription(TransGate.class, input("S"), input("~S"))
.addAttribute(Keys.ROTATE)
.addAttribute(Keys.BITS);
private final Switch aSwitch;
private ObservableValue s;
private ObservableValue ns;
private boolean closed;
/**
* Create a new instance
*
* @param attr the attributes
*/
public TransGate(ElementAttributes attr) {
aSwitch = new Switch(attr, false, "A", "B");
aSwitch.getOutput1().setPinDescription(DESCRIPTION);
aSwitch.getOutput2().setPinDescription(DESCRIPTION);
}
@Override
public void setInputs(ObservableValues inputs) throws NodeException {
s = inputs.get(0).checkBits(1, this, 0).addObserverToValue(this);
ns = inputs.get(1).checkBits(1, this, 1).addObserverToValue(this);
aSwitch.setInputs(new ObservableValues(inputs.get(2), inputs.get(3)));
}
@Override
public ObservableValues getOutputs() throws PinException {
return aSwitch.getOutputs();
}
@Override
public void readInputs() throws NodeException {
if (s.isHighZ() || ns.isHighZ())
closed = false;
else if (s.getBool() != ns.getBool())
closed = s.getBool();
}
@Override
public void writeOutputs() throws NodeException {
aSwitch.setClosed(closed);
}
@Override
public void init(Model model) throws NodeException {
aSwitch.init(model);
model.addObserver(event -> {
if (event.equals(ModelEvent.STEP)) {
if (!s.isHighZ() && !ns.isHighZ() && (s.getBool() == ns.getBool()))
throw new BurnException(Lang.get("err_invalidTransmissionGateState"), new ObservableValues(s, ns));
}
});
}
}

View File

@ -94,7 +94,8 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
.add(PullUp.DESCRIPTION) .add(PullUp.DESCRIPTION)
.add(PullDown.DESCRIPTION) .add(PullDown.DESCRIPTION)
.add(Driver.DESCRIPTION) .add(Driver.DESCRIPTION)
.add(DriverInvSel.DESCRIPTION)) .add(DriverInvSel.DESCRIPTION)
.add(TransGate.DESCRIPTION))
.add(new LibraryNode(Lang.get("lib_mux")) .add(new LibraryNode(Lang.get("lib_mux"))
.add(Multiplexer.DESCRIPTION) .add(Multiplexer.DESCRIPTION)
.add(Demultiplexer.DESCRIPTION) .add(Demultiplexer.DESCRIPTION)

View File

@ -88,6 +88,7 @@ public final class ShapeFactory {
map.put(FGNFET.DESCRIPTION.getName(), FGFETShapeN::new); map.put(FGNFET.DESCRIPTION.getName(), FGFETShapeN::new);
map.put(FGPFET.DESCRIPTION.getName(), FGFETShapeP::new); map.put(FGPFET.DESCRIPTION.getName(), FGFETShapeP::new);
map.put(PFET.DESCRIPTION.getName(), FETShapeP::new); map.put(PFET.DESCRIPTION.getName(), FETShapeP::new);
map.put(TransGate.DESCRIPTION.getName(), TransGateShape::new);
map.put(Out.DESCRIPTION.getName(), OutputShape::new); map.put(Out.DESCRIPTION.getName(), OutputShape::new);
map.put(Out.LEDDESCRIPTION.getName(), LEDShape::new); map.put(Out.LEDDESCRIPTION.getName(), LEDShape::new);
map.put(Button.DESCRIPTION.getName(), ButtonShape::new); map.put(Button.DESCRIPTION.getName(), ButtonShape::new);

View File

@ -0,0 +1,74 @@
package de.neemann.digital.draw.shapes;
import de.neemann.digital.core.Observer;
import de.neemann.digital.core.element.ElementAttributes;
import de.neemann.digital.core.element.PinDescriptions;
import de.neemann.digital.draw.elements.IOState;
import de.neemann.digital.draw.elements.Pin;
import de.neemann.digital.draw.elements.Pins;
import de.neemann.digital.draw.graphics.Graphic;
import de.neemann.digital.draw.graphics.Polygon;
import de.neemann.digital.draw.graphics.Style;
import de.neemann.digital.draw.graphics.Vector;
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
import static de.neemann.digital.draw.shapes.GenericShape.SIZE2;
/**
* Shape of a transmission gate.
* Created by hneemann on 17.05.17.
*/
public class TransGateShape implements Shape {
private static final int RAD = 4;
private static final int P = SIZE - 5;
private static final Polygon TOP = new Polygon(true)
.add(0, 0)
.add(0, -SIZE)
.add(SIZE * 2, 0)
.add(SIZE * 2, -SIZE)
.add(0, 0);
private static final Polygon BOTTOM = new Polygon(true)
.add(0, 0)
.add(0, SIZE)
.add(SIZE * 2, 0)
.add(SIZE * 2, SIZE)
.add(0, 0);
private final PinDescriptions input;
private final PinDescriptions output;
/**
* Creates a trantmission gate
*
* @param attr the attrobutes
* @param input inputs
* @param output outputs
*/
public TransGateShape(ElementAttributes attr, PinDescriptions input, PinDescriptions output) {
this.input = input;
this.output = output;
}
@Override
public Pins getPins() {
return new Pins()
.add(new Pin(new Vector(SIZE, -SIZE), input.get(0)))
.add(new Pin(new Vector(SIZE, SIZE), input.get(1)))
.add(new Pin(new Vector(0, 0), output.get(0)))
.add(new Pin(new Vector(SIZE * 2, 0), output.get(1)));
}
@Override
public InteractorInterface applyStateMonitor(IOState ioState, Observer guiObserver) {
return null;
}
@Override
public void drawTo(Graphic graphic, boolean highLight) {
graphic.drawPolygon(TOP, Style.NORMAL);
graphic.drawPolygon(BOTTOM, Style.NORMAL);
graphic.drawLine(new Vector(SIZE, -SIZE), new Vector(SIZE, -SIZE2), Style.NORMAL);
graphic.drawCircle(new Vector(SIZE - RAD, P - RAD), new Vector(SIZE + RAD, P + RAD), Style.NORMAL);
}
}

View File

@ -423,6 +423,13 @@ Die gesammte Speichergröße beträgt damit damit dx*dy*2 Speicherworte.</string
<string name="elem_LedMatrix_pin_r-data">Der Zeilen-Zustand der LEDs einer Spalte. Jedes Bit in diesem Datenwort repräsentiert den Zustand einer Zeile der aktuellen Spalte.</string> <string name="elem_LedMatrix_pin_r-data">Der Zeilen-Zustand der LEDs einer Spalte. Jedes Bit in diesem Datenwort repräsentiert den Zustand einer Zeile der aktuellen Spalte.</string>
<string name="elem_LedMatrix_pin_c-addr">Die Nummer der aktuellen Spalte, dessen Zustand gerade am anderen Eingang anliegt.</string> <string name="elem_LedMatrix_pin_c-addr">Die Nummer der aktuellen Spalte, dessen Zustand gerade am anderen Eingang anliegt.</string>
<string name="elem_TransGate">Transmissionsgatter</string>
<string name="elem_TransGate_tt">Ein reales Transmissionsgatter ist aus nur zwei Transistoren aufgebaut.</string>
<string name="elem_TransGate_pin_A">Eingang A</string>
<string name="elem_TransGate_pin_B">Eingang_B</string>
<string name="elem_TransGate_pin_S">Steuereingang</string>
<string name="elem_TransGate_pin_~S">Steuereingang, invertiert</string>
<string name="error">Fehler</string> <string name="error">Fehler</string>
<string name="err_DFlipflopWithoutALabel">Flipflop hat keine Bezeichnung!</string> <string name="err_DFlipflopWithoutALabel">Flipflop hat keine Bezeichnung!</string>
<string name="err_N_isNotInputOrOutput">Pin {0} in Element {1} ist werder Eingang noch Ausgang</string> <string name="err_N_isNotInputOrOutput">Pin {0} in Element {1} ist werder Eingang noch Ausgang</string>
@ -515,6 +522,7 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="err_testSignal_N_notFound">Testsignal {0} in der Schaltung nicht gefunden!</string> <string name="err_testSignal_N_notFound">Testsignal {0} in der Schaltung nicht gefunden!</string>
<string name="err_toManyBits_Found_N0_maxIs_N1">Es sind nur {1} Bits erlaubt, es sind jedoch {0} Bits angegeben!</string> <string name="err_toManyBits_Found_N0_maxIs_N1">Es sind nur {1} Bits erlaubt, es sind jedoch {0} Bits angegeben!</string>
<string name="err_MultiBitFlipFlopFound">Es sind keine Flipflops mit mehr als einem Bit erlaubt!</string> <string name="err_MultiBitFlipFlopFound">Es sind keine Flipflops mit mehr als einem Bit erlaubt!</string>
<string name="err_invalidTransmissionGateState">Die Steuereingänge eines Transmission-Gates müssen invertiert beschaltet werden!</string>
<string name="key_AddrBits">Adress-Bits</string> <string name="key_AddrBits">Adress-Bits</string>
<string name="key_AddrBits_tt">Anzahl der Adress-Bits die verwendet werden.</string> <string name="key_AddrBits_tt">Anzahl der Adress-Bits die verwendet werden.</string>

View File

@ -413,6 +413,13 @@
<string name="elem_LedMatrix_pin_r-data">The row state of the LEDs of a column. Each bit in this data word represents the state of a row of the current column.</string> <string name="elem_LedMatrix_pin_r-data">The row state of the LEDs of a column. Each bit in this data word represents the state of a row of the current column.</string>
<string name="elem_LedMatrix_pin_c-addr">The number of the current column whose state is currently visible at the other input.</string> <string name="elem_LedMatrix_pin_c-addr">The number of the current column whose state is currently visible at the other input.</string>
<string name="elem_TransGate">Transmission-Gate</string>
<string name="elem_TransGate_tt">A real transmission-gate is build from only two transistors.</string>
<string name="elem_TransGate_pin_A">input A</string>
<string name="elem_TransGate_pin_B">input B</string>
<string name="elem_TransGate_pin_S">control input.</string>
<string name="elem_TransGate_pin_~S">inverted control input</string>
<string name="error">Error</string> <string name="error">Error</string>
<string name="err_DFlipflopWithoutALabel">D-flip-flop has no label set</string> <string name="err_DFlipflopWithoutALabel">D-flip-flop has no label set</string>
<string name="err_N_isNotInputOrOutput">Pin {0} in component {1} is not a input or output</string> <string name="err_N_isNotInputOrOutput">Pin {0} in component {1} is not a input or output</string>
@ -505,6 +512,7 @@ The names of the variables may not be unique.</string>
<string name="err_testSignal_N_notFound">Test signal {0} not found in the circuit!</string> <string name="err_testSignal_N_notFound">Test signal {0} not found in the circuit!</string>
<string name="err_toManyBits_Found_N0_maxIs_N1">Only {1} bits allowed, but {0} bits found!</string> <string name="err_toManyBits_Found_N0_maxIs_N1">Only {1} bits allowed, but {0} bits found!</string>
<string name="err_MultiBitFlipFlopFound">Flipflops with more then one bits are not allowed!</string> <string name="err_MultiBitFlipFlopFound">Flipflops with more then one bits are not allowed!</string>
<string name="err_invalidTransmissionGateState">The two control inputs of a transmission gate must be inverted!</string>
<string name="key_AddrBits">Address Bits</string> <string name="key_AddrBits">Address Bits</string>
<string name="key_AddrBits_tt">Number of address bits used.</string> <string name="key_AddrBits_tt">Number of address bits used.</string>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<circuit> <circuit>
<version>1</version> <version>1</version>
<attributes/>
<visualElements> <visualElements>
<visualElement> <visualElement>
<elementName>And</elementName> <elementName>And</elementName>
@ -422,6 +423,11 @@
<elementAttributes/> <elementAttributes/>
<pos x="840" y="640"/> <pos x="840" y="640"/>
</visualElement> </visualElement>
<visualElement>
<elementName>TransGate</elementName>
<elementAttributes/>
<pos x="800" y="740"/>
</visualElement>
</visualElements> </visualElements>
<wires/> <wires/>
</circuit> </circuit>