AnsweredAssumed Answered

STM32F4 Discovery Multi-dimensional Array Problem

Question asked by D3K on Feb 7, 2018
Latest reply on Feb 7, 2018 by AvaTar

I have a control algorithm which operates within a Timer Interrupt of 200 us. Basically my code generates an output and compares it to a look up table. When I have a single array defined:

 

const float Adm_Re_array[720] = {...values...}

 

And search for a match in the LUT which has the minimum distance from the array using this code:

 

for (i=1;i<=8;i=i++)
{
k = act_element+i-4;
if (k < 0) k = k + 720;
if (k >(719)) k = k - 720;

dist_Re = Adm_Re-Adm_Re_array[k];

 

dist_T = (dist_Re*dist_Re);

 

if ((dist_T <= dist_T_min)||(dist_T_min == -1))
{
dist_T_min = dist_T;
act_element = k;

}
}

 

My control algorithm works well and I have used only 124 us of the 200 us.

 

When I change from a single dimension to a multi-dimensional array of form:

 

const float Adm_Re_array[7][720] = {...values...}

 

And search for a match in the LUT which has the minimum distance from the array using this code:

 

for (i=1;i<=8;i=i++)
{
k = act_element+i-4;
if (k < 0) k = k + 720; 
if (k >(719)) k = k - 720 

 

dist_Re = Adm_Re-Adm_Re_array[4][k];

 

dist_T = (dist_Re*dist_Re);

 

if ((dist_T <= dist_T_min)||(dist_T_min == -1))
{
dist_T_min = dist_T;
act_element = k;

 

}
}

 

My control code goes unstable while the loop time does not change significantly from the 124 us as I am only looking at one row of the multidimensional array in my search. Are there any known issues with the STM32 using multidimensional arrays similar to what I am observing. 

 

Regards,

K

Outcomes