This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280025C: ADC calibration function ADC_setOffsetTrim error in Driverlib Functions

Part Number: TMS320F280025C
Other Parts Discussed in Thread: C2000WARE

Hi Team,

There's an issue from the customer need your help:

The content of function ADC_setOffsetTrim in C2000Ware_5_00_00_00\driverlib\f28002x\driverlib\adc.c is as follows:

void
ADC_setOffsetTrim(uint32_t base)
{
    uint16_t *offset;
    uint32_t moduleShiftVal;
    uint16_t offsetShiftVal;
    uint16_t analogRefRegVal;
    ADC_ReferenceMode refMode;
    ADC_ReferenceVoltage refVoltage;

    //
    // Check the arguments.
    //
    ASSERT(ADC_isBaseValid(base));

    //
    // Assign a shift amount corresponding to which ADC module is being
    // configured.
    //
    switch(base)
    {
        case ADCA_BASE:
            moduleShiftVal = 0U;
            break;
        case ADCC_BASE:
            moduleShiftVal = 1U;
            break;
        default:
            //
            // Invalid base address!!
            //
            moduleShiftVal = 0U;
            break;
    }

    //
    // Read the Analog Reference Control Register value to determine the
    // ADC reference mode and reference voltage value.
    //
    analogRefRegVal = HWREGH(ANALOGSUBSYS_BASE + ASYSCTL_O_ANAREFCTL);

    //
    // Calculate refMode and refVoltage based on input ADC base
    //
    refMode = (ADC_ReferenceMode)((analogRefRegVal >> moduleShiftVal) & 1U);
    refVoltage = (ADC_ReferenceVoltage)((analogRefRegVal >>
                 (ADC_VOLTAGE_REF_REG_OFFSET + moduleShiftVal)) & 1U);

    //
    // Offset trim for internal VREF 3.3V is unique and stored in upper byte.
    //
    if((refMode == ADC_REFERENCE_INTERNAL) &&
       (refVoltage == ADC_REFERENCE_3_3V))
    {
        offsetShiftVal = 8U;
    }
    else
    {
        offsetShiftVal = 0U;
    }

    //
    // Set up pointer to offset trim in OTP.
    //
    offset = (uint16_t *)((uint32_t)ADC_OFFSET_TRIM_OTP + moduleShiftVal);

    //
    // Get offset trim from OTP and write it to the register.
    //
    EALLOW;
    HWREGH(base + ADC_O_OFFTRIM) = (*offset >> offsetShiftVal) & 0xFFU;
    EDIS;
}

When this function is used to calibrate ADCA, it can be calibrated normally.

But when used to calibrate ADCC, the value of the parameter moduleShiftVal is 1. Note lines 45-47. At this time, the values ​​assigned to refMode and refVoltage are bit1 and bit9 of the analogRefRegVal (register ANAREFCTL ) value respectively.

The bit field diagram of register ANAREFCTL is as follows:

In fact, the values ​​that should be assigned to refMode and refVoltage should be bit2 and bit10 of the register ANAREFCTL value, not bit1 and bit9.

Is this a Driverlib Functions writing error?

Thanks & Regards,

Ben