using float variable in an interrupt

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
nils
Posts: 33
Joined: Fri Nov 02, 2007 11:03 am

using float variable in an interrupt

Post by nils »

Hello

I am about to make a revolution counter on an atmega32 and I need to use at least float or double variables to calculate the time that passed per pulse.
the problem is, that I do this inside of an interrupt, because I want to have the exact value of the time that is counted by another timer interrupt.

when I declare a float inside of the main macro, the variable won't be available in the interrupt because it is not declared globally, and the parameter passing to the interrupt doesn't work as well because it is a self defined value.

do you have any idea how to solve this problem? or is there a way to globally declare a variable outside of the main macro?

thanks in advance, nils

nils
Posts: 33
Joined: Fri Nov 02, 2007 11:03 am

Post by nils »

ok, I figured something myself out:

as long as I do the calculating INSIDE the macro, I can use self defined float variables. then I do my calculations, and afterwards do a narrowing cast by assigning the float to a FCV_ variable that may be an INT or BYTE. it doesn't work out the decimal point thing, but it may help if you want to do something like 5000 / 25000 that would be zero if calculated with an INT

nils
Posts: 33
Joined: Fri Nov 02, 2007 11:03 am

Post by nils »

ok, and now I figured out, where I can implement my own global variables. it is a bit hidden inside the edit menu under supplementary code, I have to admit, but it's there :-)

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Post by Sean »

Hello Nils

Global declarations can be made via the Edit->Supplementary Code menu.

Use the "Definitions and function declarations" window to declare your new variable.

Post Reply