Added enable input to T-FF. Model analyser is not working yet.

This commit is contained in:
hneemann 2017-06-22 09:08:15 +02:00
parent 2ca9fa408f
commit 0eb4de7d19
22 changed files with 164 additions and 78 deletions

View File

@ -28,7 +28,12 @@ dann ausgeführt.</string>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
<elementAttributes/>
<elementAttributes>
<entry>
<string>withEnable</string>
<boolean>false</boolean>
</entry>
</elementAttributes>
<pos x="440" y="300"/>
</visualElement>
<visualElement>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>Out</elementName>
@ -11,7 +12,6 @@
</entry>
</elementAttributes>
<pos x="400" y="460"/>
<rotate>3</rotate>
</visualElement>
<visualElement>
<elementName>Clock</elementName>
@ -26,7 +26,6 @@
</entry>
</elementAttributes>
<pos x="280" y="360"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Out</elementName>
@ -37,7 +36,6 @@
</entry>
</elementAttributes>
<pos x="560" y="460"/>
<rotate>3</rotate>
</visualElement>
<visualElement>
<elementName>Out</elementName>
@ -48,7 +46,6 @@
</entry>
</elementAttributes>
<pos x="720" y="460"/>
<rotate>3</rotate>
</visualElement>
<visualElement>
<elementName>Out</elementName>
@ -59,7 +56,6 @@
</entry>
</elementAttributes>
<pos x="880" y="460"/>
<rotate>3</rotate>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
@ -68,13 +64,16 @@
<string>valueIsProbe</string>
<boolean>true</boolean>
</entry>
<entry>
<string>withEnable</string>
<boolean>false</boolean>
</entry>
<entry>
<string>Label</string>
<string>Q_0</string>
</entry>
</elementAttributes>
<pos x="320" y="360"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
@ -83,13 +82,22 @@
<string>valueIsProbe</string>
<boolean>true</boolean>
</entry>
<entry>
<string>withEnable</string>
<boolean>false</boolean>
</entry>
<entry>
<string>Label</string>
<string>Q_1</string>
</entry>
<entry>
<string>inverterConfig</string>
<inverterConfig>
<string>C</string>
</inverterConfig>
</entry>
</elementAttributes>
<pos x="480" y="360"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
@ -98,13 +106,22 @@
<string>valueIsProbe</string>
<boolean>true</boolean>
</entry>
<entry>
<string>withEnable</string>
<boolean>false</boolean>
</entry>
<entry>
<string>Label</string>
<string>Q_2</string>
</entry>
<entry>
<string>inverterConfig</string>
<inverterConfig>
<string>C</string>
</inverterConfig>
</entry>
</elementAttributes>
<pos x="640" y="360"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
@ -113,13 +130,22 @@
<string>valueIsProbe</string>
<boolean>true</boolean>
</entry>
<entry>
<string>withEnable</string>
<boolean>false</boolean>
</entry>
<entry>
<string>Label</string>
<string>Q_3</string>
</entry>
<entry>
<string>inverterConfig</string>
<inverterConfig>
<string>C</string>
</inverterConfig>
</entry>
</elementAttributes>
<pos x="800" y="360"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Data</elementName>
@ -138,7 +164,6 @@
</entry>
</elementAttributes>
<pos x="220" y="120"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Text</elementName>
@ -149,7 +174,6 @@
</entry>
</elementAttributes>
<pos x="260" y="80"/>
<rotate>0</rotate>
</visualElement>
</visualElements>
<wires>
@ -158,44 +182,32 @@
<p2 x="560" y="360"/>
</wire>
<wire>
<p1 x="600" y="360"/>
<p2 x="640" y="360"/>
<p1 x="280" y="360"/>
<p2 x="320" y="360"/>
</wire>
<wire>
<p1 x="380" y="360"/>
<p2 x="400" y="360"/>
</wire>
<wire>
<p1 x="280" y="360"/>
<p2 x="320" y="360"/>
</wire>
<wire>
<p1 x="440" y="360"/>
<p2 x="480" y="360"/>
</wire>
<wire>
<p1 x="700" y="360"/>
<p2 x="720" y="360"/>
</wire>
<wire>
<p1 x="760" y="360"/>
<p2 x="800" y="360"/>
</wire>
<wire>
<p1 x="860" y="360"/>
<p2 x="880" y="360"/>
</wire>
<wire>
<p1 x="540" y="380"/>
<p2 x="600" y="380"/>
<p1 x="560" y="360"/>
<p2 x="620" y="360"/>
</wire>
<wire>
<p1 x="380" y="380"/>
<p2 x="440" y="380"/>
<p1 x="400" y="360"/>
<p2 x="460" y="360"/>
</wire>
<wire>
<p1 x="700" y="380"/>
<p2 x="760" y="380"/>
<p1 x="720" y="360"/>
<p2 x="780" y="360"/>
</wire>
<wire>
<p1 x="560" y="360"/>
@ -213,17 +225,5 @@
<p1 x="720" y="360"/>
<p2 x="720" y="460"/>
</wire>
<wire>
<p1 x="440" y="360"/>
<p2 x="440" y="380"/>
</wire>
<wire>
<p1 x="760" y="360"/>
<p2 x="760" y="380"/>
</wire>
<wire>
<p1 x="600" y="360"/>
<p2 x="600" y="380"/>
</wire>
</wires>
</circuit>

