Unusually slow loop for

For a project I used a for loop to study a group of data converted by the ADC and stored within memory by the DMA (20 data to have a transfer completed by DMA and they are stored in a structure defined in the SRAM). So within my loop I want to convert the data stored in SRAM. With a code along those lines

void loop(){
while(!DMAtransferCompleted){}
int i;
double ListStep[20]={NULL};
for(i=0;i<20;i++){
if(buffer1){
ListStep[i]=3.01*(double)structure->buffer1[i]/65535;
}else{
ListStep[i]=3.01*(double)structure->buffer2[i]/65535;
}
}
}

With DMAtransferCompleted being a volatile int set to 1 when an interrupt for DMA transfer complete is triggered and buffer1 and buffer2 indicate where the DMA protocol wrote the data (double buffer mode).
My question is, when I put some micros() functions to check how long it takes for the loop to complete itself I get around a 1000 microseconds what is excessive for the amount of data treated even if I am dividing and multiplying data??

Before we go on, you do realize that floating point math is slow on an 8 bit processor, right? What processor do you actually have?

Edit - Oh, it can't be an AVR because no DMA...

But, do you see the importance of telling us such facts?

It is an STM32H747 and running it on CoreM4 (200MHz) I tried the same code on Core M7 (400MHz ) and micros sent me values around 20 microseconds.

Edit : I do get the point of telling my settings I just honestly thought I made a really stupid slowing mistake independent from my settings...

Doesn't this line force the program to sit and twiddle thumbs while data accumulates?

Isn't 'buffer1' an array identifier? What are you trying to do here?

That is the code you should post. The entire sketch.

I don't have my whole code on me and currently typing on my phone, so I used shortcut to write the code here let me clarify:
-buffer1 is a volatile int to which I add 1 and take the modulo whenever a transfer is completed by the DMA (20 ADC conversions) it helps my code to know which buffer it can read in memory without leading to a case of writing and reading at the same time and place (double buffer mode of DMA).
Also this setup works pretty well on other codes so I don't think it is linked

That does not portend well for a good answer to your problem. There are too many things you might have left out or mistyped.

You say 'buffer1' is an int, then how can you say 'buffer1[i]'? It makes no sense.

Yeah, I guess it is absolutely impossible to reason with so little code available.
Buffer1[I] is a part of the structure "structure" so it is defined differently from buffer1 which is volatile int. I guess I ll come back to get more precise answers when I can reach a computer and upload the whole code.
Sorry about that.

this line makes absolutely senseless using the DMA...

How so?

See post #4

Apart from this there is nothing that would make your loop slow down to 1ms, on 200Mhz cpu

...assuming that the DMA is set up properly, which may not be the case.

Note that the CM4 cpu in that chip only has single precision floating point hardware, so your double precision math will all be done in software...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.