We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
Calling the same function from Main and and ISR alone can be an issue. The function would need to be reentrant. What happens if main is using the function when the ISR calls it. On a PC it works. With the 51 and Keil it the variable can be corrupted. Not that calling functions from and ISR can have a lot of overhead.