Tool/software: TI C/C++ Compiler
Hello again,
I have a problem when using Objects in Interrupt routines, I hope I can explain the problem understandable.
First things first. I wrote 2 Timer ISR. Timer 1 interrupts every µS and increments a counter so I can monitor the elapsed Microseconds since the reset of the F28062. Timer2 interrupts every milliSec and increments another counter so I can monitor the elapsed milliseconds since the reset. (Iknow I could calculate the millis from the µS but the calculation takes to much time).
Next I have 2 functions. The first is "micros()" and "millis()". As you can imagine, they return the current value of the counter that increments every µS or ms. Both variables unsigned longs.
So now I use a header only lib that implements 2 classes. This lib is this "https://github.com/pfeerick/elapsedMillis". It uses some operator overloading and create an object that uses millis() or micros() to get/increment automatically.
So this is the version that is working
unsigned char trigger = 0;
elapsedMicros DataTime = 0;
void main(void)
{
.
.
.
while(1)
{
if(trigger)
{
trigger=0;
DataTime = 0;
}
if(DataTime > 5000000)
{
//doSomething
}
}
}
__interrupt void Pin_ISR(void)
{
trigger = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
As long as I push the button repeatedly to trigger the PIN_ISR and the //doSomething branch will not trigger. It is working because the DataTime is reseted in the main loop.But when I reset the DataTime in the ISR it will not work.
Here is the code that is not working.
elapsedMicros DataTime = 0;
void main(void)
{
.
.
.
while(1)
{
if(DataTime > 5000000)
{
//doSomething
}
}
}
__interrupt void Pin_ISR(void)
{
DataTime = 0;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
The non wokring code will instantly trigger the "//doSomething if branch" even if the 5 seconds haven`t passed because the value of DataTime won`t be 0 but a very high number.
Has anyone an idea why it is like this?
Thanks