changeset 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 ef9392d077a4
children 9a413516a1fc
files core/I2c_Codec.cpp
diffstat 1 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/core/I2c_Codec.cpp	Thu Jul 23 02:36:49 2015 +0100
+++ b/core/I2c_Codec.cpp	Thu Jul 23 02:37:11 2015 +0100
@@ -117,6 +117,44 @@
 	return 0;
 }
 
+//set the numerator multiplier for the PLL
+int I2c_Codec::setPllK(float k){
+	short unsigned int j=(int)k;
+	unsigned int d=(k-j+0.5)*10000; //fractionary part, between 0 and 9999
+	if(setPllJ(j)>0)
+		return 1;
+	if(setPllD(d)>0)
+		return 2;
+	return 0;
+}
+
+
+//set integer part of the numerator mutliplier of the PLL
+int I2c_Codec::setPllJ(short unsigned int j){
+	if(j>=64 || j<1){
+			return 1;
+	}
+	if(writeRegister(0x04, j<<2)){	// PLL register B: j<<2
+		printf("I2C error while writing PLL j: %d", j);
+		return 1;
+	}
+	return 0;
+}
+
+//set fractional part(between 0 and 9999) of the numerator mutliplier of the PLL
+int I2c_Codec::setPllD(unsigned int d){
+	if(d<0 || d>9999)
+		return 1;
+	if(writeRegister(0x05, (d>>6)&255)){ // PLL register C: part 1 : 8 most significant bytes of a 14bit integer
+		printf("I2C error while writing PLL d part 1 : %d", d);
+		return 1;
+	}
+	if(writeRegister(0x06, (d<<2)&255)){	// PLL register D: D=5264, part 2
+		printf("I2C error while writing PLL d part 2 : %d", d);
+		return 1;
+	}
+	return 0;
+}
 // Set the volume of the DAC output
 int I2c_Codec::setDACVolume(int halfDbSteps)
 {