analogdevicesinc / no-OS

Software drivers in C for systems without an operating system
http://analogdevicesinc.github.io/no-OS/
Other
967 stars 1.66k forks source link

Incorrect formula for AuxDAC in 9361.c #38

Closed GardenerWilly closed 6 years ago

GardenerWilly commented 6 years ago

UG-671 says that output of AuxDAC can be calculated by formula:

Vout(V) = 0.97 Vref + (0.000738 + 9 10^−6 (Vref 1.6 − 2)) DAC_word[9: 0] DAC_step − 0.3572 * DAC_step + 0.05

In function ad9361_auxdac_set we have:

    if (val_mV < 1888)
    {
        val = ((val_mV - 306) * 1000) / 1404; // Vref = 1V, Step = 2
    }
    else
    {
        val = ((val_mV - 1761) * 1000) / 1836; // Vref = 2.5V, Step = 2
    }

but seems that it must be like this:

    if (val_mV < 1888)
    {
        val = ((val_mV - 306) * 1000) / 1469; // Vref = 1V, Step = 2
    }
    else
    {
        val = ((val_mV - 1761) * 1000) / 1512; // Vref = 2.5V, Step = 2
    }

It's like someone replaced 9 10^−6 to 9 10^−5 during the coefficients calculation.

dbogdan commented 6 years ago

Fixed. Thanks for let us know about this.