Interrupt function instead of a while cicle?

Create new topics, add your comment, remark, bugs...
Post Reply
graele
Posts: 10
Joined: Fri Feb 06, 2009 11:04 am

Interrupt function instead of a while cicle?

Post by graele » 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

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: Interrupt function instead of a while cicle?

Post by LubinKerhuel » Sat Mar 21, 2009 4:42 pm

Hi Grael,

This is a good solution to run a task in background (i.e., with a low priority). This background task will be interrupted (preempted) by the main control task..

On some microcontrollers, calling function from interrupt may cause problems. That must be tested/checked.
Just set the timer interrupt to the lowest priority to allow others interrupt to execute.

Btw, I do not know how to make a background task from simulink. So, except if you add manually the background task (modifying generated C code ), there is no interrest to add this possibility (in the master block for example). Anyway, If you know a way to do it from simulink directly, please let me know...

Ps: Wat about using a multirate model ? you could divide tasks of your background tasks and execute them at lower rates to not disturb the main real time algorithm.

Lubin

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests