Yahoo Groups archive

Lpc2000

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

Message

Re: [lpc2000] Re: float in interrupt function?

2005-04-08 by Robert Adsett

At 10:01 PM 4/8/05 +0000, ed_hage wrote:
>thank you for the info.
>That is a good and simple way to avoid floats.
>
>The only thing that I can not get done is to use a global variable to
>multiply (the global is being updated by other functions like
>controller-function).
>
>I changed to the following but it still does not work:
>
>//global
>int DC1 = 80; // 80%
>
>void IRQMotorOut (void)
>{
>   PWM_MR4 = PWM_MR0 / 100;
>   PWM_MR4 *= DC1;   // 0<DC1<100 [%]
>   PWM_IR = PWM_RESET_MR0; //clear flag
>   PWM_TCR = (1<<1);
>   PWM_TCR=(1<<0);
>   VICVectAddr = 0;
>}
>
>What could I be doing wrong?

Your order of arithmetic is wrong.  Change to:

PWM_MR4 = (PWM_MR0 *DC1)/100;

or if PWM_MR0 *DC1 will EVER overflow 32bits

PWM_MR4 = (PWM_MR0 *(long long)DC1)/100;

An optimization note:

If you change your divisor to a factor of 2 the division can become a right 
shift.  Much faster on the ARM since it does not have a HW divide operation.

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,   be 
they legal, genetic, or physical.  If you don't believe me, try to chew a 
radio signal. "  -- Kelvin Throop, III
http://www.aeolusdevelopment.com/

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.