mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-30 00:18:37 -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
|
||||
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
|
||||
|
@ -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);
|
||||
|
||||
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.add(d);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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());
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<attributes/>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>JK_FF</elementName>
|
||||
@ -11,24 +12,25 @@
|
||||
</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>withEnable</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>Q_0n</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="160" y="80"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
|
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