Hi, In the general case, you're pretty much guaranteed overflow: multiplying two numbers of a fixed precision (e.g. 16-bits) gives a result twice that precision (in that case 32-bits). As another reply has pointed out, you can simply declare the result to have twice the precision of the two arguments. However, for 32-bit arguments this is likely to be slow, as there's no native processing of 64-bit values: the compiler will call an internal library function to do the math. It might be worth your while looking at the "Enhanced DSP instructions" (see ARM documentation from ARM): these provide various forms of multiply and add, including some that saturate. The LPC2000 series as ARM7TDMI devices support these instructions. A final thought that strikes me is that do you really need 32-bit arguments? In general 16-bit is fine for most purposes as an input resolution. You can still accumulate at 32- or 64-bits (scaling back to 16-bits if further processing is required). Hope this is of some help. Regards Brendan Murphy --- In lpc2000@yahoogroups.com, "Aalt Lokhorst" <lokhorst@s...> wrote: > Hello All, > > I have concerns about a PID routine which is doing some calculations > with 32-bit values. It uses multiply and add instructions. My concern > about this is, how to detect overflow. > > A overflow can result in a process correction with a wrong sign and this > is not acceptable for the process. What I need in a overflow situation > is a saturated value. > > In the past I was using a 8052, multiplying 32-bit values was possible > but it was done in a lot of 8-bit portions. > With the ARM I can do the same in one instruction but I am missing the > overflow flag. Is there a option to detect an overflow after a multiply? > > I am using the LPC2129 (ARM7) > > Greetings > Aalt > > -- > ============================== > Aalt Lokhorst > Schut Geometrische Meettechniek bv > Duinkerkenstraat 21 > 9723 BN Groningen > P.O. Box 5225 > 9700 GE Groningen > The Netherlands > Tel: +31-50-5877877 > Fax: +31-50-5877899 > E-mail: Lokhorst@S... > ==============================
Message
Re: How to detect a multiply overflow?
2005-08-09 by brendanmurphy37
Attachments
- No local attachments were found for this message.