cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 PID Functions

sarhangpour
Associate II
Posted on June 25, 2014 at 09:49

Hi,

I had a look at DoFullPID and DoPID functions in PID_C_stm32.c file and undrstood that variables like Error and Output are defined as uint16_t.

I'm wondering how these variables deal with negative values? What if in:

Error = Ref - In;

Ref < In? What would be the value of Error? (see, it's unsigned, right?).

Thanks in advance.

3 REPLIES 3
sarhangpour
Associate II
Posted on June 29, 2014 at 06:55

I wrote my own PID, but any idea about my question?

Posted on June 29, 2014 at 12:43

Wouldn't it just wrap within the 16-bit number space like most other add/sub math?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sarhangpour
Associate II
Posted on June 30, 2014 at 06:16

That's my guess too. But, what about the integrator?

Ex.: Error = -55 => 65535-54 = 65481 (two's complement of -55).

Instead of a 55 decrease, there would be a 65481 increase in integrator, if I'm right.

After all, it wasn't a big deal, I wrote my own PID and it seems to work fine.

Thank you clive1.