What is the value of MR0? By dividing first, you are losing precision
(unless the lower 7 bits are all zeroes).
For example if MRC has 1289 decimal in it and you divide by 100, you have
12, then multiply by 80, you get 960, not 1031 that you should get.
Multiply by 8 and then divide by 10 yields the correct result.
And for 80%, just use 8/10 - not 80/100.
What do you mean by "does not work". Are you getting PWM output with the
wrong values? Or just no output?
_____
From: Robert Adsett [mailto:subscriptions@...]
Sent: Friday, April 08, 2005 3:08 PM
To: lpc2000@yahoogroups.com
Subject: Re: [lpc2000] Re: float in interrupt function?
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/
_____
Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/lpc2000/
* To unsubscribe from this group, send an email to:
lpc2000-unsubscribe@yahoogroups.com
<mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe>
* Your use of Yahoo! Groups is subject to the Yahoo!
<http://docs.yahoo.com/info/terms/> Terms of Service.
[Non-text portions of this message have been removed]Message
RE: [lpc2000] Re: float in interrupt function?
2005-04-08 by Dan Beadle
Attachments
- No local attachments were found for this message.