C code - implementation of PID in microcontroller - Page 1
Forum section: electronics / general

author: nForce
author_rank: Frequent Contributor
timestamp: March 23, 2017, 08:35:29 pm
content: Hello,I have written a PID regulator in C, for some microcontroller. The call_interrupt function is a periodic function which is called periodically with switch frequency of 20000 Hz. The PID has to be written in a such a way, so that if we change the sample frequency (SAMPLE_FREQ) with the prescale value, there is no need to change the parameters of PID (Kp, Ki, Kd). How can I achieve that?Code:#define SWITCH_FREQ 20000#define SAMP_PRESCALE 1#define SAMPLE_FREQ (SWITCH_FREQ/SAMP_PRESCALE)float Kp = 1.0;float Ki = 1.0;float Kd = 1.0;float error_sum = 1.0;float temp = 0.0;float error = 0.0;void call_interrupt(void){// some codeerror = reference_value - voltage;error_sum += error;PID = (Kp * error) + (Ki * error_sum) + (Kd * (error - temp));temp = error;//some code}

author: Kleinstein
author_rank: Super Contributor
timestamp: March 23, 2017, 08:51:37 pm
content: One way to implement a PID that allows for a variable call rate, is to do the integral part by including the scaling factor KI already there. So instead oferror_sum += erroruseintegral_part += Ki * error * dtAs a side effect this also allows changing Ki on the fly without adding glitches.

author: Jeroen3
author_rank: Super Contributor
timestamp: March 24, 2017, 08:19:46 am
content: You'll need some other things as well.Such as:- Stop the I accumulator when the ouput is clamped.- Saturating calculations.(although with float chances are small)Also PID with floats 20 KHz will need some fast microcontroller. What's the core speed?I think you might be better of using fixed point math.

author: nForce
author_rank: Frequent Contributor
timestamp: March 24, 2017, 10:34:33 am
content: The core speed of microcontroller is 90 Mhz.Code:integral_part += Ki * error * dtWhat do you mean here by dt? dt is the differential of time, so it should be 1/frequency?QuoteLike so (sort of):Code:if (PID > 1.0){integral_sum = 1}if (PID < 0){integral_sum = 0}

author: brucehoult
author_rank: Super Contributor
timestamp: March 24, 2017, 11:11:18 am
content: Quote from: Jeroen3 on March 24, 2017, 08:19:46 am16 MHz AVR takes about 8 - 10 us per soft float multiply or add. So 20 KHz with six or sven operations in the loop is not *quite* possible -- 10 KHz could be doable.You'd hope a 90 MHz would be OK though ... even with software FP.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: March 24, 2017, 11:15:00 am
content: QuoteYes

author: Jeroen3
author_rank: Super Contributor
timestamp: March 24, 2017, 11:47:50 am
content: Quote from: brucehoult on March 24, 2017, 11:11:18 amIf the PID is the only thing the chips doing, yes. But the chip is not. It will need to perform data aqcuisition and filtering.And the % of cpu that takes is depending on the samplerate.10 Khz is a more realistic maximum. Assuming you want to keep the load low enough to not miss deadlines.I don't know that the ouput of the PID is connected to. But it is pointless in running the PID faster than you can change the output. (eg: with 100 hz pwm)

author: danadak
author_rank: Super Contributor
timestamp: March 24, 2017, 12:11:17 pm
content: PID control including most of the analog stuff you will need can be found onPSOC -http://www.cypress.com/documentation/application-notes/an66627-psoc-3-and-psoc-5lp-intelligent-fan-controllerhttp://www.cypress.com/documentation/application-notes/an89346-psoc-4-intelligent-fan-controllerhttp://www.cypress.com/documentation/application-notes/an2208-psoc-1-temperature-pid-using-thermoregulatorFor ref, if youuse this example port in to PSOC 3, 4, 5LP CPU.PSOC has -1) Routability2) Fast 12 bit SAR A/D and slow 20 bit DelSig3) DFB (Digital Filter Block) that is dual channel, handle FIR or IIR filters, or DFBcan be used as a GP fast processor block, similar to RISC block4) MSI logic elements GUI based and/or the UDB Verilog capability. Eg. the FPGAlike capability5) Onboard Vref6) IDAC, VDAC, OpAmps (up to 4), comparator, mixer, switch cap, analog mux....7) LCD, COM, UART, I2C, I2S, One Wire, SPI, Parallel, LIN, CAN, BLE, USB9) Custom components capability, create with schematic capture or Verilog10) DMA to offload processes like filters, COM, Display11) ARM M0 (PSOC 4) or M3 (PSOC 5LP) or 8051 core(PSOC 3)12) Extensive clock generation capabilities13) All components supported by extensive prewritten APIshttps://www.element14.com/community/thread/23736/l/100-projects-in-100-days?displayFullThread=truehttp://www.cypress.com/documentation/code-examples/psoc-345-code-examplesGreat video libraryAttached component list. A component is an on chip HW resource.Free GUI design tool with schematic capture, "Creator". Components have rich API library attachedto each component. Compilers free as well.PSOC 4 is low end of family, consider 5LP parts as well. PSOC 4 also has arduino footprint boards (pioneer) as wellhttps://www.elektormagazine.com/labs/robot-build-with-cypress-psochttp://www.cypress.com/products/32-bit-arm-cortex-m-psocRegards, Dana.

author: brucehoult
author_rank: Super Contributor
timestamp: March 24, 2017, 01:46:20 pm
content: Quote from: Jeroen3 on March 24, 2017, 11:47:50 amOf course.I don't know what you'd be doing that you'd need to run a PID that fast. Nothing mechanical. Self-balancing, steering cars or planes, traction control ... all are fine with orders of magnitude slower control rates than that.

author: Jeroen3
author_rank: Super Contributor
timestamp: March 24, 2017, 02:38:56 pm
content: I can think of very fast pick&placers that might need fast PID loops. Or software controlled loadbanks.

author: retrolefty
author_rank: Super Contributor
timestamp: March 24, 2017, 02:53:16 pm
content: Quote from: brucehoult on March 24, 2017, 01:46:20 pmAnd that is to say nothing about the speed of the process to be controled. Mechanical inertia, thermal mass, etc usually establishes the upper limit as far as sample speed requirement. At large refinery plants under a cental control system with hundreds of PID control loops, a sample speed of 1 sec was usually more then fast enough.Also hard coding of PID tuning values is an especially bad idea. Too many external variations to nothave user access to adjusting them under actual process conditions.

author: sagnikbasu
author_rank: Contributor
timestamp: March 24, 2017, 03:12:05 pm
content: I think you will need some kind of adaptive PID algorithms like twiddle or Ziggler Nichols method.Search for them in Google.

author: nForce
author_rank: Frequent Contributor
timestamp: March 26, 2017, 05:23:15 pm
content: I am still waiting for Kleinstein answer:Quote from: nForce on March 24, 2017, 10:34:33 amMany thanks!

author: Jeroen3
author_rank: Super Contributor
timestamp: March 26, 2017, 08:04:26 pm
content: Only I and D are have a time factor. Usually time factor is fixed in the execution interval.However, if you want to change this runtime you need to factor in this time change to keep the I and D gains identical.Normal, time factor in calculation interval:integral_part += Ki * errorTime compensated:integral_part += Ki * error * dtWhere dT is the time elapsed since the last calculation.Eg: if a short time has elapsed dT will be small, but if a long time has passed dT will be long. The system was allowed to drift further away in a long time, and thus requires more control.This should make the PID capable of variable speeds. However, it's easier to keep the speed fixed unless your application is special.

author: IanB
author_rank: Super Contributor
timestamp: March 26, 2017, 08:19:41 pm
content: Quote from: nForce on March 26, 2017, 05:23:15 pmRemember how a PID control algorithm is defined.Action = Proportional + Integral + DerivativeWhere:Proportional action = Kp * errorTherefore if the error is normalized to percent and the output action is scaled to percent, then Kp is dimensionless. (Normalizing input and output to a fraction of the range is normal when implementing PID controllers.)Integral action = Kp * Ki * (time integral of error)Therefore since the time integral of the error has units of (percent * time) then Ki must have units of (1/time). Ki is not dimensionless!This means you must include the units of Ki when you input it (e.g. Ki = 0.2 repeats per second) and you must include time in your control implementation.Lastly,Derivative action = Kp * Kd * (time derivative of error)Therefore since the time derivative of the error has units of (percent / time) then Ki must have units of time. Kd is not dimensionless either. You must include the units of measure of Kd when you input it, e.g. 20 seconds.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: March 27, 2017, 08:14:41 am
content: why so many of you think that we only need slow PID, PFC control is a simple app that needs PID loop of at least 40Kz there are several many others too.

