User Tools

Site Tools


k2m051_ino_changes

This is an old revision of the document!


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.
 
//#ifdef USE80MHZ
    m_dpllVal *= 16;     // Calculate SR for 80MHz part
    m_dpllVal /= 859;    // Calculate SR for 80MHz part
    m_dpllVal += 1;
    m_dpllVal *= 2;
//#endif
//#ifdef USE100MHZ
//    m_dpllVal *= 20;     // Calculate SR for 100MHz part
//    m_dpllVal /= 859;    // Calculate SR for 100MHz part
//    m_dpllVal *= 2
//#endif
 
    /*
    if (m_dpllVal < 90000) // Adjusting because in integer operation, the residual is truncated
                         // This is just cosmetic...
      m_dpllVal+=1;
      else
        if (m_dpllVal < 190000)
          m_dpllVal+=2;
        else
          if (m_dpllVal < 350000)
            m_dpllVal+=3;
          else
            m_dpllVal+=4;
    */
    /*
    if(bypassOSF)      // When OSF is bypassed, the magnitude of DPLL is reduced by a factor of 64
                      // This is no longer needed for the K2M. It reports the sample rate correctly
                      // whether it is in NOS or nonNOS
     m_dpllVal*=64;
    */
 
    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.1435069567.txt.gz · Last modified: 2015/06/23 14:26 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki