mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 23:36:27 -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>
|
||||
<string>Frequency</string>
|
||||
<int>500000</int>
|
||||
<int>2147483647</int>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="1220" y="580"/>
|
||||
|
@ -99,6 +99,11 @@ public class RealTimeClock implements ModelStateObserverTyped {
|
||||
private final ScheduledFuture<?> timer;
|
||||
|
||||
RealTimeRunner(int delay) {
|
||||
FrequencyCalculator frequencyCalculator;
|
||||
if (frequency > 2000)
|
||||
frequencyCalculator = new FrequencyCalculator(status, frequency);
|
||||
else
|
||||
frequencyCalculator = null;
|
||||
timer = executor.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -107,6 +112,8 @@ public class RealTimeClock implements ModelStateObserverTyped {
|
||||
output.setValue(1 - output.getValue());
|
||||
model.doStep();
|
||||
});
|
||||
if (frequencyCalculator != null)
|
||||
frequencyCalculator.calc();
|
||||
} catch (NodeException | RuntimeException e) {
|
||||
stopper.showErrorAndStopModel(Lang.get("msg_clockError"), e);
|
||||
timer.cancel(false);
|
||||
@ -132,14 +139,14 @@ public class RealTimeClock implements ModelStateObserverTyped {
|
||||
ThreadRunner() {
|
||||
thread = new Thread(() -> {
|
||||
LOGGER.debug("thread start");
|
||||
FrequencyCalculator frequency = new FrequencyCalculator(status);
|
||||
FrequencyCalculator frequencyCalculator = new FrequencyCalculator(status, frequency);
|
||||
try {
|
||||
while (!Thread.interrupted()) {
|
||||
model.accessNEx(() -> {
|
||||
output.setValue(1 - output.getValue());
|
||||
model.doStep();
|
||||
});
|
||||
frequency.calc();
|
||||
frequencyCalculator.calc();
|
||||
}
|
||||
} catch (NodeException | RuntimeException 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 long MIN_COUNTER = 50000;
|
||||
private final StatusInterface status;
|
||||
private long minCounter;
|
||||
private long checkCounter;
|
||||
private int counter;
|
||||
private long time;
|
||||
|
||||
private FrequencyCalculator(StatusInterface status) {
|
||||
private FrequencyCalculator(StatusInterface status, int frequency) {
|
||||
this.status = status;
|
||||
time = System.currentTimeMillis();
|
||||
counter = 0;
|
||||
checkCounter = MIN_COUNTER;
|
||||
minCounter = Math.min(frequency, 50000);
|
||||
checkCounter = minCounter;
|
||||
}
|
||||
|
||||
private void calc() {
|
||||
@ -178,9 +186,9 @@ public class RealTimeClock implements ModelStateObserverTyped {
|
||||
status.setStatus(l + " kHz");
|
||||
time = t;
|
||||
counter = 0;
|
||||
checkCounter = MIN_COUNTER;
|
||||
checkCounter = minCounter;
|
||||
} else {
|
||||
checkCounter += MIN_COUNTER;
|
||||
checkCounter += minCounter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user