Loop() performance benchmarking

Ok, this is more a arduino.cc forum question, but since the subject of my experiments is my AC I thought I will post here my question. :)I am trying to benchmark the amount of time the loop() function requires to complete. I get the max amount of time every cycle and reset it every 500ms.This is what I do (from the NG code):..void setup() {...mainLoop = millis(); // Initialize timersmediumLoop = mainLoop;slowLoop = mainLoop;...}loop(){currentTimeMicros = micros(); //micros.currentTime = currentTimeMicros / 1000; //millis.// Main loop at 200Hz (IMU + control)if ((currentTime-mainLoop) >= 5) // about 200Hz (every 5ms){...}//very slow loop 2Hz for Flight statisticsif ((currentTime-slowLoop)>=500){slowLoop = currentTime;Serial.Prinln(maxLoopTime);maxLoopTime = 0; //reset the max every 500 ms.}...loopTime = micros() - currentTimeMicros;maxLoopTime = max(loopTime , maxLoopTime);}Now the results show a maxLoopTime of about 9000 to 11000 microseconds meaning that the loop is moving at a 90/111Hz well under the 200Hz requested in by the mainLoop variable.Does this make sense? Does it means the CPU is not able to perform the main loop at 200Hz (overloaded)?I see that G_dt is calculated in every 200Hz loop so it actually get the correct value for PID calculation, but what could be the implications of running the control loop (ADC, RADIO, Attitude etc.) at a slower rate than the one specified?Emile

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • can you tell us what you have activated in code? (magneto, gps, telemetry, etc)
This reply was deleted.

Activity