Hello,
Some background info:
Previously, I had been calling a function in the main loop. It should be called approximately every 10ms and it was being called approximately every 10ms, i.e. 10ms+0.7ms. The function has many counters that are used to keep track of time. One of these counter counts up to 24Hrs, which is 8640000 counts. The 0.7ms error caused the 24Hrs to be off by 1.68hrs, i.e. 8640000*10.7ms = 92448 seconds = 25.68hrs.
Therefore, I decided to change the function to an ISR, whose interrupt is a reserved interrupt (C2000) and which allows nesting of all other interrupts. This interrupt's flag (IFR) is set inside a timer isr. Once the timer isr is completed, the interrupt occurs immediately if no other higher interrupts are pending. Otherwise, it runs after all other higher interrupts have completed. This allows the function to act like a task in a real time OS.
Actual Issue:
The function (now ISR) accesses many variables (mainly structure variables) and contains five to six function calls. A significant amount of the variables are used by functions outside of the ISR. I thought these structure variable could be optimized out by the compiler, so I changed all them to volatile types.
Am I correct in thinking that the variables could be optimized out? I haven't yet determine the impact the change has made on runtime performance.
I am thinking this same sort of issue would have occurred if I would have used a RTOS, since each task is a thread of execution that is separate from the main thread of execution. Is that correct?
I could have changed the timer structure, but that would have required a significant amount of work.
Stephen