cancel
Showing results for 
Search instead for 
Did you mean: 

Control Function.

BoboyeOkeya
Associate III

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?

4 REPLIES 4
rpip.1
Associate III

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.

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?

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.

wow, Okay I dont fully understand this.

How do you do the math behind converting 2.15 to 140902>>16?

Let's say I have a random number like 3.3, how do I convert it to this format you just described (x>>y)