CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

simple floating point in an interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lsteele



Joined: 02 Jan 2007
Posts: 18

View user's profile Send private message

simple floating point in an interrupt
PostPosted: Tue Jan 02, 2007 4:00 pm     Reply with quote

Hello,

I want to do some simple floating point in an ISR, like this:

Code:

#INT_TIMER1            // Gyro calculation ISR
void timer1_isr()
{
   isrGyroVal+=currGyroVal;
}


isrGyroVal & currGyroVal are both float's.

Here's the setup code for the timer 1 interrupt:

Code:
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
   set_timer1(0);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL0);


If I've done my sums right this interrupt should be triggering at approx 76Hz.

Intuitively I would have thought that I would have been asking for trouble using floating point in a ISR, but I've tried it, and everything seems to be peachy. Am I saving up trouble for myself further along, or can I get away with this?

Thanks,

Luke
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 02, 2007 4:55 pm     Reply with quote

It's hard to say exactly how long the floating point addition will take,
because the code branches, depending upon the data.
The following program, running on a PicDem2-Plus board, takes about
290 us (max) to execute the line that does the floating point operation.
This is after it's been running for a few minutes. It starts at about 200 us
and the duration slowly increases in length as the operands increase
in size. I measured this with a scope. There are probably better ways
to do this, but this will give you a ballpark figure.
Code:

#include <18F452.h>
#fuses XT, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)

//============================
void main()
{
float isrGyroVal = 0;
float currGyroVal = 0.1234567;


while(1)
  {
   output_high(PIN_B0);
   isrGyroVal += currGyroVal;
   output_low(PIN_B0);
   delay_us(500);
  }

}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group