How to speed up function execution?
I'm currently implementing very low current measurement electronics, such as Femto Amps.
To do this, I'm using the STM32G431CBU MCU. I'm acquiring the output voltages of a float voltage transimpetance amplifier, and I'm taking a running average.
My MCU is clocked by a 24 MHz quartz crystal, with the instruction frequency set to its maximum of 170 MHz.
But my function is still slow, between 24 µs and 50 µs.
float MoyenneGlissante(float valeurI, uint8_t MeanMoving)
{
static float buffer[50] = {0}; // capacité max : 50 échantillons
static uint8_t index = 0;
static uint8_t rempli = 0;
// Protection : on limite MeanMoving au max du buffer
if (MeanMoving > 50) MeanMoving = 50;
// Stocke la nouvelle valeur dans le buffer circulaire
buffer[index] = valeurI;
index = (index + 1) % MeanMoving;
// Marqueur pour savoir si le buffer est rempli au moins une fois
if (rempli < MeanMoving) rempli++;
// Calcul de la moyenne glissante
float somme = 0;
for (uint8_t i = 0; i < rempli; i++) {
somme = somme + buffer[i];
}
return somme / rempli;
// return valeurI;
}
How can I significantly reduce the processing time for this function?
Thank you for your help.
