2020-12-13 11:57 AM
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;
}
2020-12-13 10:16 PM
Any ideas maybe?