Hi,
The gains are just numerical values like any other variable. Assigning values to the gain variables using hex doesn't, in itself, allow "floating point" but it makes it easier to visualise what the "real" gain is. Or perhaps not... ;-)
Lets look at the proportional term:
Lets say you set pid_Kp to $0280 (or 640 in decimal if you like). Now you calculate pid_Error to, lets say, 125 and send it to the filter. The filter will then calculate the proportional term to 125 */ 640 which is the same as 125*640/256=312. Or, put another way 640/256=2.5 and 125*2.5=312.
If you set pid_kP to 102 (or $66) you'll get a gain 102/256=0.398 and an output, in the example above of 125*102/256=49 which is basically the same as 125*0.398.
If you know you want a gain of 3.7 then simply multiply that value by 256 to get the value. 3.7*256=947. pid_Kp=947 or pid_Kp=$03B3. Where, in this case $03 means 3 and $B3 means $B3/$FF or 179/256=0.7 ie a gain of 3.7
With the same error as above: 125*947/256=462 which is the same as 125*3.7=462.
So, using HEX doesn't make it floating point per se, it's just another way of assigning values to the variables. Say you wanted a gain of 4, then pid_kP=$0400 is easier to understand then pid_Kp=1024 but they both result in the exact same thing.
/Henrik.
Bookmarks