We need to determine the resolution of the error term,
. Let us
consider a system where the speed can be up to
ticks/s. This means
the error term can be up to
because the motor can be spinning
full speed backward and ask to spin full speed forward.
The next factor is how often to run the PID loop logic. The frequency
of the loop
helps to determine the resolution of the error term.
Although the actual error can be up to
ticks/s, between each
PID invocation, the difference only be up to
. For example,
if the top speed of a reversible system is 1200 ticks/s, and the PID
loop is invoked at 50Hz,
can only range from -48 to 48, which
can be represented by a 7-bit signed integer.
The number of bit required for
is, then,
| (9.3) |
When
is close to
, the magnitude of
is small. This
means you need to rely on fractions in
to fine tune the terms.
Instead of using floating point numbers, many small MCUs benefit from
the use of more efficient integer/fixed number computations.
For example, even if we know that
does not exceed 4, we can use
8 bits to represent it. The least significant 6 bits become fractional
terms. Given an integral bit pattern of
, the actual
represented value is
. The division by
is inexpensively performed by right shift operations.