mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-26 22:41:59 -04:00
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.
This commit is contained in:
parent
56bd90c13a
commit
982d077c11
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
157
src/test/resources/dig/test/fet/nchan.dig
Normal file
157
src/test/resources/dig/test/fet/nchan.dig
Normal file
@ -0,0 +1,157 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>NFET</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="500" y="180"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="3"/>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>D</string>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>isHighZ</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="500" y="120"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="1"/>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>d</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="540" y="120"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="1"/>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>S</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="500" y="280"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="3"/>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>s</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="540" y="280"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>G</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="460" y="220"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Testcase</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Testdata</string>
|
||||
<testData>
|
||||
<dataString>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
|
||||
</dataString>
|
||||
</testData>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="640" y="240"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="500" y="140"/>
|
||||
<p2 x="500" y="120"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="500" y="280"/>
|
||||
<p2 x="500" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="180"/>
|
||||
<p2 x="520" y="140"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="260"/>
|
||||
<p2 x="520" y="220"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="540" y="140"/>
|
||||
<p2 x="540" y="120"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="540" y="280"/>
|
||||
<p2 x="540" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="500" y="260"/>
|
||||
<p2 x="520" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="260"/>
|
||||
<p2 x="540" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="500" y="140"/>
|
||||
<p2 x="520" y="140"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="140"/>
|
||||
<p2 x="540" y="140"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="460" y="220"/>
|
||||
<p2 x="500" y="220"/>
|
||||
</wire>
|
||||
</wires>
|
||||
</circuit>
|
157
src/test/resources/dig/test/fet/pchan.dig
Normal file
157
src/test/resources/dig/test/fet/pchan.dig
Normal file
@ -0,0 +1,157 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="3"/>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>S</string>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>isHighZ</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="500" y="120"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="1"/>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>s</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="540" y="120"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="1"/>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>D</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="500" y="280"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>rotation</string>
|
||||
<rotation rotation="3"/>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>d</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="540" y="280"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>G</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="460" y="180"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Testcase</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Testdata</string>
|
||||
<testData>
|
||||
<dataString>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
|
||||
</dataString>
|
||||
</testData>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="640" y="240"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>PFET</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="500" y="180"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="500" y="260"/>
|
||||
<p2 x="520" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="260"/>
|
||||
<p2 x="540" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="460" y="180"/>
|
||||
<p2 x="500" y="180"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="500" y="140"/>
|
||||
<p2 x="520" y="140"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="140"/>
|
||||
<p2 x="540" y="140"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="500" y="120"/>
|
||||
<p2 x="500" y="140"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="500" y="260"/>
|
||||
<p2 x="500" y="280"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="140"/>
|
||||
<p2 x="520" y="180"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="520" y="220"/>
|
||||
<p2 x="520" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="540" y="120"/>
|
||||
<p2 x="540" y="140"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="540" y="260"/>
|
||||
<p2 x="540" y="280"/>
|
||||
</wire>
|
||||
</wires>
|
||||
</circuit>
|
Loading…
x
Reference in New Issue
Block a user