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
"There has to be EEPROM write delay in between. This answers the "why delay in ISR" question"
Actually, it doesn't! ;-) It answers why you need a delay, but not why it needs to be in the ISR.
"The ISR is a "sag" ISR, which means that the system is going down"
Now that does answer the question!
"Should not the compiler handle this; switch the register bank before invoking the function"
It does - but you have to tell it which Register Bank to use! If you don't state a Register Bank with the using qualifier, the compiler, as always, will use its default - which is, I think, Zero.
"If the simulator is saying this function will take "x" msec, why doesnot the actual execution take the same time ?"
Presumably because there's some vital information that you haven't (correctly) supplied to the simulator...