This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Calling functions & passing parameters from ISR

Hello,

I am having two problems which I think are pretty much related to each other:

Problem 1: passing parameters to function called from ISR

I am invoking a function from ISR. To this function, I pass a variable (unsigned char). When the function is invoked, the value received in the function is zero! If the same function is called from main (), then the value received = the value passed. What am I missing ? How to rectify this problem, besides use of global variables to pass the data (this work around I am already using).

Problem 2: function called from ISR does not behave as intended

There is a delay function that I invoke from the ISR (void delay_6ms()). I have simulated the code on KEIL, which shows that the delay introduced by this function should be to the tune of 6 msec. When I invoke it from ISR, the delay is about 320 usec, however, when I invoke it from main (), the delay is about 4 msec. Why the difference ? Why main() does not give 6 msec delay ?

If I declare the variable inside the function as static (i and j), the delay in ISR changes to 1.4 msec. I tried to declare the function reentrant to see the effect, but there was no change.

---------------------------------------------------
void delay_ms()
{ unsigned char xdata i; unsigned char xdata j;

i = 0;

while(i++ < 25) { j++; }

i = 0;
}

void delay_6ms ()
{ delay_ms();
delay_ms();
delay_ms();
delay_ms();
delay_ms();
delay_ms();
} ---------------------------------------------------

This function should give 1 msec delay, and if called multiple times, then should give a delay in proximity to the number of times it is called.

Regards
Aman

0