Interrupt function instead of a while cicle?
Posted: Thu Mar 19, 2009 7:56 pm
Hello everybody..
The generated code substantially work with a for cicle of this type:
for (;;) {
/* Associate rt_OneStep() with a timer that executes at the base rate of the model */
while (!_T1IF);
_T1IF = 0;
rt_OneStep();
}
so, that everytime the timer generates the interrupt, the flag changes and, after resetting it, the program executes the step routine..
I wonder about the differences if I implement it by changing the code in a different way.. like this for example:
for (;;) {
// my code...
}
and then I call the step routine from the timer interrupt function...
void __attribute__((interrupt, no_auto_psv))_T0Interrupt(void) {
_T1IF = 0;
rt_OneStep();
}
I'm thinking about this solution so that I can put my control routine in rt_onestep.. and this is called each T time.. assuming that for the routine it takes Tr time,
I can efford the other code in the T-Tr time without compromising the performance of my control algorithm..
What do you think about this solution? Can it really improve my control algorithm as I'm thinking, or is there something I'm not considering??
Manu
The generated code substantially work with a for cicle of this type:
for (;;) {
/* Associate rt_OneStep() with a timer that executes at the base rate of the model */
while (!_T1IF);
_T1IF = 0;
rt_OneStep();
}
so, that everytime the timer generates the interrupt, the flag changes and, after resetting it, the program executes the step routine..
I wonder about the differences if I implement it by changing the code in a different way.. like this for example:
for (;;) {
// my code...
}
and then I call the step routine from the timer interrupt function...
void __attribute__((interrupt, no_auto_psv))_T0Interrupt(void) {
_T1IF = 0;
rt_OneStep();
}
I'm thinking about this solution so that I can put my control routine in rt_onestep.. and this is called each T time.. assuming that for the routine it takes Tr time,
I can efford the other code in the T-Tr time without compromising the performance of my control algorithm..
What do you think about this solution? Can it really improve my control algorithm as I'm thinking, or is there something I'm not considering??
Manu