Pumpkin, Inc.

Pumpkin User Forums

OS_Delay Strange problem ...

For issues specific to Microchip's PICmicro® MCUs, including compilers (e.g. HI-TECH PICC & PICC-18, Microchip MPLAB®-C18) and IDEs (e.g. Microchip MPLAB®).

OS_Delay Strange problem ...

Postby marabej » Thu Dec 25, 2008 1:56 am

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).]

marabej
 
Posts: 2
Joined: Thu Dec 25, 2008 12:00 am
Location: Sevlievo,N/A,Bulgaria

Re: OS_Delay Strange problem ...

Postby aek » Thu Dec 25, 2008 7:42 am

Make <i> static in your tasks ...

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

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: OS_Delay Strange problem ...

Postby marabej » Fri Dec 26, 2008 11:32 am

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).]

marabej
 
Posts: 2
Joined: Thu Dec 25, 2008 12:00 am
Location: Sevlievo,N/A,Bulgaria


Return to PICmicro MCUs

Who is online

Users browsing this forum: No registered users and 4 guests

cron