View File

@ -25,22 +25,42 @@ Teilerverhältnisse 1/2, 1/4, 1/8 und 1/16.</string>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
<elementAttributes/>
<elementAttributes>
<entry>
<string>withEnable</string>
<boolean>false</boolean>
</entry>
</elementAttributes>
<pos x="240" y="120"/>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
<elementAttributes/>
<elementAttributes>
<entry>
<string>withEnable</string>
<boolean>false</boolean>
</entry>
</elementAttributes>
<pos x="340" y="120"/>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
<elementAttributes/>
<elementAttributes>
<entry>
<string>withEnable</string>
<boolean>false</boolean>
</entry>
</elementAttributes>
<pos x="440" y="120"/>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
<elementAttributes/>
<elementAttributes>
<entry>
<string>withEnable</string>
<boolean>false</boolean>
</entry>
</elementAttributes>
<pos x="540" y="120"/>
</visualElement>
<visualElement>

View File

@ -46,8 +46,8 @@ public class ModelAnalyser {
this.model = model;
try {
replaceJKFF();
replaceTFF();
replaceJKFF();
} catch (NodeException e) {
throw new AnalyseException(e);
}

View File

@ -76,7 +76,7 @@ public abstract class FanIn extends Node implements Element {
addAttribute(Keys.ROTATE);
addAttribute(Keys.BITS);
addAttribute(Keys.INPUT_COUNT);
addAttribute(Keys.INVERTERCONFIG);
addAttribute(Keys.INVERTER_CONFIG);
}
@Override

View File

@ -20,7 +20,7 @@ public class XNOr extends XOr {
= new ElementTypeDescription(XNOr.class, input("a"), input("b"))
.addAttribute(Keys.ROTATE)
.addAttribute(Keys.BITS)
.addAttribute(Keys.INVERTERCONFIG);
.addAttribute(Keys.INVERTER_CONFIG);
/**
* Creates a new instance

View File

@ -20,7 +20,7 @@ public class XOr extends Node implements Element {
= new ElementTypeDescription(XOr.class, input("a"), input("b"))
.addAttribute(Keys.ROTATE)
.addAttribute(Keys.BITS)
.addAttribute(Keys.INVERTERCONFIG);
.addAttribute(Keys.INVERTER_CONFIG);
private final int bits;
private final ObservableValue out;

View File

@ -277,7 +277,7 @@ public final class Keys {
/**
* output format for numbers
*/
public static final Key.KeyEnum<IntFormat> INTFORMAT
public static final Key.KeyEnum<IntFormat> INT_FORMAT
= new Key.KeyEnum<>("intFormat", IntFormat.def, IntFormat.values());
/**
@ -365,7 +365,7 @@ public final class Keys {
/**
* contains the input inverter config
*/
public static final Key<InverterConfig> INVERTERCONFIG
public static final Key<InverterConfig> INVERTER_CONFIG
= new Key<>("inverterConfig", new InverterConfig());
@ -378,4 +378,10 @@ public final class Keys {
.setMin(50)
.setMax(400);
/**
* true if a enable input is needed
*/
public static final Key<Boolean> WITH_ENABLE
= new Key<>("withEnable", true);
}

View File

@ -25,7 +25,7 @@ public class FlipflopD extends Node implements Element {
.addAttribute(Keys.BITS)
.addAttribute(Keys.LABEL)
.addAttribute(Keys.DEFAULT)
.addAttribute(Keys.INVERTERCONFIG)
.addAttribute(Keys.INVERTER_CONFIG)
.addAttribute(Keys.VALUE_IS_PROBE);
private final int bits;

View File

@ -25,7 +25,7 @@ public class FlipflopDAsync extends Node implements Element {
.addAttribute(Keys.BITS)
.addAttribute(Keys.LABEL)
.addAttribute(Keys.DEFAULT)
.addAttribute(Keys.INVERTERCONFIG)
.addAttribute(Keys.INVERTER_CONFIG)
.addAttribute(Keys.VALUE_IS_PROBE);
private final int bits;

View File

@ -24,7 +24,7 @@ public class FlipflopJK extends Node implements Element {
.addAttribute(Keys.ROTATE)
.addAttribute(Keys.LABEL)
.addAttribute(Keys.DEFAULT)
.addAttribute(Keys.INVERTERCONFIG)
.addAttribute(Keys.INVERTER_CONFIG)
.addAttribute(Keys.VALUE_IS_PROBE);
private final Boolean isProbe;

View File

@ -29,7 +29,7 @@ public class FlipflopJKAsync extends Node implements Element {
.addAttribute(Keys.ROTATE)
.addAttribute(Keys.LABEL)
.addAttribute(Keys.DEFAULT)
.addAttribute(Keys.INVERTERCONFIG)
.addAttribute(Keys.INVERTER_CONFIG)
.addAttribute(Keys.VALUE_IS_PROBE);
private final Boolean isProbe;

View File

@ -24,7 +24,7 @@ public class FlipflopRS extends Node implements Element {
.addAttribute(Keys.ROTATE)
.addAttribute(Keys.LABEL)
.addAttribute(Keys.DEFAULT)
.addAttribute(Keys.INVERTERCONFIG)
.addAttribute(Keys.INVERTER_CONFIG)
.addAttribute(Keys.VALUE_IS_PROBE);
private final boolean isProbe;

View File

@ -1,10 +1,7 @@
package de.neemann.digital.core.flipflops;
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.core.element.*;
import static de.neemann.digital.core.ObservableValues.ovs;
import static de.neemann.digital.core.element.PinInfo.input;
@ -20,17 +17,28 @@ public class FlipflopT extends Node implements Element {
* The T-FF description
*/
public static final ElementTypeDescription DESCRIPTION
= new ElementTypeDescription("T_FF", FlipflopT.class, input("C"))
= new ElementTypeDescription("T_FF", FlipflopT.class) {
@Override
public PinDescriptions getInputDescription(ElementAttributes elementAttributes) throws NodeException {
if (elementAttributes.get(Keys.WITH_ENABLE))
return new PinDescriptions(input("T"), input("C")).setLangKey(getPinLangKey());
else
return new PinDescriptions(input("C")).setLangKey(getPinLangKey());
}
}
.addAttribute(Keys.ROTATE)
.addAttribute(Keys.LABEL)
.addAttribute(Keys.WITH_ENABLE)
.addAttribute(Keys.DEFAULT)
.addAttribute(Keys.INVERTERCONFIG)
.addAttribute(Keys.INVERTER_CONFIG)
.addAttribute(Keys.VALUE_IS_PROBE);
private final boolean isProbe;
private final String label;
private final boolean isEnable;
private ObservableValue clockVal;
private ObservableValue enable;
private ObservableValue q;
private ObservableValue qn;
private boolean lastClock;
@ -45,6 +53,7 @@ public class FlipflopT extends Node implements Element {
super(true);
this.q = new ObservableValue("Q", 1).setPinDescription(DESCRIPTION);
this.qn = new ObservableValue("\u00ACQ", 1).setPinDescription(DESCRIPTION);
isEnable = attributes.get(Keys.WITH_ENABLE);
isProbe = attributes.get(Keys.VALUE_IS_PROBE);
label = attributes.getCleanLabel();
@ -58,7 +67,12 @@ public class FlipflopT extends Node implements Element {
public void readInputs() throws NodeException {
boolean clock = clockVal.getBool();
if (clock && !lastClock) {
out = !out;
if (enable == null)
out = !out;
else {
if (enable.getBool())
out = !out;
}
}
lastClock = clock;
}
@ -71,7 +85,11 @@ public class FlipflopT extends Node implements Element {
@Override
public void setInputs(ObservableValues inputs) throws BitsException {
clockVal = inputs.get(0).addObserverToValue(this).checkBits(1, this, 0);
if (isEnable) {
enable = inputs.get(0).addObserverToValue(this).checkBits(1, this, 0);
clockVal = inputs.get(1).addObserverToValue(this).checkBits(1, this, 1);
} else
clockVal = inputs.get(0).addObserverToValue(this).checkBits(1, this, 0);
}
@Override

View File

@ -22,7 +22,7 @@ public class Probe implements Element {
= new ElementTypeDescription("Probe", Probe.class, input("in"))
.addAttribute(Keys.ROTATE)
.addAttribute(Keys.LABEL)
.addAttribute(Keys.INTFORMAT);
.addAttribute(Keys.INT_FORMAT);
private final String label;
private ObservableValue value;

View File

@ -60,7 +60,7 @@ public class ModelEntry {
try {
HashMap<String, Pin> ins = pins.getInputs();
InverterConfig ic = visualElement.getElementAttributes().get(Keys.INVERTERCONFIG);
InverterConfig ic = visualElement.getElementAttributes().get(Keys.INVERTER_CONFIG);
ObservableValues values = ObservableValues.EMPTY_LIST;
ArrayList<ObservableValue> inputs = new ArrayList<>();

View File

@ -41,7 +41,7 @@ public class ProbeShape implements Shape {
if (label == null || label.length() == 0)
label = Lang.get("name");
this.label = label;
this.format = attr.get(Keys.INTFORMAT);
this.format = attr.get(Keys.INT_FORMAT);
}
@Override

View File

@ -166,7 +166,7 @@ public final class ShapeFactory {
pt.getOutputDescriptions(elementAttributes),
elementAttributes.getLabel(),
true)
.setInverterConfig(elementAttributes.get(Keys.INVERTERCONFIG));
.setInverterConfig(elementAttributes.get(Keys.INVERTER_CONFIG));
}
}
} else {
@ -200,7 +200,7 @@ public final class ShapeFactory {
public Shape create(ElementAttributes attributes, PinDescriptions inputs, PinDescriptions outputs) throws NodeException {
return new GenericShape(name, inputs, outputs)
.invert(invers)
.setInverterConfig(attributes.get(Keys.INVERTERCONFIG));
.setInverterConfig(attributes.get(Keys.INVERTER_CONFIG));
}
}
}

View File

@ -44,7 +44,7 @@ public abstract class IEEEGenericShape implements Shape {
this.inputs = inputs;
this.outputs = outputs;
this.invert = invert;
inverterConfig = attr.get(Keys.INVERTERCONFIG);
inverterConfig = attr.get(Keys.INVERTER_CONFIG);
}
@Override

View File

@ -331,8 +331,9 @@ Die gesammte Speichergröße beträgt damit damit dx*dy*2 Speicherworte.</string
<string name="elem_Sub_pin_c_o">Ausgang gibt 1 aus wenn bei der Substraktion ein Überlauf aufgetreten ist.</string>
<string name="elem_T_FF">T-FlipFlop</string>
<string name="elem_T_FF_short">T</string>
<string name="elem_T_FF_tt">Wechselt den Status der Ausgänge mit jeder 1 am Eingang.</string>
<string name="elem_T_FF_pin_C">Dieser Eingang nimmt ein Bit entgegen und wechselt jedes mal die Ausgänge wenn er auf 1 gesetzt wird (toggle).</string>
<string name="elem_T_FF_tt">Speichert ein Bit welches sich mit einem Eingang umschalten lässt.</string>
<string name="elem_T_FF_pin_T">Aktiviert die Umschaltfunktion.</string>
<string name="elem_T_FF_pin_C">Dieser Eingang schaltet das Flipflop um. Wenn ein T-Eingang vorhanden ist passiert das nur, wenn T auf 1 gesetzt ist.</string>
<string name="elem_T_FF_pin_Q">Gibt den gespeicherten Wert aus.</string>
<string name="elem_T_FF_pin_¬Q">Gibt den gespeicherten Wert negiert aus.</string>
<string name="elem_Terminal">Terminal</string>
@ -668,6 +669,8 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="key_fontSize">Schriftgröße im Menü [%]</string>
<string name="key_fontSize_tt">Für die Menüs kann eine abweichende Schriftgröße gewählt werden.
Angabe in Prozent der Standardgröße.</string>
<string name="key_withEnable">Enable Eingang</string>
<string name="key_withEnable_tt">Wenn gesetzt, ist ein Enable-Eingang (T) vorhanden.</string>
<string name="mod_insertWire">Leitung eingefügt.</string>
<string name="mod_insertCopied">Aus Zwischenablage eingefügt.</string>

View File

@ -325,8 +325,9 @@
<string name="elem_Sub_pin_c_o">Output returns 1 if an overflow occurred.</string>
<string name="elem_T_FF">T-FlipFlop</string>
<string name="elem_T_FF_short">T</string>
<string name="elem_T_FF_tt">A component with one input. Toggles the state of the output on a rising edge at the input.</string>
<string name="elem_T_FF_pin_C">Clock. A rising edge toggles the output.</string>
<string name="elem_T_FF_tt">Stores a single bit. Toggles the state on a rising edge at input C.</string>
<string name="elem_T_FF_pin_T">Enables the toggle function.</string>
<string name="elem_T_FF_pin_C">Clock. A rising edge toggles the output, if input T is set to 1.</string>
<string name="elem_T_FF_pin_Q">Returns the stored value.</string>
<string name="elem_T_FF_pin_¬Q">Returns the negated stored value.</string>
<string name="elem_Terminal">Terminal</string>
@ -657,6 +658,8 @@ The names of the variables may not be unique.</string>
<string name="key_inverterConfig_tt">You can select the inputs that are to be inverted.</string>
<string name="key_fontSize">Menus Font Size [%]</string>
<string name="key_fontSize_tt">Size of the fonts used in the menu in percent of the default size.</string>
<string name="key_withEnable">Enable Input</string>
<string name="key_withEnable_tt">If set an enable input (T) is available.</string>
<string name="mod_insertWire">Inserted wire.</string>
<string name="mod_insertCopied">Insert from clipboard.</string>

View File

@ -3,18 +3,21 @@ package de.neemann.digital.core.flipflops;
import de.neemann.digital.TestExecuter;
import de.neemann.digital.core.Model;
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.Keys;
import junit.framework.TestCase;
/**
* @author hneemann
*/
public class FlipflopT_Test extends TestCase {
public void testFlipFlop() throws Exception {
ObservableValue c = new ObservableValue("c", 1);
Model model = new Model();
FlipflopT out = model.add(new FlipflopT(new ElementAttributes().setBits(1)));
FlipflopT out = model.add(new FlipflopT(new ElementAttributes().setBits(1).set(Keys.WITH_ENABLE, false)));
out.setInputs(c.asList());
TestExecuter sc = new TestExecuter(model).setInputs(c).setOutputs(out.getOutputs());
@ -27,4 +30,32 @@ public class FlipflopT_Test extends TestCase {
sc.check(1, 0, 1);
sc.check(0, 0, 1);
}
public void testFlipFlopWithEnable() throws Exception {
ObservableValue t = new ObservableValue("t", 1);
ObservableValue c = new ObservableValue("c", 1);
Model model = new Model();
FlipflopT out = model.add(new FlipflopT(new ElementAttributes().setBits(1).set(Keys.WITH_ENABLE, true)));
out.setInputs(new ObservableValues(t, c));
TestExecuter sc = new TestExecuter(model).setInputs(t, c).setOutputs(out.getOutputs());
// T C Q ~Q
sc.check(1, 0, 0, 1);
sc.check(1, 1, 1, 0);
sc.check(1, 1, 1, 0);
sc.check(1, 0, 1, 0);
sc.check(1, 0, 1, 0);
sc.check(1, 1, 0, 1);
sc.check(1, 0, 0, 1);
sc.check(0, 1, 0, 1);
sc.check(0, 0, 0, 1);
sc.check(0, 1, 0, 1);
sc.check(0, 0, 0, 1);
sc.check(1, 1, 1, 0);
sc.check(0, 0, 1, 0);
sc.check(0, 1, 1, 0);
sc.check(0, 0, 1, 0);
}
}