cancel
Showing results for 
Search instead for 
Did you mean: 

ADC_Regular_ConversionMode with Range 2. First rank is channel1, second rank is channel2. How to read odd and even from buffer

MBomb.2
Associate

I am using ADC_Regular_ConversionMode with Range 2. The first rank is channel1, the second rank is channel2. I would like now to adapt code, because before I have only 1 range and only 1 channel.

I am calculating average "average += buffer[i];" in the buffer and here I need to get now data from channel1 and channel2. Now I want to divide this buffer to 2. odd numbers for *AverageADC_pedal and even for *AverageADC_lr.

Any help how can I do this because I am more new to stm32

My current code

static returnCode_t remoteInputs_getADCbufferAverage(uint16_t* buffer, uint32_t size, uint16_t *AverageADC_pedal, uint16_t *AverageADC_lr)

{

if( (buffer != first_half) && (buffer != second_half) )

{

return RC_ERR_ARG;

}

static uint16_t oldAverage = 0;

uint32_t average = 0;

for (uint32_t i = 0; i < size; i++)

{

average += buffer[i];

}

uint16_t newAverage = average/size;//simple_filter(oldAverage, (average/size));

*AverageADC_pedal = newAverage;

latestAverageADC = newAverage;

if( latestAverageADC != oldAverage)

{

oldAverage = latestAverageADC;

return RC_SUCCESS;

}

// TODO for test only return RC_ERR_UNKNOWN;

return RC_SUCCESS;

}

1 REPLY 1
MBomb.2
Associate

Any ideas maybe?