Mercurial > hg > beaglert
comparison core/I2c_Codec.cpp @ 151:e9c9404e3d1f ClockSync
Pff partially working. No PID. When setting the audio clock on the bbb to 44098 the master and slave clock keep diverging instead of converging ...
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 22 Sep 2015 04:10:07 +0100 |
parents | 134bff10e561 |
children |
comparison
equal
deleted
inserted
replaced
150:ebbfb154351a | 151:e9c9404e3d1f |
---|---|
47 // The master clock PLLCLK_IN is 12MHz | 47 // The master clock PLLCLK_IN is 12MHz |
48 // K can be varied in intervals of resolution of 0.0001 up to 63.9999 | 48 // K can be varied in intervals of resolution of 0.0001 up to 63.9999 |
49 // using P=8 and R=1 gives a resolution of 0.0732421875Hz ( 0.000166% at 44.1kHz) | 49 // using P=8 and R=1 gives a resolution of 0.0732421875Hz ( 0.000166% at 44.1kHz) |
50 // to obtain Fs=44100 we need to have K=60.2112 | 50 // to obtain Fs=44100 we need to have K=60.2112 |
51 | 51 |
52 if(setPllP(7)) | 52 if(setPllP(1)) |
53 return 1; | 53 return 1; |
54 if(setPllR(1)) | 54 if(setPllR(1)) |
55 return 1; | 55 return 1; |
56 if(setAudioSamplingRate(44100)) //this will automatically find and set K for the given P and R so that Fs=44100 | 56 if(setAudioSamplingRate(44100)) //this will automatically find and set K for the given P and R so that Fs=44100 |
57 return 1; | 57 return 1; |
216 int I2c_Codec::setAudioSamplingRate(float newSamplingRate){ | 216 int I2c_Codec::setAudioSamplingRate(float newSamplingRate){ |
217 long int PLLCLK_IN=12000000; | 217 long int PLLCLK_IN=12000000; |
218 // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) | 218 // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) |
219 float k = ((double)(newSamplingRate * pllP * 2048.0f/(float)pllR)) / PLLCLK_IN ; | 219 float k = ((double)(newSamplingRate * pllP * 2048.0f/(float)pllR)) / PLLCLK_IN ; |
220 int ret = setPllK(k); | 220 int ret = setPllK(k); |
221 float actualSamplingRate = PLLCLK_IN * (pllJ + pllD/10000.0) * pllR / (2048.0 * pllP); | 221 // printf("P: %d, R: %d, J: %d, D: %d, samplingRate= %f\n", pllP, pllR, pllJ, pllD, getAudioSamplingRate()); |
222 printf("P: %d, R: %d, J: %d, D: %d, samplingRate= %f\n", pllP, pllR, pllJ, pllD, actualSamplingRate ); | 222 // printf("fs_ref=%f;\n",getAudioSamplingRate()); |
223 // printf("fs_ref=%f;\n",actualSamplingRate); | 223 // printf("0 0 0 0 0 0\n"); |
224 return ret; | 224 return ret; |
225 } | 225 } |
226 | 226 |
227 short unsigned int I2c_Codec::getPllJ(){ | 227 short unsigned int I2c_Codec::getPllJ(){ |
228 return pllJ; | 228 return pllJ; |
241 float d=getPllD(); | 241 float d=getPllD(); |
242 float k=j+d/10000.0f; | 242 float k=j+d/10000.0f; |
243 return k; | 243 return k; |
244 } | 244 } |
245 | 245 |
246 float I2c_Codec::getAudioSamplingRate(){ | 246 double I2c_Codec::getAudioSamplingRate(){ |
247 int pllP=1; //TODO: create get/set for pllP and pllR | 247 int pllP=1; //TODO: create get/set for pllP and pllR |
248 int pllR=1; | 248 int pllR=1; |
249 long int PLLCLK_IN=12000000; | 249 long int PLLCLK_IN=12000000; |
250 // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) | 250 // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) |
251 float fs = (PLLCLK_IN/2048.0f) * getPllK()*pllR/(float)pllP; | 251 float fs = (PLLCLK_IN/2048.0f) * getPllK()*pllR/(float)pllP; |