model analyser supports enable input of T-FF.

This commit is contained in:
hneemann 2017-06-22 10:18:31 +02:00
parent 0eb4de7d19
commit f56946feaf
8 changed files with 236 additions and 99 deletions

View File

@ -7,8 +7,12 @@ planned as v0.13
CAUTION: All default values are lost! If you have built a circuit that contains
test cases that depend on a non-null default value, this tests will fail. To
resolve this issue, reset the default value.
- added an enable input to the T flip-flop
CAUTION: By default this input is activated now. In circuits which used the T flip-flop
in the past, the new input needs to be disabled.
- A warning message shows up if a circuit with unnamed inputs/outputs is analysed.
- A warning message shows up if a circuit with missing pin numbers is exported to a hardware-related file.
- A warning message shows up if a circuit with missing pin numbers is exported to a
hardware-related file.
- Comments are allowed in hex files.
v0.12.1, released on 05. Jun 2016

View File

@ -254,8 +254,8 @@ public class ModelAnalyser {
* Analyses the circuit
*
* @return the generated truth table
* @throws NodeException NodeException
* @throws PinException PinException
* @throws NodeException NodeException
* @throws PinException PinException
* @throws BacktrackException BacktrackException
*/
public TruthTable analyse() throws NodeException, PinException, BacktrackException {
@ -303,8 +303,6 @@ public class ModelAnalyser {
for (FlipflopJK jk : jkList) {
checkClock(jk);
// remove JK-ff from model
model.removeNode(jk);
jk.getClockVal().removeObserver(jk);
jk.getjVal().removeObserver(jk);
jk.getkVal().removeObserver(jk);
@ -330,28 +328,32 @@ public class ModelAnalyser {
model.add(a2);
model.add(nk);
model.add(or);
model.add(d);
model.replace(jk, d);
}
}
private void replaceTFF() throws NodeException, AnalyseException {
List<FlipflopT> jkList = model.findNode(FlipflopT.class);
List<FlipflopT> tList = model.findNode(FlipflopT.class);
for (FlipflopT tff : jkList) {
for (FlipflopT tff : tList) {
checkClock(tff);
// remove T-ff from model
model.removeNode(tff);
tff.getClockVal().removeObserver(tff);
// create d ff
ObservableValue q = tff.getOutputs().get(0);
ObservableValue qn = tff.getOutputs().get(1);
FlipflopD d = new FlipflopD(tff.getLabel(), q, qn);
d.setInputs(new ObservableValues(qn, getClock()));
model.add(d);
ObservableValue enable = tff.getEnableVal();
if (enable == null) {
// create d ff
FlipflopD d = new FlipflopD(tff.getLabel(), q, qn);
d.setInputs(new ObservableValues(qn, getClock()));
model.replace(tff, d);
} else {
// create jk ff
enable.removeObserver(tff);
FlipflopJK jk = new FlipflopJK(tff.getLabel(), q, qn);
jk.setInputs(new ObservableValues(enable, getClock(), enable));
model.replace(tff, jk);
}
}
}

View File

@ -546,6 +546,7 @@ public class Model implements Iterable<Node> {
return sigWithoutPinNumber;
}
/**
* A filter for nodes.
*
@ -575,6 +576,21 @@ public class Model implements Iterable<Node> {
nodes.remove(node);
}
/**
* replaces a node by an other node
*
* @param oldNode old node
* @param newNode new node
* @throws NodeException NodeException
*/
public void replace(Node oldNode, Node newNode) throws NodeException {
int i = nodes.indexOf(oldNode);
if (i < 0)
throw new NodeException("node not found", oldNode, -1, null);
nodes.set(i, newNode);
}
/**
* Returns the input with the given name.
*

View File

@ -27,7 +27,7 @@ public class FlipflopJK extends Node implements Element {
.addAttribute(Keys.INVERTER_CONFIG)
.addAttribute(Keys.VALUE_IS_PROBE);
private final Boolean isProbe;
private final boolean isProbe;
private final String label;
private ObservableValue jVal;
private ObservableValue kVal;
@ -55,6 +55,23 @@ public class FlipflopJK extends Node implements Element {
qn.setBool(!out);
}
/**
* Creates a new instance
*
* @param label the label
* @param q the output
* @param qn the inverted output
*/
public FlipflopJK(String label, ObservableValue q, ObservableValue qn) {
super(true);
this.q = q;
this.qn = qn;
isProbe = false;
this.label = label;
q.setBool(false);
qn.setBool(true);
}
@Override
public void readInputs() throws NodeException {
boolean clock = clockVal.getBool();

View File

@ -111,6 +111,13 @@ public class FlipflopT extends Node implements Element {
return clockVal;
}
/**
* @return enable value or null if not available
*/
public ObservableValue getEnableVal() {
return enable;
}
/**
* @return the label
*/

View File

@ -51,6 +51,12 @@ public class ModelAnalyserTest extends TestCase {
check2BitCounter(tt);
}
public void testAnalyzerTFFEnable() throws Exception {
Model model = new ToBreakRunner("dig/analyze/analyzeTestTFFEnable.dig", false).getModel();
TruthTable tt = new ModelAnalyser(model).analyse();
check2BitCounter(tt);
}
private void check2BitCounter(TruthTable tt) {
assertEquals(4, tt.getRows());
assertEquals(4, tt.getCols());

View File

@ -1,84 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<visualElements>
<visualElement>
<elementName>JK_FF</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>Q_1n</string>
</entry>
</elementAttributes>
<pos x="160" y="-60"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Clock</elementName>
<elementAttributes/>
<pos x="80" y="100"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>Q_0n</string>
</entry>
</elementAttributes>
<pos x="160" y="80"/>
<rotate>0</rotate>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="220" y="80"/>
<p2 x="240" y="80"/>
</wire>
<wire>
<p1 x="120" y="80"/>
<p2 x="160" y="80"/>
</wire>
<wire>
<p1 x="140" y="-20"/>
<p2 x="160" y="-20"/>
</wire>
<wire>
<p1 x="80" y="100"/>
<p2 x="120" y="100"/>
</wire>
<wire>
<p1 x="140" y="20"/>
<p2 x="240" y="20"/>
</wire>
<wire>
<p1 x="120" y="-40"/>
<p2 x="160" y="-40"/>
</wire>
<wire>
<p1 x="140" y="-60"/>
<p2 x="160" y="-60"/>
</wire>
<wire>
<p1 x="240" y="20"/>
<p2 x="240" y="80"/>
</wire>
<wire>
<p1 x="120" y="-40"/>
<p2 x="120" y="80"/>
</wire>
<wire>
<p1 x="120" y="80"/>
<p2 x="120" y="100"/>
</wire>
<wire>
<p1 x="140" y="-60"/>
<p2 x="140" y="-20"/>
</wire>
<wire>
<p1 x="140" y="-20"/>
<p2 x="140" y="20"/>
</wire>
</wires>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>JK_FF</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>Q_1n</string>
</entry>
</elementAttributes>
<pos x="160" y="-60"/>
</visualElement>
<visualElement>
<elementName>Clock</elementName>
<elementAttributes/>
<pos x="80" y="100"/>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
<elementAttributes>
<entry>
<string>withEnable</string>
<boolean>false</boolean>
</entry>
<entry>
<string>Label</string>
<string>Q_0n</string>
</entry>
</elementAttributes>
<pos x="160" y="80"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="220" y="80"/>
<p2 x="240" y="80"/>
</wire>
<wire>
<p1 x="120" y="80"/>
<p2 x="160" y="80"/>
</wire>
<wire>
<p1 x="140" y="-20"/>
<p2 x="160" y="-20"/>
</wire>
<wire>
<p1 x="80" y="100"/>
<p2 x="120" y="100"/>
</wire>
<wire>
<p1 x="140" y="20"/>
<p2 x="240" y="20"/>
</wire>
<wire>
<p1 x="120" y="-40"/>
<p2 x="160" y="-40"/>
</wire>
<wire>
<p1 x="140" y="-60"/>
<p2 x="160" y="-60"/>
</wire>
<wire>
<p1 x="240" y="20"/>
<p2 x="240" y="80"/>
</wire>
<wire>
<p1 x="120" y="-40"/>
<p2 x="120" y="80"/>
</wire>
<wire>
<p1 x="120" y="80"/>
<p2 x="120" y="100"/>
</wire>
<wire>
<p1 x="140" y="-60"/>
<p2 x="140" y="-20"/>
</wire>
<wire>
<p1 x="140" y="-20"/>
<p2 x="140" y="20"/>
</wire>
</wires>
</circuit>

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>Clock</elementName>
<elementAttributes/>
<pos x="80" y="100"/>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>Q_1n</string>
</entry>
</elementAttributes>
<pos x="160" y="-60"/>
</visualElement>
<visualElement>
<elementName>T_FF</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>Q_0n</string>
</entry>
</elementAttributes>
<pos x="160" y="80"/>
</visualElement>
<visualElement>
<elementName>VDD</elementName>
<elementAttributes/>
<pos x="140" y="60"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="220" y="80"/>
<p2 x="240" y="80"/>
</wire>
<wire>
<p1 x="140" y="80"/>
<p2 x="160" y="80"/>
</wire>
<wire>
<p1 x="80" y="100"/>
<p2 x="120" y="100"/>
</wire>
<wire>
<p1 x="120" y="100"/>
<p2 x="160" y="100"/>
</wire>
<wire>
<p1 x="140" y="20"/>
<p2 x="240" y="20"/>
</wire>
<wire>
<p1 x="120" y="-40"/>
<p2 x="160" y="-40"/>
</wire>
<wire>
<p1 x="140" y="-60"/>
<p2 x="160" y="-60"/>
</wire>
<wire>
<p1 x="240" y="20"/>
<p2 x="240" y="80"/>
</wire>
<wire>
<p1 x="120" y="-40"/>
<p2 x="120" y="100"/>
</wire>
<wire>
<p1 x="140" y="-60"/>
<p2 x="140" y="20"/>
</wire>
<wire>
<p1 x="140" y="60"/>
<p2 x="140" y="80"/>
</wire>
</wires>
</circuit>