Mercurial > hg > beaglert
comparison core/I2c_Codec.cpp @ 97:c44fa102d02b
Added methods to I2c_Codec to interact with the PLL
| author | Giulio Moro <giuliomoro@yahoo.it> |
|---|---|
| date | Thu, 23 Jul 2015 02:37:11 +0100 |
| parents | 8a575ba3ab52 |
| children | e24c531220ee |
comparison
equal
deleted
inserted
replaced
| 96:ef9392d077a4 | 97:c44fa102d02b |
|---|---|
| 115 | 115 |
| 116 running = true; | 116 running = true; |
| 117 return 0; | 117 return 0; |
| 118 } | 118 } |
| 119 | 119 |
| 120 //set the numerator multiplier for the PLL | |
| 121 int I2c_Codec::setPllK(float k){ | |
| 122 short unsigned int j=(int)k; | |
| 123 unsigned int d=(k-j+0.5)*10000; //fractionary part, between 0 and 9999 | |
| 124 if(setPllJ(j)>0) | |
| 125 return 1; | |
| 126 if(setPllD(d)>0) | |
| 127 return 2; | |
| 128 return 0; | |
| 129 } | |
| 130 | |
| 131 | |
| 132 //set integer part of the numerator mutliplier of the PLL | |
| 133 int I2c_Codec::setPllJ(short unsigned int j){ | |
| 134 if(j>=64 || j<1){ | |
| 135 return 1; | |
| 136 } | |
| 137 if(writeRegister(0x04, j<<2)){ // PLL register B: j<<2 | |
| 138 printf("I2C error while writing PLL j: %d", j); | |
| 139 return 1; | |
| 140 } | |
| 141 return 0; | |
| 142 } | |
| 143 | |
| 144 //set fractional part(between 0 and 9999) of the numerator mutliplier of the PLL | |
| 145 int I2c_Codec::setPllD(unsigned int d){ | |
| 146 if(d<0 || d>9999) | |
| 147 return 1; | |
| 148 if(writeRegister(0x05, (d>>6)&255)){ // PLL register C: part 1 : 8 most significant bytes of a 14bit integer | |
| 149 printf("I2C error while writing PLL d part 1 : %d", d); | |
| 150 return 1; | |
| 151 } | |
| 152 if(writeRegister(0x06, (d<<2)&255)){ // PLL register D: D=5264, part 2 | |
| 153 printf("I2C error while writing PLL d part 2 : %d", d); | |
| 154 return 1; | |
| 155 } | |
| 156 return 0; | |
| 157 } | |
| 120 // Set the volume of the DAC output | 158 // Set the volume of the DAC output |
| 121 int I2c_Codec::setDACVolume(int halfDbSteps) | 159 int I2c_Codec::setDACVolume(int halfDbSteps) |
| 122 { | 160 { |
| 123 dacVolumeHalfDbs = halfDbSteps; | 161 dacVolumeHalfDbs = halfDbSteps; |
| 124 if(running) | 162 if(running) |
