diff --git a/ch32v/ch32v203-goertzel/adcgoertzel.c b/ch32v/ch32v203-goertzel/adcgoertzel.c
index 9687fb6..db5d2cd 100644
--- a/ch32v/ch32v203-goertzel/adcgoertzel.c
+++ b/ch32v/ch32v203-goertzel/adcgoertzel.c
@@ -779,8 +779,11 @@ int HandleHidUserGetReportSetup( struct _USBState * ctx, tusb_control_request_t
((uint32_t*)scratchpad)[1] = (g_lastper<<16) | g_lastlen;
((uint32_t*)scratchpad)[2] = (0<<16) | (((g_pwm_period+1)*g_goertzel_buffer)); //LSW = 144MHz / X
+ ((uint32_t*)scratchpad)[3] = SysTick->CNT;
+ ((uint32_t*)scratchpad)[4] = *((uint32_t*)adc_buffer);
+
int i;
- for( i = 3; i < samps_to_send + 3; i++ )
+ for( i = 5; i < samps_to_send + 5; i++ )
{
last_baselog = (last_baselog+1)&(LOG_GOERTZEL_LIST-1);
((uint32_t*)(scratchpad))[i] = ((int32_t*)qibaselogs)[last_baselog];
diff --git a/ch32v/lib/webhidcontrol.js b/ch32v/lib/webhidcontrol.js
index 777a602..802773b 100644
--- a/ch32v/lib/webhidcontrol.js
+++ b/ch32v/lib/webhidcontrol.js
@@ -297,6 +297,45 @@ FMiirphase = 0.0; /* for FM */
FMlastphase = 0.0; /* for FM */
FMphaseout = 0.0; /* for FM */
+lastadc = 0|0;
+
+
+remote_clock_mhz = 0;
+remote_clock_last_timestamp = 0|0;
+remote_clock_last_timems = 0.0;
+remote_clock_initted = false;
+remote_clock_refinement = 1.0;
+remote_clock_total_s = 0;
+remote_clock_total_ticks = 0.0;
+
+function ComputeRemoteClock( remote_time_ticks, now_ms )
+{
+ if( !remote_clock_initted )
+ {
+ remote_clock_last_timestamp = remote_time_ticks;
+ remote_clock_last_timems = now_ms;
+ remote_clock_refinement = 1.0;
+ remote_clock_initted = true;
+ remote_clock_total_ms = 0;
+ remote_clock_total_ticks = 0|0;
+ return;
+ }
+
+ var delta_s = (now_ms - remote_clock_last_timems)/1000.0;
+ var delta_clock = ((remote_time_ticks - remote_clock_last_timestamp)|0)*2; // convert 144MHz to 288MHz
+ var this_mhz = delta_clock / delta_s;
+
+ remote_clock_total_s += delta_s;
+ remote_clock_total_ticks += delta_clock * 1.0;
+
+ remote_clock_mhz = remote_clock_total_ticks / remote_clock_total_s;
+
+ remote_clock_total_s *= 0.99999;
+ remote_clock_total_ticks *= 0.99999;
+
+ remote_clock_last_timestamp = remote_time_ticks;
+ remote_clock_last_timems = now_ms;
+}
async function sendLoop()
{
@@ -331,7 +370,13 @@ async function sendLoop()
(kBsecAvg).toFixed(2) + " kB/s
" +
(xActionSecAvg).toFixed(2) + "x/s
";
document.getElementById( "GeneralData" ).innerHTML =
- "Count: " + goodCount + " / " + badCount + "
Inten: " + ((Math.log( lastIntensity * lastIntensity )/Math.log(10)) * 10-120).toFixed(2) + "db (" + lastIntensity + ")";
+ "
| Count: " + goodCount + " / " + badCount + " | " + + "Inten: " + ((Math.log( lastIntensity * lastIntensity )/Math.log(10)) * 10-120).toFixed(2) + "db (" + lastIntensity + ") | " + + "ADCs: " + (lastadc>>16).toFixed(0) + " / " + (lastadc&0xffff).toFixed(0) + " | " + + "Remote clock: MHz ` + " | " + + "" + ((remote_clock_mhz-288000000)/288).toFixed(3) + " PPM | " + + "