mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-30 16:30:04 -04:00
model analyser supports enable input of T-FF.
This commit is contained in:
parent
0eb4de7d19
commit
f56946feaf
@ -7,8 +7,12 @@ planned as v0.13
|
|||||||
CAUTION: All default values are lost! If you have built a circuit that contains
|
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
|
test cases that depend on a non-null default value, this tests will fail. To
|
||||||
resolve this issue, reset the default value.
|
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 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.
|
- Comments are allowed in hex files.
|
||||||
|
|
||||||
v0.12.1, released on 05. Jun 2016
|
v0.12.1, released on 05. Jun 2016
|
||||||
|
@ -254,8 +254,8 @@ public class ModelAnalyser {
|
|||||||
* Analyses the circuit
|
* Analyses the circuit
|
||||||
*
|
*
|
||||||
* @return the generated truth table
|
* @return the generated truth table
|
||||||
* @throws NodeException NodeException
|
* @throws NodeException NodeException
|
||||||
* @throws PinException PinException
|
* @throws PinException PinException
|
||||||
* @throws BacktrackException BacktrackException
|
* @throws BacktrackException BacktrackException
|
||||||
*/
|
*/
|
||||||
public TruthTable analyse() throws NodeException, PinException, BacktrackException {
|
public TruthTable analyse() throws NodeException, PinException, BacktrackException {
|
||||||
@ -303,8 +303,6 @@ public class ModelAnalyser {
|
|||||||
for (FlipflopJK jk : jkList) {
|
for (FlipflopJK jk : jkList) {
|
||||||
checkClock(jk);
|
checkClock(jk);
|
||||||
|
|
||||||
// remove JK-ff from model
|
|
||||||
model.removeNode(jk);
|
|
||||||
jk.getClockVal().removeObserver(jk);
|
jk.getClockVal().removeObserver(jk);
|
||||||
jk.getjVal().removeObserver(jk);
|
jk.getjVal().removeObserver(jk);
|
||||||
jk.getkVal().removeObserver(jk);
|
jk.getkVal().removeObserver(jk);
|
||||||
@ -330,28 +328,32 @@ public class ModelAnalyser {
|
|||||||
model.add(a2);
|
model.add(a2);
|
||||||
model.add(nk);
|
model.add(nk);
|
||||||
model.add(or);
|
model.add(or);
|
||||||
model.add(d);
|
model.replace(jk, d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void replaceTFF() throws NodeException, AnalyseException {
|
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);
|
checkClock(tff);
|
||||||
|
|
||||||
// remove T-ff from model
|
|
||||||
model.removeNode(tff);
|
|
||||||
tff.getClockVal().removeObserver(tff);
|
tff.getClockVal().removeObserver(tff);
|
||||||
|
|
||||||
// create d ff
|
|
||||||
ObservableValue q = tff.getOutputs().get(0);
|
ObservableValue q = tff.getOutputs().get(0);
|
||||||
ObservableValue qn = tff.getOutputs().get(1);
|
ObservableValue qn = tff.getOutputs().get(1);
|
||||||
FlipflopD d = new FlipflopD(tff.getLabel(), q, qn);
|
|
||||||
|
|
||||||
d.setInputs(new ObservableValues(qn, getClock()));
|
ObservableValue enable = tff.getEnableVal();
|
||||||
|
if (enable == null) {
|
||||||
model.add(d);
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,6 +546,7 @@ public class Model implements Iterable<Node> {
|
|||||||
return sigWithoutPinNumber;
|
return sigWithoutPinNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A filter for nodes.
|
* A filter for nodes.
|
||||||
*
|
*
|
||||||
@ -575,6 +576,21 @@ public class Model implements Iterable<Node> {
|
|||||||
nodes.remove(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.
|
* Returns the input with the given name.
|
||||||
*
|
*
|
||||||
|
@ -27,7 +27,7 @@ public class FlipflopJK extends Node implements Element {
|
|||||||
.addAttribute(Keys.INVERTER_CONFIG)
|
.addAttribute(Keys.INVERTER_CONFIG)
|
||||||
.addAttribute(Keys.VALUE_IS_PROBE);
|
.addAttribute(Keys.VALUE_IS_PROBE);
|
||||||
|
|
||||||
private final Boolean isProbe;
|
private final boolean isProbe;
|
||||||
private final String label;
|
private final String label;
|
||||||
private ObservableValue jVal;
|
private ObservableValue jVal;
|
||||||
private ObservableValue kVal;
|
private ObservableValue kVal;
|
||||||
@ -55,6 +55,23 @@ public class FlipflopJK extends Node implements Element {
|
|||||||
qn.setBool(!out);
|
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
|
@Override
|
||||||
public void readInputs() throws NodeException {
|
public void readInputs() throws NodeException {
|
||||||
boolean clock = clockVal.getBool();
|
boolean clock = clockVal.getBool();
|
||||||
|
@ -111,6 +111,13 @@ public class FlipflopT extends Node implements Element {
|
|||||||
return clockVal;
|
return clockVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return enable value or null if not available
|
||||||
|
*/
|
||||||
|
public ObservableValue getEnableVal() {
|
||||||
|
return enable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the label
|
* @return the label
|
||||||
*/
|
*/
|
||||||
|
@ -51,6 +51,12 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
check2BitCounter(tt);
|
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) {
|
private void check2BitCounter(TruthTable tt) {
|
||||||
assertEquals(4, tt.getRows());
|
assertEquals(4, tt.getRows());
|
||||||
assertEquals(4, tt.getCols());
|
assertEquals(4, tt.getCols());
|
||||||
|
@ -1,84 +1,86 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<circuit>
|
<circuit>
|
||||||
<version>1</version>
|
<version>1</version>
|
||||||
<visualElements>
|
<attributes/>
|
||||||
<visualElement>
|
<visualElements>
|
||||||
<elementName>JK_FF</elementName>
|
<visualElement>
|
||||||
<elementAttributes>
|
<elementName>JK_FF</elementName>
|
||||||
<entry>
|
<elementAttributes>
|
||||||
<string>Label</string>
|
<entry>
|
||||||
<string>Q_1n</string>
|
<string>Label</string>
|
||||||
</entry>
|
<string>Q_1n</string>
|
||||||
</elementAttributes>
|
</entry>
|
||||||
<pos x="160" y="-60"/>
|
</elementAttributes>
|
||||||
<rotate>0</rotate>
|
<pos x="160" y="-60"/>
|
||||||
</visualElement>
|
</visualElement>
|
||||||
<visualElement>
|
<visualElement>
|
||||||
<elementName>Clock</elementName>
|
<elementName>Clock</elementName>
|
||||||
<elementAttributes/>
|
<elementAttributes/>
|
||||||
<pos x="80" y="100"/>
|
<pos x="80" y="100"/>
|
||||||
<rotate>0</rotate>
|
</visualElement>
|
||||||
</visualElement>
|
<visualElement>
|
||||||
<visualElement>
|
<elementName>T_FF</elementName>
|
||||||
<elementName>T_FF</elementName>
|
<elementAttributes>
|
||||||
<elementAttributes>
|
<entry>
|
||||||
<entry>
|
<string>withEnable</string>
|
||||||
<string>Label</string>
|
<boolean>false</boolean>
|
||||||
<string>Q_0n</string>
|
</entry>
|
||||||
</entry>
|
<entry>
|
||||||
</elementAttributes>
|
<string>Label</string>
|
||||||
<pos x="160" y="80"/>
|
<string>Q_0n</string>
|
||||||
<rotate>0</rotate>
|
</entry>
|
||||||
</visualElement>
|
</elementAttributes>
|
||||||
</visualElements>
|
<pos x="160" y="80"/>
|
||||||
<wires>
|
</visualElement>
|
||||||
<wire>
|
</visualElements>
|
||||||
<p1 x="220" y="80"/>
|
<wires>
|
||||||
<p2 x="240" y="80"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="220" y="80"/>
|
||||||
<wire>
|
<p2 x="240" y="80"/>
|
||||||
<p1 x="120" y="80"/>
|
</wire>
|
||||||
<p2 x="160" y="80"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="120" y="80"/>
|
||||||
<wire>
|
<p2 x="160" y="80"/>
|
||||||
<p1 x="140" y="-20"/>
|
</wire>
|
||||||
<p2 x="160" y="-20"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="140" y="-20"/>
|
||||||
<wire>
|
<p2 x="160" y="-20"/>
|
||||||
<p1 x="80" y="100"/>
|
</wire>
|
||||||
<p2 x="120" y="100"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="80" y="100"/>
|
||||||
<wire>
|
<p2 x="120" y="100"/>
|
||||||
<p1 x="140" y="20"/>
|
</wire>
|
||||||
<p2 x="240" y="20"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="140" y="20"/>
|
||||||
<wire>
|
<p2 x="240" y="20"/>
|
||||||
<p1 x="120" y="-40"/>
|
</wire>
|
||||||
<p2 x="160" y="-40"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="120" y="-40"/>
|
||||||
<wire>
|
<p2 x="160" y="-40"/>
|
||||||
<p1 x="140" y="-60"/>
|
</wire>
|
||||||
<p2 x="160" y="-60"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="140" y="-60"/>
|
||||||
<wire>
|
<p2 x="160" y="-60"/>
|
||||||
<p1 x="240" y="20"/>
|
</wire>
|
||||||
<p2 x="240" y="80"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="240" y="20"/>
|
||||||
<wire>
|
<p2 x="240" y="80"/>
|
||||||
<p1 x="120" y="-40"/>
|
</wire>
|
||||||
<p2 x="120" y="80"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="120" y="-40"/>
|
||||||
<wire>
|
<p2 x="120" y="80"/>
|
||||||
<p1 x="120" y="80"/>
|
</wire>
|
||||||
<p2 x="120" y="100"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="120" y="80"/>
|
||||||
<wire>
|
<p2 x="120" y="100"/>
|
||||||
<p1 x="140" y="-60"/>
|
</wire>
|
||||||
<p2 x="140" y="-20"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="140" y="-60"/>
|
||||||
<wire>
|
<p2 x="140" y="-20"/>
|
||||||
<p1 x="140" y="-20"/>
|
</wire>
|
||||||
<p2 x="140" y="20"/>
|
<wire>
|
||||||
</wire>
|
<p1 x="140" y="-20"/>
|
||||||
</wires>
|
<p2 x="140" y="20"/>
|
||||||
|
</wire>
|
||||||
|
</wires>
|
||||||
</circuit>
|
</circuit>
|
83
src/test/resources/dig/analyze/analyzeTestTFFEnable.dig
Normal file
83
src/test/resources/dig/analyze/analyzeTestTFFEnable.dig
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user