Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] How to detect a multiply overflow?

2005-08-09 by Anton Erasmus

On 9 Aug 2005 at 16:54, Aalt Lokhorst 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)

You can do a 32x32 bit multiply to get a 64 bit result. You can either use the 64bit result
directly or force the 32-bit answer to the maximum. If you are using gcc you
can declare your variable as a long long which is 64 bits.

Regards
  Anton Erasmus-- 
A J Erasmus

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.