|
|
View previous topic :: View next topic |
Author |
Message |
lsteele
Joined: 02 Jan 2007 Posts: 18
|
simple floating point in an interrupt |
Posted: Tue Jan 02, 2007 4:00 pm |
|
|
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
|
|
Posted: Tue Jan 02, 2007 4:55 pm |
|
|
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);
}
} |
|
|
|
|
|
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
|