Cleanflight Looptime

Cleanflight gives you fine control over most every parameter.  A lot of rope to hang yourself.

One parameter that is often adjusted is looptime.  looptime is how much time a computational loop should take before starting the next one.  In general, embedded processors perform computation, wait on a high resolution timer until it is time to compute again, and repeat.  Each computation is done at a fixed rate, yielding a very clean and predictable output.

There is “headroom” at the end of the computation phase where the CPU is simply waiting.  This time is simply wasted, but for good reason.  The looptime parameter tells how long each loop should take in microseconds.  The default value is 3500 which comes out to about 285 loops per second (286Hz).

There is a lot of discussion of what to set the looptime too.  2500 (or 400Hz) seems to be a common value, which makes sense because that is the refresh rate of the ESCs.  However, unless they are in sync with the ESC, there would be an interesting phasing hickup that is beyond the discussion of this post.

There is also discussion to lower it as low as possible.  With my cc3d, the ungoverned looptime of the flight controller in rate mode was about 900us.  According to this article, if you are running in rate mode, the accelerometer hardware can be disabled with “set acc_hardware=1”.  When I do that, the looptime is extremely low, 250us or so.

Disabling the accelerometer hardware, I’ve set my loop time to 500us which is 2000Hz.  That is just crazy fast.  I honestly don’t know that I will be able to feel a difference, but no harm no foul.  It runs stable in this mode, so I need to do some A B comparison tests running 500us vs 2500us.  It’d be sweet if I could switch it on the fly with an aux channel.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s