Skip to content

MXC_ADC_SetConversionSpeed parameter confusing #1383

@perkinsmg

Description

@perkinsmg

For MAX32655, we have the MXC_ADC_SetConversionSpeed function:

/**
 * @brief   Sets the ADC conversion speed
 *
 * @param   hz Desired clock freuquency for ADC conversion.
 *
 * @return  Actual conversion speed, or \ref MXC_Error_Codes for Error.
 */
int MXC_ADC_SetConversionSpeed(uint32_t hz);

But the implementation does this:

int MXC_ADC_SetConversionSpeed(uint32_t hz)
{
    //check for overflow
    MXC_ASSERT(hz < ((uint32_t)((1U << 31) - 1) / 1024));
    uint32_t adc_clock_freq = 1024 * hz;

    if (adc_clock_freq > MXC_ADC_MAX_CLOCK) {
        return E_BAD_PARAM;
    }

    uint8_t divider = PeripheralClock / adc_clock_freq;

    if (divider > 0xf || divider < 2) {
        return E_BAD_PARAM;
    }

So the parameter, far from being in "hz", is actually hz/1024. (Note that 1024 is not even the right divider to get the units in kHz).

As a result, the call in MXC_ADC_Init is:

MXC_ADC_SetConversionSpeed(MXC_CONVERSION_SPEED_6MHZ);

where

#define MXC_CONVERSION_SPEED_6MHZ 5847

This is crazy for a parameter called "hz". I don't know why it does this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions