At 07:58 PM 4/8/05 +0000, ed_hage wrote:
>I have a simple interrupt-function for the PWM which reads the duty
>cycle variable and then sets the DC. This does not work. In the
>example beneath MR6 does give a good duty cycle (but is fixed!! so no
>pracitcal use), and when I use the float DC1 (as in MR4) it does not
>work. This is probably a problem which I may encounter more using
>floats etc. What is the best known method to deal with this? (I am
>newby in programming embedded ... as you might have guessed.
Two methods are available
- The complex way is to save the floating point state, init a new
floating point state, do your calculations and restore the floating point
state. Even if it's possible it's messy and take a while.
- The more usual method is to use fractional or fixed point
arithmetic (slight variations on a theme). In your case
> PWM_MR6 = 0.8*PWM_MR0;
Becomes
PWM_MR6 = (8 * PWM_MR0) /10;
The brackets are important and you need to make sure the intermediate
multiply cannot overflow (by working in the next size integer type if
necessary.
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/Message
Re: [lpc2000] float in interrupt function?
2005-04-08 by Robert Adsett
Attachments
- No local attachments were found for this message.