 # fixed point 32 bit

I am looking for a 32bit fixed point implementation of a multiplier, adder, subtractor and PI controller in arduino. I want plain code and no predefined libraries. Can anybody help

Consider posting in the Gigs and Collaborations section of the forum. You may be asked to pay for the help.

I want to achieve a 32 bit implementation of PI controller and estimate performance on arduino. Guidance required for the same

Unless you can give a good reason to use fixed point, google “arduino PID” for a floating point library and tutorials.

integer is not fixed point - what do you really mean?

Edit: I originally wrote this while boarding a flight, so I missed the factor of 10 in the multiply. Sorry for the confusion.

Fixed-point multiply...

``````int32_t a, b, c;
void setup() {
a=12.2*10;
b=167.8*10;

//fixed point multiply operation:
c=a*b/10;

Serial.begin(9600);
while(!Serial);  //native USB, ignored on other Arduinos

Serial.println(c/10.0, 1); //print result
}
void loop() {}
``````

And don’t forget there is no point of calculations to this precision if your input / output signals don’t have the same resolution.
Non linearities , lags and hystersis in the control loop are the usual issue in PID loops, rather than the maths - you really need to look into control theory , if looking into evaluating PID performance, which is critically dependant upon the systems transfer function .

MorganS:
Fixed-point multiply…

``````int32_t a, b, c;
``````

void setup() {
a=12.210;
b=167.8
10;

//fixed point multiply operation:
c=a*b;

Serial.begin(9600);
while(!Serial); //native USB, ignored on other Arduinos

Serial.println(c/10.0, 1); // Oops
}
void loop() {}

This bug demonstrates the problem with manual fixed point code:

`````` Serial.println(c/10.0, 1); //print result
``````

As a and b are multiplied by 10, the product c has to be divided by 100.

Delphi supports a type Currency with 64 bit and 4 decimal places.

I'd look for a class for proper computation. With 32 bit 2 decimal places might do.