Page 1 of 1

problem with OSDelay()

PostPosted: Fri Feb 04, 2005 3:32 am
by sharaf_embedded
Hii all,

Following is the program i coded anticipating that state of BULB would change every minute, but it changes almost every 10 seconds.

code:
#include "main.h"
#include "salvo.h"

#define TASK_ON_BULB_P OSTCBP(1)
#define TASK_KEY1_PRESS_P OSTCBP(2)

#define PRIO_ON_BULB 2
#define PRIO_KEY1_PRESS 2

_OSLabel(TaskOnBulb_Label)
_OSLabel(TaskKey1Press_Label)

sbit BULB = P1^1;

unsigned int higherValue;
unsigned int lowerValue;

void TaskOnBulb(void)
{
while(1)
{
OS_Yield(TaskOnBulb_Label);
}
}

void TaskKey1Press(void)
{
while(1)
{
BULB = !BULB;
OS_Delay(1200, TaskKey1Press_Label);
}
}

void ISR0(void) interrupt 1
{
TH0 = higherValue;
TL0 = lowerValue;
OSTimer();
}

void main( void )
{
Init();

OSInit();

P1 = 0X04; /*0000 0100*/

higherValue = 0x3C;
lowerValue = 0X0B0;

TMOD = 0X01;
EA = 1;
ET0 = 1;
TH0 = higherValue;
TL0 = lowerValue;
TR0 = 1;

OSCreateTask(TaskOnBulb, TASK_ON_BULB_P, PRIO_ON_BULB);
OSCreateTask(TaskKey1Press, TASK_KEY1_PRESS_P, PRIO_KEY1_PRESS);

while(1)
OSSched();
}


I am not sure if the problem is with my concept of OSTimer() and OSDelay(). Any help is appreciated.
Thanks,
Sharaf

[This message has been edited by aek (edited February 04, 2005).]


Re: problem with OSDelay()

PostPosted: Fri Feb 04, 2005 6:36 am
by aek
Hi Sharaf.

1) At what rate is the ISR called? Not in theory, but by actual measurement ...

2) Assuming you're building with a Salvo library, your call to OS_Delay() is really

code:
OS_Delay(176, label);

Why? Because Salvo libraries are built with 8-bit delays, and your argument to OS_Delay() is much larger than 8 bits. Hence you get a real argument of 1200 mod 256 = 176.

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


Re: problem with OSDelay()

PostPosted: Fri Feb 04, 2005 11:26 am
by sharaf_embedded
Hii
Thank you. It works well.

Re: problem with OSDelay()

PostPosted: Sat Feb 05, 2005 7:20 am
by aek
Great!

For longer delays, you either need Salvo Pro (and do a source-code build with OSBYTES_OF_DELAYS = 2 or 4, or build a custom library in a similar manner), or you can follow the suggestions in our App Note AN-7.

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