processor expert ADC function return previous conversion value?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

processor expert ADC function return previous conversion value?

787 Views
stevedecoen
Contributor II

Hi,

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;
    POWERAD_SEL_PutVal(pAdcInputParamTab->Multiplexer);    
    ADC_CreateSampleGroup(ADC_DeviceData, (LDD_ADC_TSample *) SampleGroup,1U); //uses ChannelToPin[ adcCh_num]
    ADC_StartSingleMeasurement(ADC_DeviceData); // Start ADC
    tmrf_Start(&ADCTimeOut,0.0005);
    while (!tmrf_Ok(&ADCTimeOut))
    {
        ADC_Main(ADC_DeviceData);
        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

Tags (1)
0 Kudos
Reply
5 Replies

650 Views
stevedecoen
Contributor II

Thank you for your advice,

The transfert buffer work fine, yes these are my USB functions.

I do not want to use interrupts, i think this is a bug in processor expert .

Already replaced the ADC code with my own code which address the ADC registers directly, and now it works fine.

I was wondering if somebody got the same issues with processor expert and how they solved it

BR

Steve

0 Kudos
Reply

650 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Steve,

Could you please check the ADC Result register , or the in the memory view to check it,

whether the data is right.

If it really a bug, i will report it to PE team, and solve it . While just now , i don't

know you meaning where is the bug ? A function ? Or anything else ?  Or the ADC result ?

BR

Alice

0 Kudos
Reply

650 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello steve,

What about your chip part number ? And which version of IDE do you used ?

BR

Alice

0 Kudos
Reply

650 Views
stevedecoen
Contributor II

MKE04Z64VLK4 , IDE code warrior 10.6.4 ,

0 Kudos
Reply

650 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Steve,

- Sorry in fact , i don't know your code clearly , for some function is defined by you.

For example , what is "UsbTmtUINT16()" .Use the USB transfer ?

You said transfer the wrong data , i think you can check the buffer which save data to send.

- And you maybe you can use the ADC interrupt to send data , in the ADC interrupt function , save

ADC data . There are some demo about ADC :

pastedImage_1.png

BR

Alice

0 Kudos
Reply