Mercurial > hg > beaglert
changeset 145:8ff5668bbbad
Further updates and refactoring of the I2c_Codec class
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 14 Sep 2015 21:38:09 +0100 |
parents | d064234468cd |
children | 0a5a94de9dd0 3b7270949a97 f25940933503 |
files | .cproject core/I2c_Codec.cpp include/I2c_Codec.h |
diffstat | 3 files changed, 20 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/.cproject Mon Sep 14 17:31:24 2015 +0100 +++ b/.cproject Mon Sep 14 21:38:09 2015 +0100 @@ -183,7 +183,7 @@ <sourceEntries> <entry excluding="default_main.cpp|audio_routines_old.S" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="core"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include"/> - <entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="projects/scope"/> + <entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="projects/basic"/> <entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="source"/> </sourceEntries> </configuration>
--- a/core/I2c_Codec.cpp Mon Sep 14 17:31:24 2015 +0100 +++ b/core/I2c_Codec.cpp Mon Sep 14 21:38:09 2015 +0100 @@ -43,20 +43,33 @@ // see datasehet for TLV320AIC3104 from page 44 if(writeRegister(0x02, 0x00)) // Codec sample rate register: fs_ref / 1 return 1; + // The sampling frequency is given as f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) + // 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) + // to obtain Fs=44100 we need to have K=60.2112 + + if(setPllP(8)) + return 1; + if(setPllR(1)) + return 1; + if(setAudioSamplingRate(44100)) //this will automatically find and set K for the given P and R so that Fs=44100 + return 1; // if(writeRegister(0x03, 0x91)) // PLL register A: enable // return 1; - if(setPllP(1)) - return 1; // if(writeRegister(0x04, 0x1C)) // PLL register B // return 1; // if(writeRegister(0x05, 0x52)) // PLL register C // return 1; // if(writeRegister(0x06, 0x40)) // PLL register D // return 1; - if(setPllD(5264)) //7.5264 gives 44.1kHz nominal value with a 12MHz master clock - return 1; - if(setPllJ(7)) - return 1; +// if(writeRegister(0x0B, 0x01)) // Audio codec overflow flag register: PLL R = 1 +// return 1; + +// if(setPllD(5264)) //7.5264 gives 44.1kHz nominal value with a 12MHz master clock +// return 1; +// if(setPllJ(7)) +// return 1; if(dual_rate) { if(writeRegister(0x07, 0xEA)) // Codec datapath register: 44.1kHz; dual rate; standard datapath return 1; @@ -71,10 +84,6 @@ return 1; if(writeRegister(0x0A, 0x00)) // Audio serial control register C: 0 bit offset return 1; -// if(writeRegister(0x0B, 0x01)) // Audio codec overflow flag register: PLL R = 1 -// return 1; - if(setPllR(1)) - return 1; if(writeRegister(0x0C, 0x00)) // Digital filter register: disabled return 1; if(writeRegister(0x0D, 0x00)) // Headset / button press register A: disabled @@ -205,8 +214,6 @@ return 0; } int I2c_Codec::setAudioSamplingRate(float newSamplingRate){ - int pllP=getPllP(); //TODO: create get/set for pllP and pllR - int pllR=1; long int PLLCLK_IN=12000000; // f_{S(ref)} = (PLLCLK_IN × K × R)/(2048 × P) float k = ((double)(newSamplingRate * pllP * 2048.0f/(float)pllR)) / PLLCLK_IN ;
--- a/include/I2c_Codec.h Mon Sep 14 17:31:24 2015 +0100 +++ b/include/I2c_Codec.h Mon Sep 14 21:38:09 2015 +0100 @@ -25,7 +25,6 @@ short unsigned int pllD; short unsigned int pllP; short unsigned int pllR; - short unsigned int anotherField; public: int writeRegister(unsigned int reg, unsigned int value);