cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to variables within interupt rutines

us2
Associate II
Posted on May 01, 2003 at 08:49

Writing to variables within interupt rutines

3 REPLIES 3
us2
Associate II
Posted on April 30, 2003 at 06:02

Hi

First, I want to say that I am using the ST72334 and Metrowerks (shouldn't make any difference though).

Here is my question/problem:

In an interupt service rutine I have a call to a function which does some floating point calculation and then saves the result in a global variable. The funtion has some parameter declarations but does not return any variables. Like this:

Code:

void calc(unsigned char x, unsigned int y)

{

extern float a;

extern float b;

extern float result[2][2];

float c;

c = a*b + y;

result[x][1] = c;

}

The calculations are fine but when I want to save the result in the global variable result the program crashes when it runs on my ST7 board (because it runs when I disable the command result[x][1] = c).

Why can't I save this local variable c in the global variable result? It is no problem to write a value eg. 34e-25 to result! I just can't save a variable.

I hope someone can explain what I am doing wrong because I am completely blank.

Please help someone.

Thanks,

Ulrich

stephanie
Associate II
Posted on April 30, 2003 at 07:50

Here below some advises:

* check that your char x is equal to 0 or 1

* supress the useless float c as follows:

void calc(unsigned char x, unsigned int y)

{

extern float a;

extern float b;

extern float result[2][2];

result[x][1] == a*b + y;

}

* check the generated assembly code

* check your function call

* check in Metrowerks documentation if floats can be used in an interrupt routine

Good work!
us2
Associate II
Posted on May 01, 2003 at 08:49

Hi again.

I found out the float and long can ONLY be used in an interrupt service runtine (ISR) if you use the commands SaveLong() and RestoreLong() in the beginning and the end of the ISR, respectively. The commands take a pointer to a memery location of atleast 24 bytes.

The problem is that the documentation is very sparse and does not describe very well how you do it.

What is it exactly I have to save with the SaveLong and RestoreLong commands and how would I do it?

Best regards,

Ulrich