Pumpkin, Inc.

Pumpkin User Forums

problem with OSDelay()

If you can't make Salvo do what you want it to do, post it here.

problem with OSDelay()

Postby sharaf_embedded » Fri Feb 04, 2005 3:32 am

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

sharaf_embedded
 
Posts: 5
Joined: Tue Jan 04, 2005 12:00 am
Location: Malappuram, Kerala, India

Re: problem with OSDelay()

Postby aek » Fri Feb 04, 2005 6:36 am

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.

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

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

Re: problem with OSDelay()

Postby sharaf_embedded » Fri Feb 04, 2005 11:26 am

Hii
Thank you. It works well.
sharaf_embedded
 
Posts: 5
Joined: Tue Jan 04, 2005 12:00 am
Location: Malappuram, Kerala, India

Re: problem with OSDelay()

Postby aek » Sat Feb 05, 2005 7:20 am

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.

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

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


Return to Coding

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron