Mercurial > hg > beaglert
diff core/I2c_Codec.cpp @ 149:134bff10e561 ClockSync
Added simple one-variable one-measurement Kalman filter, Pid controller(which output is not used). Virtual clock is now much more precise and reactive for period. Still it is lagging behind a bit on the overall offset.
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 21 Sep 2015 03:12:21 +0100 |
parents | e9a2f31dff7b |
children | e9c9404e3d1f |
line wrap: on
line diff
--- a/core/I2c_Codec.cpp Mon Sep 21 03:11:32 2015 +0100 +++ b/core/I2c_Codec.cpp Mon Sep 21 03:12:21 2015 +0100 @@ -47,8 +47,6 @@ // The master clock PLLCLK_IN is 12MHz // K can be varied in intervals of resolution of 0.0001 up to 63.9999 // using P=8 and R=1 gives a resolution of 0.0732421875Hz ( 0.000166% at 44.1kHz) - // for whatever reason, P=8 does not work (i.e.: setting the sampling rate works fine, - // but when changing K by a small-ish value (0.0040), the clock does not seem to change). // to obtain Fs=44100 we need to have K=60.2112 if(setPllP(7)) @@ -220,7 +218,9 @@ // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) float k = ((double)(newSamplingRate * pllP * 2048.0f/(float)pllR)) / PLLCLK_IN ; int ret = setPllK(k); -// printf("P: %d, R: %d, J: %d, D: %d\n", pllP, pllR, pllJ, pllD); + float actualSamplingRate = PLLCLK_IN * (pllJ + pllD/10000.0) * pllR / (2048.0 * pllP); + printf("P: %d, R: %d, J: %d, D: %d, samplingRate= %f\n", pllP, pllR, pllJ, pllD, actualSamplingRate ); +// printf("fs_ref=%f;\n",actualSamplingRate); return ret; }