Skip to main content
BoboyeOkeya
Associate III
September 8, 2021
Question

Control Function.

  • September 8, 2021
  • 1 reply
  • 1872 views

Hi All,

Can someone please enlighten me on this:

Why is the integrator term, and the control function output scaled and shifted as shown in this code below?

Why would I need to do that in an embedded system suc0693W00000Dma3JQAR.pngh as STM32?

This topic has been closed for replies.

1 reply

rpip.1
Associate II
September 9, 2021

Decimal number involved in PID control part often. Ki is so small in most cases, such as 0.00053. And float tpye is not proper for some mcu. So we need to translate it to multiply and shift. 0.00053 = 34>>16.

BoboyeOkeya
Associate III
September 9, 2021

Hi rpip.1 okay that makes sense. But, in this particular code it was not only the integral term that was scaled, the output was also scaled.

Also, can it always be a random number?

rpip.1
Associate II
September 10, 2021

PID para is determined by calculation based on control theory or by test. It's related to motor para and PWM freq. Whatever, you don't want to set para just be an integer.

Even if para is not small enough, fraction part still involved in, such as 2.15.

Scale and shift can make more accurated result.

For examle,

If you want to set Kp to 2.15, it's moded by integer type to 2. Meaning a 1 step.

if you set Kp to 140902>>16, it's 2.1499. Meaning a 1>>16 step.

And in the latter case, you must multipy para with error first, then shifting.

Also Motor library need to be compatible to small para. If calculated pid para happen to be an integer or it's acceptable with integer type in your case. you can elide these scale and shift.