AnsweredAssumed Answered

processor expert ADC function return previous conversion value?

Question asked by stevedecoen on Dec 6, 2016
Latest reply on Dec 15, 2016 by Alice_Yang



I have some ADC read function like this :


if(!UsbTmtUINT16(hw_uLeesAD(AD_Speaker)))            return;
if(!UsbTmtUINT16(hw_uLeesAD(AD_Aux)))                return;


This example sends the speakers AD value and the Aux Ad value to a PC (and 22 other ADC's)

The code in hw_uLeesAD looks like this :

uint16_t hw_uLeesAD(TAdcInput AdcInput)
    Ttmrf ADCTimeOut;
    LDD_ADC_TSample SampleGroup[1U];
    uint16_t AdcValue;
    TAdcInputParamTab const *pAdcInputParamTab;
    pAdcInputParamTab = &AdcInputParamTab[AdcInput];
    SampleGroup[0].ChannelIdx = pAdcInputParamTab->AdInput;
    ADC_CreateSampleGroup(ADC_DeviceData, (LDD_ADC_TSample *) SampleGroup,1U); //uses ChannelToPin[ adcCh_num]
    ADC_StartSingleMeasurement(ADC_DeviceData); // Start ADC
    while (!tmrf_Ok(&ADCTimeOut))
        if (bADCConversionDone)
            bADCConversionDone = 0;
            if (ERR_OK == ADC_GetMeasuredValues(ADC_DeviceData,(LDD_TData *) &AdcValue))
            { // Read measured values
                return AdcValue; //Capture Output
    return 0xFFFF;

This code selects the correct ADC input (selected by AdcInput), and returns the ADC value from the ADC.

The problem i have is that the ADC value which is send is always the previous ADC value, so in above example i get at the PC side AD_Speaker when i expect AD_Aux. When i replace all hw_uLeesAD(AD_XXX) by constants , then it works fine.

When i run the function 2 times like this , then i receive the correct ADC value:

uint16_t adcval;

adcval = hw_uLeesAD(AD_Speaker);

if(!UsbTmtUINT16(hw_uLeesAD(AD_Speaker)))            return;

adcval = hw_uLeesAD(AD_Aux);
if(!UsbTmtUINT16(hw_uLeesAD(AD_Aux)))                return;

It looks like ADC_GetMeasuredValues returns a previous ADC value, but i can't find out why.

Any input is more then welcome


Thank you