author: Jeroen3
author_rank: Super Contributor
timestamp: March 27, 2017, 09:09:22 am
content: When PID loops get fast, there will be specialized hardware available. Or you're exploring new terrain...Eg: for power factor control, there are power factor correction IC's that use hardware instead of software. Or at least they make it look like hardware.

author: brucehoult
author_rank: Super Contributor
timestamp: March 27, 2017, 09:59:45 am
content: Quote from: ali_asadzadeh on March 27, 2017, 08:14:41 amNo one says things requiring fast PID don't exist. And it's easy enough to make it as fast as you want, sofeware-wise at least, with a cheap microcontroller. Just perhaps not the very cheapest unless you do some very careful fixed-point arithmetic. Floating point makes it much easier to not fail catastrophically, but requires either a lot of clock cycles or hardware FP or at least a fast full-precision integer multiplier (and careful fixed-point programming, preferably including clamping)I'm guessing here, but I suspect Power Factor Control is best done by someone who has studied control system theory formally, including complex  analysis, eigenvalues and the like. They'll be the people answering the questions about PIDs on public forums, not asking about them.

author: snarkysparky
author_rank: Frequent Contributor
timestamp: March 27, 2017, 11:45:28 am
content: I found an arm cortex m0+ does fixed point math with 64 signed integer quite fast as long as you can make your divisions by a power of two only.

author: nForce
author_rank: Frequent Contributor
timestamp: March 27, 2017, 01:25:51 pm
content: Sorry IanB, but I don't understand why do we here:Quoteinclude the proportinal (Kp) parameter for calculating the integral term?From theory of PID regulators it's only Integral action = Ki * time integral of error.

author: IanB
author_rank: Super Contributor
timestamp: March 27, 2017, 01:46:48 pm
content: Quote from: nForce on March 27, 2017, 01:25:51 pmSee, for example, these references:http://blog.opticontrols.com/archives/124http://www.expertune.com/artCE87.aspxLook at the variety of PID algorithms, but see particularly the "ideal" or "standard" form. In the ideal form of the PID control algorithm the gain applies to the integral and derivative terms as well as the error. Experience has shown that this form is more useful in practice than the pure "parallel" form often seen in textbooks.

author: brucehoult
author_rank: Super Contributor
timestamp: March 27, 2017, 02:05:26 pm
content: Quote from: snarkysparky on March 27, 2017, 11:45:28 amIf you're always dividing by the same thing (or at least by the same thing dozens or hundreds of times) then you can do a 32 bit divide with a 32x32 multiply and a shift, so that's pretty quick.Even on ancient ARM7TDMI, the 32x32 -> 64 multiply took 2-5 I cycles plus 1 S cycle. Plus 1 extra I cycle if you wanted to add the result to what was already in the destination pair. For the divide trick it'll always be the full 6 cycles.10 - 15 years ago ARM7TDMI were running at 1 - 10 MHz, but these days ST has them at 66 MHz, Atmel at 75 MHz, and I saw a reference to Fujitsu at 100 MHz.Of course anything Cortex is far superior, not least because Thumb2 not ARM+Thumb1.

author: nForce
author_rank: Frequent Contributor
timestamp: March 28, 2017, 09:21:09 am
content: Quote from: IanB on March 27, 2017, 01:46:48 pmOh, sorry I didn't know that there were 3 different algorithms. Why don't we multiply the PID terms with dt in all cases of implementing the algorithm in microcontroller?

author: nForce
author_rank: Frequent Contributor
timestamp: March 29, 2017, 03:13:18 pm
content: QuoteDoes my question make any sense? Because I can redefine it.

author: IanB
author_rank: Super Contributor
timestamp: March 29, 2017, 04:33:18 pm
content: Quote from: nForce on March 29, 2017, 03:13:18 pmNo, your question doesn't make any sense. I was hoping you would try to answer the question by yourself by thinking about it some more. Have you tried to understand how time fits into the PID calculations?You may have trouble with this unless you have an understanding of what mathematical integration and differentiation mean. Have you studied these concepts in your mathematics classes?

