User Tools

Site Tools


k2m051_ino_changes

k2m051.ino changes

I am using a function derived from a function in HiFiDUINO's k2m051.ino in a proprietary contract project. The CC-by 3.0 license wants me to share modifications, and I am happy to oblige!

Here's the (trivially) modified version of unsigned long sampleRate() that I am using as a class member function:

unsigned long ES9018K2M::getSampleRate()
{
    if (!isSignalLock())
    {
        return 0;
    }
//    uint8_t dpll0 = 0;  // LSB of DPLL register
//    uint8_t dpll1 = 0;
//    uint8_t dpll2 = 0;
//    uint8_t dpll3 = 0;  // MSB of DPLL register
 
    dpll0 = 0;
    dpll1 = 0;
    dpll2 = 0;
    dpll3 = 0;
 
    m_dpllVal = 0;
    // Read the 4 registers of DPLL one byte at a time starting with LSB (reg 66).
    dpll0 = readRegister(66);
    dpll1 = readRegister(67);
    dpll2 = readRegister(68);
    dpll3 = readRegister(69);
 
    m_dpllVal |= dpll3;
    m_dpllVal <<= 8;
    m_dpllVal |= dpll2;
    m_dpllVal <<= 8;
    m_dpllVal |= dpll1;
    m_dpllVal <<= 8;
    m_dpllVal |= dpll0;
    m_dpllVal >>= 1;     // Get rid of LSB to allow for integer operation below to avoid overflow.
 
    //using 80MHZ clock
    m_dpllVal *= 16;     // Calculate SR for 80MHz part
    m_dpllVal /= 859;    // Calculate SR for 80MHz part
    m_dpllVal += 1;
    m_dpllVal *= 2;
 
    return m_dpllVal;
}

and my isSignalLock() function:

uint8_t ES9018K2M::isSignalLock()
{
    uint8_t regVal = readRegister(REG_64);
    return 0x01 & regVal;   // mask off all but last bit
}
k2m051_ino_changes.txt · Last modified: 2015/06/23 14:29 by mithat