|
|
View previous topic :: View next topic |
Author |
Message |
theteaman
Joined: 04 Aug 2006 Posts: 98
|
How slow can division really be? |
Posted: Sat Dec 08, 2007 7:43 am |
|
|
Hi
I've got timer0 set up as setup_timer_0(RTCC_DIV_16 | RTCC_8_BIT);
In my interrupt hander for this timer, I have practically nothing, just a few conditional flag setting statements.
When i compile my code I get the good ol' "interrupts have been disabled to prevent re-entrance @DIV3232" warning. But the problem is my interrupt handler is not calling any functions. The offending line is actually a division in another part of the program that is not called, in any way, by the clock interrupt - it's in the main loop.
When I change the division to an addition the warning disappears.
Does anyone know why this is happening?
Thanks
ps. i am dividing int32s. |
|
|
Ttelmah Guest
|
|
Posted: Sat Dec 08, 2007 8:15 am |
|
|
Post the contents of your interrupt handler.
You won't get this message, unless you _are_ calling a division. The 'odds' are that something you don't think uses division, does.
Best Wishes |
|
|
theteaman
Joined: 04 Aug 2006 Posts: 98
|
|
Posted: Sat Dec 08, 2007 3:51 pm |
|
|
Here it is:
Code: |
#INT_TIMER0
//this function is called every time timer0 overflows, approx 1220 times per second
void clock_isr()
{
if(int_count % MOD_CLK_RES == 0)
mod = TRUE;
else
mod = FALSE;
int_count++;
} |
I just discovered that changing the modulus to an addition stops the error.. any ideas? The handler hasn't changed for ages and it was working without warning for a few days but now suddenly it is causing this warning...
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
theteaman
Joined: 04 Aug 2006 Posts: 98
|
|
Posted: Sat Dec 08, 2007 4:30 pm |
|
|
Thanks PCM, I will give it a try. |
|
|
Ttelmah Guest
|
|
Posted: Sun Dec 09, 2007 4:10 am |
|
|
It is also worth working out if you can perform this some other way.
The 'modulus' function, is a division. Modulus is the remainder from a division operation, and hence involves a division. Since the compiler refers to div32, it implies at least one of the numbers is a 32bit value, which implies you are talking about something in excess of 500 machine instructions, for this one operation... :(
Now if (for instance), 'MOD_CLK_RES', could be selected to be a binary value (8, 16 etc.), then you can get the same result, using:
if(int_count & (MOD_CLK_RES-1) == 0)
Which takes less than a dozen instructions.
Also, if this is a counter, and you want to know when it is divisible by (say) 60, to give a zero result, it is about 50 times quicker, to just run a second counter. So:
Code: |
#INT_TIMER0
//this function is called every time timer0 overflows, approx 1220 times per second
void clock_isr() {
static int16 modctr=0;
if (--modctr==0) {
modctr=MOD_CLK_RES;
mod=true;
}
else mod=FALSE;
int_count++;
}
|
Should give the same result (I am assuming 'MOD_CLK_RES', is < 65535), and will do it vastly quicker.
I'd avoid _anything_ involving division in an ISR. At 1220* per second, you could be borderline on actually executing the original code in the interrupt time (depending on the processor involved).
Best Wishes |
|
|
|
|
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
|