author: IanB
author_rank: Super Contributor
timestamp: March 29, 2017, 05:34:51 pm
content: In case my previous answer seems unhelpful, an internet search on PID control algorithms will turn up a huge number of documents, descriptive articles and tutorials on the subject.I could write yet another tutorial explanation in this thread, but I would be repeating what others have already done. I would encourage you to read around the topic more widely by yourself.

author: Jeroen3
author_rank: Super Contributor
timestamp: March 29, 2017, 05:56:53 pm
content: The concept is that this:Code:while(forever){P = error * Pgain * 0.1;I = I + (error * Igain) * 0.1;D = (error - error[t-1]) * Dgain * 0.1;Out = P+I+D;wait(0.1);}Is similar to:Code:while(forever){dT = Tnow - Tlast;Tlast = Tnow;P = error * Pgain * dT;I = I + (error * Igain) * dT;D = (error - error[t-1]) * Dgain * dT;Out = P+I+D;wait(random);}Meaning the 0.1 in the first example can be merged with the gains. Which you do implicitly when tuning.However, I have never made a variable time PID controller.

author: IanB
author_rank: Super Contributor
timestamp: March 29, 2017, 06:01:43 pm
content: Quote from: Jeroen3 on March 29, 2017, 05:56:53 pmBut the code quoted above is incorrect and should not be used for reference. (Which perhaps is connected with your last comment.)

author: Kleinstein
author_rank: Super Contributor
timestamp: March 29, 2017, 07:37:05 pm
content: The proportional term is independent from the time step. Only the integral part is proportional to the time step. The differential is inverse proportional to the time step.Variable time step PID is rare, but it works within bound (especially the slope part can change if time steps get to short). In many cases the sampling time also sets the extra low pass filtering to make the D term practical.There are a few cases where a fast PID is needed. One sample is probe high regulation in scanning probe microscopes. Even though it is a mechanical system frequency can reach the 100 kHz range.

author: pelule
author_rank: Frequent Contributor
timestamp: March 29, 2017, 08:49:21 pm
content: Have a look to following pages:https://en.wikipedia.org/wiki/PID_controller#PID_controller_theoryhttps://de.mathworks.com/help/control/ref/pid.html?requestedDomain=www.mathworks.com#responsive_offcanvas.It may help to understand PID and the dependency of sample time for a PID algorithm tranformed out of a continous time system into a discrete time system (using Laplace- and Z-transformation).In discrete systems you normally run the PID algorithm/function after each measurement (measure time = PID loop time = sample time). To call the PID more often does not make sense, just waste performance.If you want to run the PID slower (less often) than after each measurement, the easiest method is, just to skip a number (n) of measurements (to be still syncronous with sampling and to keep the PID calculation simple).If you like to create a flexible system that is a flexible sample time system (or better more or less skipped measurments).Lets say, you measure a value every 1ms (1 ms measurement time), but you run the PID just every 10ms (you skip 9 times the PID) your PID sample time is = 10ms.In that case you have to adopt the time correcting factors in dependency of that "PID" sample time.So easiest way is to define the system based on the shortest/fastest sample time and just use correcting factors if you use run the PID less often (slower).For example:You define KP, KI and KD based on Ti = Td = 1 second, and the fastest sample time of 1 ms.Then the PID adopting factors is easy to calculate:at a PID loop time of1ms => 1000 and 1/100010ms = 100 and 1/100...100ms = 10 and 1/10.../PeLuLe

author: nForce
author_rank: Frequent Contributor
timestamp: March 30, 2017, 10:56:18 am
content: I was following this tutorial:http://coder-tronics.com/pid-tutorial-c-code-example-pt2/And in this tutorial, there isn't any "dt" in I and D terms. So I got confused. From all this if I understand correctly we need to multiply with dt in integral term, and with 1/dt in derivative term. Because that implies from definition.Can someone explain why this guy from the tutorial didn't multiply with a fixed time interval then?

author: Phoenix
author_rank: Frequent Contributor
timestamp: March 30, 2017, 11:42:49 am
content: Quote from: nForce on March 30, 2017, 10:56:18 amThey are implicity incorporated in the gains Kd and Ki. All three gains also implicitly incorporate the dimensional and scalling conversion from ADC volts to PWM duty cycle.Implementation can look very different to theory (even if they are actually the same when pulled apart).

author: nForce
author_rank: Frequent Contributor
timestamp: March 30, 2017, 05:30:07 pm
content: Quote from: Phoenix on March 30, 2017, 11:42:49 amOh I get it now, constants Kd and Ki are already multiplied with "dt". And because it's a fixed interval it doesn't change.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: March 30, 2017, 05:56:09 pm
content: QuoteSeveral companies including ST and infineon has done 40KHz PID on only a single 0.5USD cortex M0 @ 48MHz and include lot's of other stuff like soft start etc.., also Microchip has done it on their dsPIC's with open source software. Search their PFC app notes for more info

author: Jeroen3
author_rank: Super Contributor
timestamp: March 30, 2017, 08:20:07 pm
content: Well, then I must be doing it wrong. But I only get about 4 Khz max on an 72 Mhz M3 with Q15.16 mathematics.

author: brucehoult
author_rank: Super Contributor
timestamp: March 30, 2017, 08:45:45 pm
content: Quote from: Jeroen3 on March 30, 2017, 08:20:07 pmFor three fixed point multiplies and two adds? Yeah, sounds wrong. The M3 should always take 1-2 cycles for a 32x32 multiply. Lower Cortex CPUs can be configured with either 1 cycle or 32 multipliers.A Q15.16 multiply is simply a 32x32->32 multiply followed by a 15 bit right shift. An add is just an add. The whole PID should be under 10 clock cycles.

author: IanB
author_rank: Super Contributor
timestamp: March 30, 2017, 10:00:55 pm
content: Quote from: brucehoult on March 30, 2017, 08:45:45 pmBut there might be some extra time required for practical things like range limiting and input filtering?

author: brucehoult
author_rank: Super Contributor
timestamp: March 30, 2017, 10:55:20 pm
content: Quote from: IanB on March 30, 2017, 10:00:55 pmSure, but 4 KHz is 18000 clock cycles. There's quite a gap between 10 cycles and 18000 cycles. What is a bit of range limiting and filtering going to turn than 10 cycles into? 20? 100?

author: Jeroen3
author_rank: Super Contributor
timestamp: March 31, 2017, 07:37:36 am
content: Only in textbooks a pid is 3 multiplications.

author: Kleinstein
author_rank: Super Contributor
timestamp: March 31, 2017, 09:45:46 am
content: Extra filtering in PID is used of the ADC or there feedback value is coming in faster than the PID loop itself. Thus very fast PID loops tend to be without extra filtering, or filtering will be more like a first step to work on the data.Usually there will be extra anti-windup and limiting / scaling of the output values. So a 10 cycle loop would be hard, but something like 20-50 Cycles is reasonable of it needs to be fast. The glitch free implementation to allow real time changes in the parameters might also add a little - not every time, but worst case.The 18000 cycle long loop code might be due to software floating point and maybe a division to much. This might very well be OK for a slow process, like most thermal systems. Sometimes more readable code is more important than the last bit of speed.

author: nForce
author_rank: Frequent Contributor
timestamp: March 31, 2017, 11:19:27 am
content: So is my statement correct?:QuoteSorry I don't understand indirect answers. Simple yes or no will do just fine.

author: Jeroen3
author_rank: Super Contributor
timestamp: March 31, 2017, 02:11:12 pm
content: Quote from: Kleinstein on March 31, 2017, 09:45:46 amThat is correct. The PID uses multiple RMS computations as error. And changes behavior depending on frequency.There are two arbitrary divisions and one sqrt in the code.However, if you want to regulate a real life system you often have to compute the real life values.

author: Phoenix
author_rank: Frequent Contributor
timestamp: April 02, 2017, 02:19:31 am
content: Quote from: nForce on March 30, 2017, 05:30:07 pmKi is already multiplied by dt. Kd is already divided by dt. This is for a practical implementation.In THEORY Kd and Ki do not contain dt, but since they are constants in practice you can lump them together and save computation.

author: nForce
author_rank: Frequent Contributor
timestamp: April 06, 2017, 12:44:44 pm
content: I have a few other theoretical questions:- Which is the highest sample frequency at which the system will still work?- Which is the lowest sample frequency at which the system will still be stable?These two questions are from electronics and control theory, they are theoretical so I would be happy if someone can also explain how to get the frequencies.Thank you

author: retrolefty
author_rank: Super Contributor
timestamp: April 06, 2017, 01:26:07 pm
content: Quote from: nForce on April 06, 2017, 12:44:44 pmIt is all dominated by the process time lag,volume capacity,physical process limits. I saw process control loops that received new PV input data only once a min used in large petrochemical plants.That is why loop tuning variables (PID constants) can be such a challenge with such a difference in process applications.

author: nForce
author_rank: Frequent Contributor
timestamp: April 07, 2017, 10:09:07 am
content: Thank you retrolefty for your reply. What about in theory?Is there some sort of algorithm or formula for calculating stability and possibilty of working?

author: retrolefty
author_rank: Super Contributor
timestamp: April 07, 2017, 12:27:41 pm
content: Quote from: nForce on April 07, 2017, 10:09:07 amIf one could model the external process I'm sure there could be, it's just above my pay grade.

author: nForce
author_rank: Frequent Contributor
timestamp: April 08, 2017, 10:59:40 am
content: Quote from: retrolefty on April 07, 2017, 12:27:41 pmI meant, for this PID algorithm which we discussed in this topic. See my first post of the question.

author: IanB
author_rank: Super Contributor
timestamp: April 08, 2017, 04:22:18 pm
content: Quote from: nForce on April 07, 2017, 10:09:07 amYes, it is called control theory. It is a complex subject involving a lot of mathematics and cannot be explained in a short post. It is something you could spend many months learning about in an advanced college course.An internet search will turn up some introductory material on the subject of PID controllers, design, implementation, tuning and stability. For example:http://ingscientif.yolasite.com/resources/pid%20control%20book%202nd.pdfhttp://act.rasip.fer.hr/materijali/11/pid_Control_15_1_2007.pdfhttps://www.cds.caltech.edu/~murray/courses/cds101/fa02/caltech/astrom-ch6.pdfThe simplest answer is that sample period of a discrete control implementation must be "short" relative to the dominant time constants of the process. Making the sample period too short generally doesn't matter. Making it too long will reduce the stability of the controller.

author: f5r5e5d
author_rank: Frequent Contributor
timestamp: April 08, 2017, 05:01:45 pm
content: "too high" a sample frequency becomes a problem with needing additional wordlength in your accumulators/calculations to keep the decreasing differences within your quantization/rounding resolutioncontrol loops are characterized by "unity loop gain intercept" frequency == where the feedback, "excess loop gain" is reduced to unityfor stability, the total phase shift at this unity loop gain frequency of process and controller has to be less than 180 degreesthis includes the controlled process' dynamics and the digital controller's required anti-alias filtering, digital sampling, calculation and ADC/DAC delaystypically just workable digital sampled control uses 4-5x higher sampling than the unity loop gain intercept frequency, but requires close analysisby 10-20x sample rate the digital controller delays typically become small enough to be ignored in the analysis, control algorithm design

author: ehughes
author_rank: Frequent Contributor
timestamp: April 09, 2017, 12:04:45 am
content: Be careful with falling into the "1 cycle trap on the cortex m3/m4". While this is technically true, It assumes everything is setup in the source registers. It is not uncommon to have several cycles of register manipulation get the operation setup.For reference it is possible to get floating point PID in 12 cycles on a flash based Cortex M4(LPC54114 : Code in Flash, Data in RAM) and 11 cycles for a ram based implementation ( LPC4370 : code in RAM and data in RAM).This was done with the CMSIS DSP libraries compiled with GCC -03. This is with the floating point unit and hard ABI

author: IanB
author_rank: Super Contributor
timestamp: April 09, 2017, 12:13:45 am
content: I do not see the point of doing PID control calculations with floating point. Floating point is designed for values which vary widely in orders of magnitude, from 1e-6 to 1e+6, say. However control calculations usually need values scaled between 0 and 1 (i.e. 0 - 100%). With scaled and normalized values you can work very efficiently with fixed point arithmetic.

author: brucehoult
author_rank: Super Contributor
timestamp: April 09, 2017, 01:03:31 am
content: Quote from: IanB on April 09, 2017, 12:13:45 amI agree fixed point is fine. Two things though:1) you have to think a bit harder to understand your particular problem and the likely values. Floating point lets you get away without thinking. It also make it much easier to use standard libraries.2) you'd better use fixed point with saturating arithmetic. Especially on the I term. Overflowing and wrapping is very bad.