AnsweredAssumed Answered

stm32f3 discovery how to fix loop periode !!

Question asked by najeh.marzouk on Oct 26, 2016
Latest reply on Oct 26, 2016 by Clive One
Hi all, i use stm32f3 discovery and i develop a project with IAR but i have faced a problem in fixing my loop periode

to be more clear  :

i use the accelerometer and the gyroscope of th stm32f3 discovery , however after filtring the acc and gyro data i have to know how much time my loop take longer , sorry for my beginner english  ;)  i need some help please thank you ..!

i think this post discribe clearly what i want to do 

"""""""""""""""""""

The gyro tracking will not be accurate if you can not run a well timed loop. The code includes the mymillis() function for the timing.

At the start of each loop, we get the current time;

                                               
1             startInt = mymillis();            

then at the end of the loop, we make sure that at least 20ms has passed before continuing;

                                               
1             2             3             4             5             //Each loop should be at least 20ms.             while(mymillis() - startInt < 20)             {                     usleep(100);             }            

If your loop takes longer than 20ms to run, 45ms for example. Jut update the above value to make sure that every loop cycle runs at the same speed and set this value in DT for the gyro tracking.

 

Outcomes