mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-15 07:48:29 -04:00
shows measured frequency if clock is set to a value above 2kHz
This commit is contained in:
parent
ef16453939
commit
47fec320ee
@ -228,7 +228,7 @@ Single-Cycle CPU.}}</string>
|
|||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>Frequency</string>
|
<string>Frequency</string>
|
||||||
<int>500000</int>
|
<int>2147483647</int>
|
||||||
</entry>
|
</entry>
|
||||||
</elementAttributes>
|
</elementAttributes>
|
||||||
<pos x="1220" y="580"/>
|
<pos x="1220" y="580"/>
|
||||||
|
@ -99,6 +99,11 @@ public class RealTimeClock implements ModelStateObserverTyped {
|
|||||||
private final ScheduledFuture<?> timer;
|
private final ScheduledFuture<?> timer;
|
||||||
|
|
||||||
RealTimeRunner(int delay) {
|
RealTimeRunner(int delay) {
|
||||||
|
FrequencyCalculator frequencyCalculator;
|
||||||
|
if (frequency > 2000)
|
||||||
|
frequencyCalculator = new FrequencyCalculator(status, frequency);
|
||||||
|
else
|
||||||
|
frequencyCalculator = null;
|
||||||
timer = executor.scheduleAtFixedRate(new Runnable() {
|
timer = executor.scheduleAtFixedRate(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -107,6 +112,8 @@ public class RealTimeClock implements ModelStateObserverTyped {
|
|||||||
output.setValue(1 - output.getValue());
|
output.setValue(1 - output.getValue());
|
||||||
model.doStep();
|
model.doStep();
|
||||||
});
|
});
|
||||||
|
if (frequencyCalculator != null)
|
||||||
|
frequencyCalculator.calc();
|
||||||
} catch (NodeException | RuntimeException e) {
|
} catch (NodeException | RuntimeException e) {
|
||||||
stopper.showErrorAndStopModel(Lang.get("msg_clockError"), e);
|
stopper.showErrorAndStopModel(Lang.get("msg_clockError"), e);
|
||||||
timer.cancel(false);
|
timer.cancel(false);
|
||||||
@ -132,14 +139,14 @@ public class RealTimeClock implements ModelStateObserverTyped {
|
|||||||
ThreadRunner() {
|
ThreadRunner() {
|
||||||
thread = new Thread(() -> {
|
thread = new Thread(() -> {
|
||||||
LOGGER.debug("thread start");
|
LOGGER.debug("thread start");
|
||||||
FrequencyCalculator frequency = new FrequencyCalculator(status);
|
FrequencyCalculator frequencyCalculator = new FrequencyCalculator(status, frequency);
|
||||||
try {
|
try {
|
||||||
while (!Thread.interrupted()) {
|
while (!Thread.interrupted()) {
|
||||||
model.accessNEx(() -> {
|
model.accessNEx(() -> {
|
||||||
output.setValue(1 - output.getValue());
|
output.setValue(1 - output.getValue());
|
||||||
model.doStep();
|
model.doStep();
|
||||||
});
|
});
|
||||||
frequency.calc();
|
frequencyCalculator.calc();
|
||||||
}
|
}
|
||||||
} catch (NodeException | RuntimeException e) {
|
} catch (NodeException | RuntimeException e) {
|
||||||
stopper.showErrorAndStopModel(Lang.get("msg_clockError"), e);
|
stopper.showErrorAndStopModel(Lang.get("msg_clockError"), e);
|
||||||
@ -156,17 +163,18 @@ public class RealTimeClock implements ModelStateObserverTyped {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final class FrequencyCalculator {
|
private static final class FrequencyCalculator {
|
||||||
private static final long MIN_COUNTER = 50000;
|
|
||||||
private final StatusInterface status;
|
private final StatusInterface status;
|
||||||
|
private long minCounter;
|
||||||
private long checkCounter;
|
private long checkCounter;
|
||||||
private int counter;
|
private int counter;
|
||||||
private long time;
|
private long time;
|
||||||
|
|
||||||
private FrequencyCalculator(StatusInterface status) {
|
private FrequencyCalculator(StatusInterface status, int frequency) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
time = System.currentTimeMillis();
|
time = System.currentTimeMillis();
|
||||||
counter = 0;
|
counter = 0;
|
||||||
checkCounter = MIN_COUNTER;
|
minCounter = Math.min(frequency, 50000);
|
||||||
|
checkCounter = minCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calc() {
|
private void calc() {
|
||||||
@ -178,9 +186,9 @@ public class RealTimeClock implements ModelStateObserverTyped {
|
|||||||
status.setStatus(l + " kHz");
|
status.setStatus(l + " kHz");
|
||||||
time = t;
|
time = t;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
checkCounter = MIN_COUNTER;
|
checkCounter = minCounter;
|
||||||
} else {
|
} else {
|
||||||
checkCounter += MIN_COUNTER;
|
checkCounter += minCounter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user