Yahoo Groups archive

Lpc2000

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

Message

RE: [lpc2000] float in interrupt function?

2005-04-08 by Dan Beadle

In general, try to keep interrupt functions short and sweet.  Floating
brings in many more cycles, for very little benefit in cases like this.

 

You can get almost the same results with simple fixed point math.  As long
as MR0 is below 2^28 (2^28 x 8 will not exceed 2^31, the max integer) (which
it probably is unless your motor is VERY slow), you can simply multiply by 8
then divide by 10.

 

PWM_MR4 = PWM_MR0*8;

PWM_MR4 /=10;

 

If you put the *8/10 on two lines, you guarantee that the 8/10 does not
truncate to 0.

 

The in-line integer math will run much faster.  And then you don't have to
worry about library calls from interrupts, library reentrancy, etc. 

 

  _____  

From: ed_hage [mailto:ed_hage@...] 
Sent: Friday, April 08, 2005 12:58 PM
To: lpc2000@yahoogroups.com
Subject: [lpc2000] float in interrupt function?

 


I am using a LPC2106-board from Olimex to drive two motors via PWM.

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.

// single edge PWM 
//global
float DC1 = 0.800;

void IRQMotorOut (void)
{
  PWM_MR4 =  ((unsigned long) (DC1 * PWM_MR0));  
  PWM_MR6 = 0.8*PWM_MR0; 
  PWM_IR = PWM_RESET_MR0; //clear flag
  VICVectAddr = 0;
}






  _____  

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]

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.