How to avoid floating point math

Alarm.timerRepeat(5,Repeats);

TimeAlarms doesn't use interrupts. So Repeats is not an ISR (Interrupt Service Routine).

Quote from http://arduino.cc/forum/index.php/topic,37693.0.html

Q: Are there any restrictions on the code in a task handler function? A: No. The scheduler does not use interrupts so your task handling function is no different from other functions you create in your sketch.

Calc = ((float)Count* ((float)720 / (float)k_factor));

just a tip: division is much slower than multiply so this code can be written as

Calc = 720.0 * Count * inverse_k_factor;

As the first value is float the whole expression is float, no need to cast. Yes you need to calculate inverse_k_factor somewhere in advance.

Your intuition is correct. Floating point math is typically implemented via calls. When floating math is used in the isr and elsewhere in the main loop, you can get into re-entrancy -> big issues.

Sometimes 32-bit multificaton is done via calls so same issue.

You can simplify the math or to use a flag.

I don't see the relevance of this. As shown, the only interrupt which is called at all frequently (100 times a second) doesn't do floating maths.

Isn't the floating point code reentrant, in any case? I would have assumed it was, and I can't think of any good reason for it NOT to be.

I suggest you post all of your code - or attach it, if it's too big to post. Various snippets have been posted, but the only complete copy I can see is in the first post, which is formatted horribly and probably out of date.

Just a couple thoughts... (1) I am both surprised and respectfully humbled by the effort you guys gave in getting me in line. I will make the multiplication versus division changes...I do have the app working, against all odds. It's been 2 and a half weeks of grunt work to get up to speed. Newbie efforts are expensive, time wise. But I am building something I think my fellow pilots and I will greatly benefit from, and for that, it is worth it. Christmas came early for a couple of my friends. Thanks all, who assisted, I will be back soon for more advice and abuse ;-) You guys are the absolute best.

But I am building something I think my fellow pilots and I will greatly benefit from, and for that, it is worth it.

Can you tell a bit more (or maybe after Christmas) ?

I know this is an old post, but in the last entry from the OP, he states that he has "3 interrupts". I only see one "Interrupt" (external interrupt) and two functions that get called from the loop. Does the OP consider them to be interrupts because the program "jumps" to them?

Pete Stanaitis

cornwallav8r: I have now 2 weeks solid in programming a new project, and as a newbie I don't mind figuring out my screwups on my own, but now I have what appears to be stack overflow issues due to the overhead of multiple timing interrupts and sensor pulse input interrupts overloading the processor....so my question is....I need to eliminate the floating point math I threw in....I can't remember the tips I read somewhere about how to avoid floating point where workarounds can be done....fractions in my case will kill the project, what is one to do...

Are you to multiply the parts by say, 100 or 1,000 before multiplying or dividing, to move the fractional part up, then afterwards divide it back down, thus preserving the initial decimal fractional part? Is there more to it? Thanks as always...

I suspect your problem lies in misuse of interrupts (for example, executing large, complex blocks of code within the interrupt itself).

There is absolutely no reason to resort to programming witchcraft to simulate floating point when floating point itself works just fine and doesn't use much more flash memory anyway.

And, any variables used by the interrupt service code should be cast as volatile, for example [b]volatile uint8_t busy_flag;[/b]

Rather than exec lots of code in an ISR, you should simply use flags (use uint8_t for atomic access without grief).

For example, you could have a main loop something like this:

while (1) {
    if (flag1) {
        // do somthing
        // flag1 = 0; // says "event 1" is done
    }

    if (flag2) {
        // do something else
        // flag2 = 0; // says "event 2" is done
    }
}

Then all your ISR(s) need to do is set a flag for example:

ISR (INT0_vect)
{
    if (flag1 == 0) {
        // exec event #1 if it's not already being handled.
        // checking this way prevents piling up interrupts until the stack overflows.
        flag1 = 1;
    }
}

Make sense?

@krupski, I want to make myself quite clear that the following is NOT meant to discourage you from continuing to help people and I do believe your post was worth writing for the benefit of everyone else who will come to this thread.

Quote from: cornwallav8r on [u]Nov 29, 2012[/u], 11:19 pm

Last Online: 574 days ago

krupski: Make sense?

I have a suspicion @cornwallav8r will not be responding.

[quote author=Coding Badly date=1506980571 link=msg=3434048] @krupski, I want to make myself quite clear that the following is NOT meant to discourage you from continuing to help people and I do believe your post was worth writing for the benefit of everyone else who will come to this thread.

I have a suspicion @cornwallav8r will not be responding.

[/quote] Oops... didn't notice that. Sorry.

(I'll bet you're right!)