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.

Fast calculaton of average from ADC samples



Hello,

I use a F28335 delfion controller. The DMA is configured to get 50 samples from 14 ADC channels. After that an interrupt is triggered and I have
to calculate the average value for every channel. 

I implemented the function in C but it's very slow, and as I know, it would be much fast implemented in assembler by the use of special DSP commands.
I already checked the FPU reference guide but didn't find a instruction which can handle the ADC values, which are integers, without converting them. 

pseudo code:

result = 0;
for(int i = 0; i < 50; i++)
{
   result += adcValue[i] / 50;
}

  • Hi Holger,

    It is the divide that is making your loop slow. Try summing in the loop and then divide the result only once after the loop finishes. Make sure that the sum will not overflow though.

    Regards, Mitja

  • Hi, 

    your right, but this won't be much faster. I want to do the following in ASM but I'm to stupid:

    CLEAR ACC                       // clear ACC
    ASM REPEAT 50               // repeat the following command 50 times
    ADD ACC,*VARPTR++    //  add content of var pointer to acc and increment pointer by 1
    I32TOF32 RETVAL,ACC // convert content of ACC to float
    MULT RETVAL,1/50        // multiypl result with 1/50
    RETURN? RETVAL        // return result

    Where can I get some examples?

    Regards,
    Holger 

  • If someone is interested in:

    Uint16 *mean_arrAdc;
    float mean_fRetval;

    void meanfast50()
    {
    asm(" movl xar2,@_mean_arrAdc"); // initialize XAR2 register with array start addr
    asm(" ZAPA"); // clear registers
    asm(" RPT #49 \n || ADD ACC,*XAR2++"); // summarize all values (50)
    asm(" MOV32 R1H, ACC"); // move result to FPU register
    asm(" nop");
    asm(" nop");
    asm(" nop");
    asm(" nop");
    asm(" I32TOF32 R2H, R1H"); // convert result to floating point
    asm(" nop");
    asm(" MPYF32 R3H, R2H, 0.02" ); // multiply with 1/50
    asm(" nop");
    asm(" MOV32 @_mean_fRetval, R3H");
    }

    Does anyone know how I can use a #define within asm ("") block?

    Following code doesn't work:

    #define K 1/50
    asm(" MPYF32 R3H, R2H, K" );