comparison core/I2c_Codec.cpp @ 147:e9a2f31dff7b ClockSync

Something weird happened when pllP=8, so I set pllP=7, which reduces (a bit) the clock adjustment precision
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 15 Sep 2015 02:01:15 +0100
parents 8ff5668bbbad
children 134bff10e561
comparison
equal deleted inserted replaced
146:0a5a94de9dd0 147:e9a2f31dff7b
45 return 1; 45 return 1;
46 // The sampling frequency is given as f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) 46 // The sampling frequency is given as f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P)
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 // for whatever reason, P=8 does not work (i.e.: setting the sampling rate works fine,
51 // but when changing K by a small-ish value (0.0040), the clock does not seem to change).
50 // to obtain Fs=44100 we need to have K=60.2112 52 // to obtain Fs=44100 we need to have K=60.2112
51 53
52 if(setPllP(8)) 54 if(setPllP(7))
53 return 1; 55 return 1;
54 if(setPllR(1)) 56 if(setPllR(1))
55 return 1; 57 return 1;
56 if(setAudioSamplingRate(44100)) //this will automatically find and set K for the given P and R so that Fs=44100 58 if(setAudioSamplingRate(44100)) //this will automatically find and set K for the given P and R so that Fs=44100
57 return 1; 59 return 1;
215 } 217 }
216 int I2c_Codec::setAudioSamplingRate(float newSamplingRate){ 218 int I2c_Codec::setAudioSamplingRate(float newSamplingRate){
217 long int PLLCLK_IN=12000000; 219 long int PLLCLK_IN=12000000;
218 // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) 220 // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P)
219 float k = ((double)(newSamplingRate * pllP * 2048.0f/(float)pllR)) / PLLCLK_IN ; 221 float k = ((double)(newSamplingRate * pllP * 2048.0f/(float)pllR)) / PLLCLK_IN ;
220 return (setPllK(k)); 222 int ret = setPllK(k);
223 // printf("P: %d, R: %d, J: %d, D: %d\n", pllP, pllR, pllJ, pllD);
224 return ret;
221 } 225 }
222 226
223 short unsigned int I2c_Codec::getPllJ(){ 227 short unsigned int I2c_Codec::getPllJ(){
224 return pllJ; 228 return pllJ;
225 } 229 }