From 5f24e86c3e7e6a83b0f7f3631e1c8fbb42de1288 Mon Sep 17 00:00:00 2001 From: BigEd Date: Sat, 2 Oct 2010 11:51:33 +0000 Subject: [PATCH] [dev]add speedometer --- macros.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/macros.js b/macros.js index d50a916..cdc5b7e 100644 --- a/macros.js +++ b/macros.js @@ -341,13 +341,35 @@ function chipStatus(){ ' Y:' + hexByte(readY()) + ' SP:' + hexByte(readSP()) + ' ' + readPstring(); - setStatus(machine1 + "
" + machine2); + setStatus(machine1 + "
" + machine2 + "
Hz: " + estimatedHz().toFixed(1)); if (loglevel>0) { updateLogbox(signalSet(loglevel)); } selectCell(ab); } +var prevHzTimeStamp=0; +var prevHzCycleCount=0; +var prevHzEstimate1=1; +var prevHzEstimate2=1; +var HzSamplingRate=10; +function estimatedHz(){ + if(cycle%HzSamplingRate!=3) + return prevHzEstimate1; + var HzTimeStamp = now(); + var HzEstimate = (cycle-prevHzCycleCount+.01)/(HzTimeStamp-prevHzTimeStamp+.01); + HzEstimate=HzEstimate*1000/2; // convert from phases per millisecond to Hz + if(HzEstimate<5) + HzSamplingRate=5; // quicker + if(HzEstimate>10) + HzSamplingRate=10; // smoother + prevHzEstimate2=prevHzEstimate1; + prevHzEstimate1=(HzEstimate+prevHzEstimate1+prevHzEstimate2)/3; // wrong way to average speeds + prevHzTimeStamp=HzTimeStamp; + prevHzCycleCount=cycle; + return prevHzEstimate1 +} + function initLogbox(names){ var logbox=document.getElementById('logstream'); logStream = [];