Hello, I have designed a PI controller with constants Kp=2.5 and Ti = 12.7. Now I have port this to a fixed point processor. The processor is a 8-bit core with 16-bit accumulator registers. The A/D converter is 10 bit. My input is a in the range 0-10V and the ouput is in the range 0-1. How do I perform the scaling of the signals and the parameters? I have to go from 0-1023 to 0-255 and the parameters also needs to be scaled to fit this range. I guess this is a typical implementation, but I can not find anything about it. Does anyone know some litterature on the subject?
Fixed point PI control
Started by ●September 9, 2008
Reply by ●September 9, 20082008-09-09
sorenbirk wrote:> Hello, > > I have designed a PI controller with constants Kp=2.5 and Ti = 12.7. Now I > have port this to a fixed point processor. The processor is a 8-bit core > with 16-bit accumulator registers. The A/D converter is 10 bit. My input is > a in the range 0-10V and the ouput is in the range 0-1. How do I perform > the scaling of the signals and the parameters? I have to go from 0-1023 to > 0-255 and the parameters also needs to be scaled to fit this range. I guess > this is a typical implementation, but I can not find anything about it. > Does anyone know some litterature on the subject?You'll more likely get your best responses from a group devoted to embedded systems. That said, I can offer a few tips. Will 8-bit precision be enough to make your system work? If not, you will need to implement double-precision arithmetic for at least some of your calculations. That has a strong effect in the scaling you will implement. You may find that even though some inputs need two-octets to cover their range, no products require more than three. If so, you can implement one-and-a-half precision multiplication. That's significantly faster than full double precision, even with an on-board single-precision multiplier. You will be working with fixed-point* arithmetic, although you can move the position of the (in your head) binary point can move from one routine to another. Randy Yates has written an excellent introduction to fixed-point. Read it at http://www.digitalsignallabs.com/fp.pdf Jerry _____________________________________ * "Scaled integer" is another useful search term. -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●September 9, 20082008-09-09
sorenbirk wrote:> Hello, > > I have designed a PI controller with constants Kp=2.5 and Ti = 12.7. Now I > have port this to a fixed point processor. The processor is a 8-bit core > with 16-bit accumulator registers. The A/D converter is 10 bit. My input is > a in the range 0-10V and the output is in the range 0-1. How do I perform > the scaling of the signals and the parameters? I have to go from 0-1023 to > 0-255 and the parameters also needs to be scaled to fit this range. I guess > this is a typical implementation, but I can not find anything about it. > Does anyone know some literature on the subject?You have two problems: What mathematical scheme to use, and how to translate your parameters so they make sense in your scheme. You've further complicated your problem by expressing a time quantity (Ti) as a dimensionless number, when it has to have some time units behind it -- seconds? Sample intervals? Hours? If your Ti is in anything other than control sample intervals, then you need to know your sampling rate, too (and you should be questioning how you're going to convert your controller design in the Laplace domain into a z domain model that you can use to design your difference equations for your software). You need my book. Chapter 6 and 7 will help you with getting from the s domain to the z domain, Chapter 10 deals with the two most popular ways of control with fixed-point math. Most of the semiconductor companies that make microprocessors have white papers dealing with both of these subjects, as well. For the math portion you have a choice between a low-overhead rocky road using all integer arithmetic, or a high-overhead smooth road using fractional arithmetic (unless your overhead is taken care of with a fractional arithmetic library -- which you can get with my book). You didn't say how much excess processor speed you have available, or what language you're planning on using, but you'll almost certainly need more than 16-bit data paths in some places. The easy way to do this is to use all 32-bit integer math ("long" in C), but this can really bog down an 8-bit processor. The more complicated way to do this is to use just as many bytes for each operation as you need, but this is time consuming, and really only appropriate if you're programming in assembly. To determine your gains you need to model the _whole_ system. Your ADC has a gain, counts/volt, or counts/amp, counts/second, or whatever, depending on what it responds to. Your DAC (or other output process) has a gain of volts/count, or whatever, depending. When you block out your system with those gains taken into account, it'll be obvious what your internal Kp needs to be to get your desired external Kp. Your integral gain computation will be a bit more convoluted, because you'll have to take the sample rate into account as well, but that tree, too, will fall to determined analysis. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by ●September 9, 20082008-09-09
Jerry Avins wrote:> sorenbirk wrote: >> Hello, >> >> I have designed a PI controller with constants Kp=2.5 and Ti = 12.7. >> Now I >> have port this to a fixed point processor. The processor is a 8-bit core >> with 16-bit accumulator registers. The A/D converter is 10 bit. My >> input is >> a in the range 0-10V and the ouput is in the range 0-1. How do I perform >> the scaling of the signals and the parameters? I have to go from >> 0-1023 to >> 0-255 and the parameters also needs to be scaled to fit this range. I >> guess >> this is a typical implementation, but I can not find anything about it. >> Does anyone know some litterature on the subject? > > You'll more likely get your best responses from a group devoted to > embedded systems.Actually, cross-posting to this group and comp.arch.embedded is probably best, because DSP implementation is more "DSP" than "embedded".> That said, I can offer a few tips. > > Will 8-bit precision be enough to make your system work? If not, you > will need to implement double-precision arithmetic for at least some of > your calculations. That has a strong effect in the scaling you will > implement. You may find that even though some inputs need two-octets to > cover their range, no products require more than three. If so, you can > implement one-and-a-half precision multiplication. That's significantly > faster than full double precision, even with an on-board > single-precision multiplier.If the OP is like most folks nowadays, they'll be implementing things in C, and 'long' (unless it's one of the perverse compilers floating around out there for 8-bit processors) will give you 32-bit math. As you say it's more than the OP needs, but if they have the processing speed it'll significantly reduce development time.> You will be working with fixed-point* arithmetic, although you can move > the position of the (in your head) binary point can move from one > routine to another. Randy Yates has written an excellent introduction to > fixed-point. Read it at http://www.digitalsignallabs.com/fp.pdf > > Jerry > _____________________________________ > * "Scaled integer" is another useful search term.-- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by ●September 9, 20082008-09-09
Tim Wescott wrote:> If the OP is like most folks nowadays, they'll be implementing things in > C, and 'long' (unless it's one of the perverse compilers floating around > out there for 8-bit processors) will give you 32-bit math. As you say > it's more than the OP needs, but if they have the processing speed it'll > significantly reduce development time.Unless the memory footprint and the speed are too critical, the PID controller can be implemented very well in C in the floating point even on the 8-bitter. The floating point variant is going to be somewhat 15..20 times slower then the integer variant, however on a typical 10-MIPS modern 8-bitter one can process a PID in less then one millisecond, which is satisfactory for many control tasks. It is time to forget the difficult childhood and start thinking of algorithms instead of counting every byte and cycle :-) Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by ●September 9, 20082008-09-09
glen herrmannsfeldt wrote:> Vladimir Vassilevsky wrote: > (snip) > >> Unless the memory footprint and the speed are too critical, the PID >> controller can be implemented very well in C in the floating point >> even on the 8-bitter. The floating point variant is going to be >> somewhat 15..20 times slower then the integer variant, however on a >> typical 10-MIPS modern 8-bitter one can process a PID in less then one >> millisecond, which is satisfactory for many control tasks. > > > But why floating point instead of sufficiently wide > fixed point?It is convenient to have the voltage in volts, the current in amps, and the time in seconds without being bothered with the overflows, underflows and the long tail of the scaling coefficients depending on everything.> Without some details of the actual system > it is a little hard to say, but it seems to me that floating > point is way overused for this type of problem.If the resource is available, why not using it? BTW, from my practice, in many cases PID can be implemented using only the binary shifts (no multiplications). The coefficients can be accurate to the power of 2; this is enough to have the reasonably good performance. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by ●September 9, 20082008-09-09
Vladimir Vassilevsky wrote: (snip)> Unless the memory footprint and the speed are too critical, the PID > controller can be implemented very well in C in the floating point even > on the 8-bitter. The floating point variant is going to be somewhat > 15..20 times slower then the integer variant, however on a typical > 10-MIPS modern 8-bitter one can process a PID in less then one > millisecond, which is satisfactory for many control tasks.But why floating point instead of sufficiently wide fixed point? Without some details of the actual system it is a little hard to say, but it seems to me that floating point is way overused for this type of problem. -- glen
Reply by ●September 9, 20082008-09-09
Tim Wescott wrote:> sorenbirk wrote:(snip)> You have two problems: What mathematical scheme to use, and how to > translate your parameters so they make sense in your scheme. You've > further complicated your problem by expressing a time quantity (Ti) as a > dimensionless number, when it has to have some time units behind it -- > seconds? Sample intervals? Hours? If your Ti is in anything other > than control sample intervals, then you need to know your sampling rate, > too (and you should be questioning how you're going to convert your > controller design in the Laplace domain into a z domain model that you > can use to design your difference equations for your software).I thought the question was how to do scaled fixed point arithmetic. That is at least one question before getting much farther along in the design. -- glen
Reply by ●September 9, 20082008-09-09
sorenbirk wrote:> I have designed a PI controller with constants Kp=2.5 and Ti = 12.7. Now I > have port this to a fixed point processor. The processor is a 8-bit core > with 16-bit accumulator registers. The A/D converter is 10 bit. My input is > a in the range 0-10V and the ouput is in the range 0-1. How do I perform > the scaling of the signals and the parameters? I have to go from 0-1023 to > 0-255 and the parameters also needs to be scaled to fit this range. I guess > this is a typical implementation, but I can not find anything about it. > Does anyone know some litterature on the subject?It seems that the topic of scaled fixed point arithmetic is not covered very well in schools. We learn it somewhere around 5th or 6th grade, but it never comes up again. As someone else posted, Randy has a good discussion on binary fixed point arithmetic. The general idea is that you multiply all the values by an appropriate constant such that they don't get too big for the range of you accumulator, yet are close enough to being integers to get the right answer. Scaled fixed point is a much better solution to many problems than floating point, which mostly hides the problems with rounding and makes for slow implementations on small processors. Since you didn't give all the equations, one can't give exact answers, but you have to put scaling constants in the appropriate places such that the right results come out. For a start, your A/D converter takes 0 to 10 volts and give a number between 0 and 1023. Since 1023 is 10 volts, then you get 102.3 per volt. (I think it is actually 102.4, but maybe close enough for now.) The scaling constants just change the units for the various values. You have to figure out the appropriate values in your case. -- glen
Reply by ●September 9, 20082008-09-09
glen herrmannsfeldt wrote:> Vladimir Vassilevsky wrote: > (snip) > >> Unless the memory footprint and the speed are too critical, the PID >> controller can be implemented very well in C in the floating point >> even on the 8-bitter. The floating point variant is going to be >> somewhat 15..20 times slower then the integer variant, however on a >> typical 10-MIPS modern 8-bitter one can process a PID in less then one >> millisecond, which is satisfactory for many control tasks. > > But why floating point instead of sufficiently wide > fixed point? Without some details of the actual system > it is a little hard to say, but it seems to me that floating > point is way overused for this type of problem. > > -- glen >It really boils down to details quite rapidly. If you're early in the design process and you're not space, power, or technology constrained, then the only reason not to use floating point would be to allow you to shave some pennies off of a high-volume product. If you're trying to wedge a PID algorithm into an existing product that can't use floating point, then you need to go with integer math. If you find that you can't get all of your functionality into a small enough (or low power enough) chip while using floating point, then you can't use floating point. If someone has arbitrarily decided on some slow processor (like a PIC or an 8051), or if there's some compelling reason to use it, then you're back to wedging in fixed point math. Having said all of that, I don't find fixed-point algorithm development particularly more difficult than floating point development once you have a library for it, and it does considerably speed up the control computations, particularly where a 32-bit float with it's 25-bit mantissa just can't cut it but the whole 32 bits in a fixed-point word can. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html






