Page 1 of 1

OS_Delay Strange problem ...

PostPosted: Thu Dec 25, 2008 1:56 am
by marabej
Hi

Excuse me for poor English.

I've got a strange problem with OS_Delay.
Have a look the following code :

----------------------------------------
_OSLabel(TaskB1)
_OSLabel(TaskC1)

#define TMR0_RELOAD 156 /* for 100Hz ints @ 4MHz */

void interrupt IntVector( void )
{
if ( T0IE && T0IF )
{
T0IF = 0;
TMR0 -= TMR0_RELOAD;
OSTimer();
}
}

void TaskB( void )
{
int i;
for (; ; ) {
RB1=!RB1;
for(i=0;i<10;i++)
OS_Delay(10, TaskB1);
}
}


void TaskC( void )
{
int i;
for (; ; ) {
RB2 = !RB2;
for(i=0;i<10;i++)
OS_Delay(10, TaskC1);
}
}

void main( void )
{
CMCON = 7;
TRISB = 0
OPTION = 5;
INTCON |= 32;
TMR0 = 255-TMR0_RELOAD;
OSInit();
OSCreateTask(TaskB, OSTCBP(1), 10);
OSCreateTask(TaskC, OSTCBP(2), 10);
OSEi();
for (; ; )
OSSched();
}

The problem is , that when OS_Delay is situated in some cycle , it give unpredictable results. In this case the two impulse series must be same , but they are very very different. If I add other task the result is same ( for example chage the upper limit in for cycle ( i<10 ) may to influence to the other tasks ). Maybe the problem isn't in my code , I use for tests Proteus 6, but it works fine for me since 3 years almost.

[This message has been edited by marabej (edited December 25, 2008).]


Re: OS_Delay Strange problem ...

PostPosted: Thu Dec 25, 2008 7:42 am
by aek
Make <i> static in your tasks ...

------------------


Re: OS_Delay Strange problem ...

PostPosted: Fri Dec 26, 2008 11:32 am
by marabej
pay attention : these two same tasks give different results. ex RB1 generates impulse twice bigger from RB2

void TaskB( void )
{
static int i;
for (; ;) {
RB1=!RB1;
for(i=0;i<2;i++)
OS_Delay(100,TaskB1);
}
}

void TaskC( void )
{
static int i;
for (; ;) {
RB2=!RB2;
for(i=0;i<2;i++);
OS_Delay(100,TaskC1);
}
}

[This message has been edited by marabej (edited December 26, 2008).]