AnsweredAssumed Answered

MK22 differential adc-channel in 16bit mode puts out half of the actual value

Question asked by Philipp Thornhill on Aug 1, 2018
Latest reply on Aug 2, 2018 by Philipp Thornhill

Hello,

I'm currently working on the adc of the MK22FN128VLH10 microcontroller. I used the example, given with the FRDM-K22-board, to initialize a differential channel in 16bit mode. The outputted value is only half of the actual value. I've checked the hardware. The voltage is applied correctly to the pins.

Is there any configuration I have to make to make the adc work correctly?

Here the code:

 

int main(void)
{
    adc16_config_t adc16ConfigStruct;
    adc16_channel_config_t adc16ChannelConfigStruct;

 

    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();
    vPowerSupplyEnableV5PL();
    EnableIRQ(DEMO_ADC16_IRQn);
    PRINTF("\r\nADC16 interrupt Example.\r\n");
    ADC16_GetDefaultConfig(&adc16ConfigStruct);
    adc16ConfigStruct.resolution = kADC16_Resolution16Bit;
    ADC16_Init(DEMO_ADC16_BASE, &adc16ConfigStruct);
    ADC16_EnableHardwareTrigger(DEMO_ADC16_BASE, false); /* Make sure the software trigger is used. */
    if (kStatus_Success == ADC16_DoAutoCalibration(DEMO_ADC16_BASE))
    {
        PRINTF("ADC16_DoAutoCalibration() Done.\r\n");
    }
    else
    {
        PRINTF("ADC16_DoAutoCalibration() Failed.\r\n");
    }
    PRINTF("Press any key to get user channel's ADC value ...\r\n");
    adc16ChannelConfigStruct.channelNumber = DEMO_ADC16_USER_CHANNEL;
    adc16ChannelConfigStruct.enableInterruptOnConversionCompleted = true; /* Enable the interrupt. */
    adc16ChannelConfigStruct.enableDifferentialConversion = true;
    ADC16_SetChannelMuxMode( DEMO_ADC16_BASE, kADC16_ChannelMuxB );

 

    g_Adc16InterruptCounter = 0U;

 

    while (1)
    {
        GETCHAR();
        g_Adc16ConversionDoneFlag = false;
        ADC16_SetChannelConfig(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP, &adc16ChannelConfigStruct);
        while (!g_Adc16ConversionDoneFlag)
        {
        }
        PRINTF("ADC Value: %d\r\n", g_Adc16ConversionValue);
        PRINTF("ADC Interrupt Count: %d\r\n", g_Adc16InterruptCounter);
    }
}

 

Greetings,

Philipp

 

P.S.: vPowerSupplyEnableV5PL sets a few gpios.

Outcomes