From 982d077c11e540a21c7e37368c3b5885b47780a4 Mon Sep 17 00:00:00 2001 From: hneemann Date: Thu, 23 Feb 2017 09:53:00 +0100 Subject: [PATCH] fets behave more like fets and not like relays. If a n-chan fat has a high gate and a high source, this fet is not conducting. Also if the gate is high and source is floating the fet is not conducting. --- .../de/neemann/digital/core/wiring/NFET.java | 16 +- .../de/neemann/digital/core/wiring/PFET.java | 17 +- .../de/neemann/digital/core/wiring/Relay.java | 14 +- .../digital/integration/TestExamples.java | 4 +- src/test/resources/dig/test/fet/nchan.dig | 157 ++++++++++++++++++ src/test/resources/dig/test/fet/pchan.dig | 157 ++++++++++++++++++ 6 files changed, 355 insertions(+), 10 deletions(-) create mode 100644 src/test/resources/dig/test/fet/nchan.dig create mode 100644 src/test/resources/dig/test/fet/pchan.dig diff --git a/src/main/java/de/neemann/digital/core/wiring/NFET.java b/src/main/java/de/neemann/digital/core/wiring/NFET.java index af8a36a66..b60a208af 100644 --- a/src/main/java/de/neemann/digital/core/wiring/NFET.java +++ b/src/main/java/de/neemann/digital/core/wiring/NFET.java @@ -1,5 +1,8 @@ package de.neemann.digital.core.wiring; +import de.neemann.digital.core.NodeException; +import de.neemann.digital.core.ObservableValue; +import de.neemann.digital.core.ObservableValues; import de.neemann.digital.core.element.ElementAttributes; import de.neemann.digital.core.element.ElementTypeDescription; import de.neemann.digital.core.element.Keys; @@ -31,8 +34,17 @@ public class NFET extends Relay { } @Override - protected boolean getClosed(boolean inState, boolean inHighZ) { - return !inHighZ && inState; + protected boolean getClosed(boolean inState, boolean inHighZ, ObservableValue in1, ObservableValue in2) { + if (inHighZ || in2.isHighZ()) + return false; + return inState && !in2.getBool(); } + + @Override + public void setInputs(ObservableValues inputs) throws NodeException { + super.setInputs(inputs); + inputs.get(2).addObserverToValue(this); + } + } diff --git a/src/main/java/de/neemann/digital/core/wiring/PFET.java b/src/main/java/de/neemann/digital/core/wiring/PFET.java index 2a76d8e45..392722408 100644 --- a/src/main/java/de/neemann/digital/core/wiring/PFET.java +++ b/src/main/java/de/neemann/digital/core/wiring/PFET.java @@ -1,5 +1,8 @@ package de.neemann.digital.core.wiring; +import de.neemann.digital.core.NodeException; +import de.neemann.digital.core.ObservableValue; +import de.neemann.digital.core.ObservableValues; import de.neemann.digital.core.element.ElementAttributes; import de.neemann.digital.core.element.ElementTypeDescription; import de.neemann.digital.core.element.Keys; @@ -31,7 +34,17 @@ public class PFET extends Relay { } @Override - protected boolean getClosed(boolean inState, boolean inHighZ) { - return !inHighZ && !inState; + protected boolean getClosed(boolean inState, boolean inHighZ, ObservableValue in1, ObservableValue in2) { + if (inHighZ || in1.isHighZ()) + return false; + + return !inState && in1.getBool(); } + + @Override + public void setInputs(ObservableValues inputs) throws NodeException { + super.setInputs(inputs); + inputs.get(1).addObserverToValue(this); + } + } diff --git a/src/main/java/de/neemann/digital/core/wiring/Relay.java b/src/main/java/de/neemann/digital/core/wiring/Relay.java index be770c1c3..6ef914fbd 100644 --- a/src/main/java/de/neemann/digital/core/wiring/Relay.java +++ b/src/main/java/de/neemann/digital/core/wiring/Relay.java @@ -30,6 +30,8 @@ public class Relay extends Node implements Element { private ObservableValue input; private boolean state; private boolean stateHighZ; + private ObservableValue in1; + private ObservableValue in2; /** * Create a new instance @@ -49,7 +51,9 @@ public class Relay extends Node implements Element { @Override public void setInputs(ObservableValues inputs) throws NodeException { input = inputs.get(0).checkBits(1, this).addObserverToValue(this); - s.setInputs(new ObservableValues(inputs.get(1), inputs.get(2))); + in1 = inputs.get(1); + in2 = inputs.get(2); + s.setInputs(new ObservableValues(in1, in2)); } @Override @@ -60,17 +64,19 @@ public class Relay extends Node implements Element { @Override public void writeOutputs() throws NodeException { - s.setClosed(getClosed(state, stateHighZ)); + s.setClosed(getClosed(state, stateHighZ, in1, in2)); } /** * get the closed state * - * @param inState the input state + * @param inState the input state * @param inHighZ input high z value + * @param in1 input 1 + * @param in2 input 2 * @return true if switch is to close */ - protected boolean getClosed(boolean inState, boolean inHighZ) { + protected boolean getClosed(boolean inState, boolean inHighZ, ObservableValue in1, ObservableValue in2) { if (inHighZ) return invers; diff --git a/src/test/java/de/neemann/digital/integration/TestExamples.java b/src/test/java/de/neemann/digital/integration/TestExamples.java index c1546c38d..0fc9690d9 100644 --- a/src/test/java/de/neemann/digital/integration/TestExamples.java +++ b/src/test/java/de/neemann/digital/integration/TestExamples.java @@ -39,8 +39,8 @@ public class TestExamples extends TestCase { */ public void testTestExamples() throws Exception { File examples = new File(Resources.getRoot(), "/dig/test"); - assertEquals(43, new FileScanner(this::check).scan(examples)); - assertEquals(33, testCasesInFiles); + assertEquals(45, new FileScanner(this::check).scan(examples)); + assertEquals(35, testCasesInFiles); } diff --git a/src/test/resources/dig/test/fet/nchan.dig b/src/test/resources/dig/test/fet/nchan.dig new file mode 100644 index 000000000..82ec97825 --- /dev/null +++ b/src/test/resources/dig/test/fet/nchan.dig @@ -0,0 +1,157 @@ + + + 1 + + + NFET + + + + + In + + + rotation + + + + Label + D + + + isHighZ + true + + + + + + Out + + + rotation + + + + Label + d + + + + + + In + + + rotation + + + + Label + S + + + + + + Out + + + rotation + + + + Label + s + + + + + + In + + + Label + G + + + + + + Testcase + + + Testdata + + S D G s d +1 z 0 1 z +z 1 0 z 1 +1 z z 1 z +z 1 z z 1 + +# gate is high but fet is not conducting +# because source is not low +z 0 1 z 0 +z z 1 z z +z 1 1 z 1 +1 z 1 1 z + +# switch test +0 z 1 0 0 +1 z 1 1 z +0 z 1 0 0 +1 z 1 1 z + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/dig/test/fet/pchan.dig b/src/test/resources/dig/test/fet/pchan.dig new file mode 100644 index 000000000..e475356e8 --- /dev/null +++ b/src/test/resources/dig/test/fet/pchan.dig @@ -0,0 +1,157 @@ + + + 1 + + + In + + + rotation + + + + Label + S + + + isHighZ + true + + + + + + Out + + + rotation + + + + Label + s + + + + + + In + + + rotation + + + + Label + D + + + + + + Out + + + rotation + + + + Label + d + + + + + + In + + + Label + G + + + + + + Testcase + + + Testdata + + S D G s d +1 z 1 1 z +z 1 1 z 1 +1 z z 1 z +z 1 z z 1 + +# gate is low but fet is not conducting +# because source is not high +z 0 0 z 0 +z z 0 z z +z 1 0 z 1 +0 z 0 0 z + +# switch test +0 z 0 0 z +1 z 0 1 1 +0 z 0 0 z +1 z 0 1 1 + + + + + + + + PFET + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file