Pumpkin, Inc.

Pumpkin User Forums

Clearing ticks in OS_Delay

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

Clearing ticks in OS_Delay

Postby Nado » Thu Oct 16, 2003 12:11 am

Hello -
I have a quick question. What's the best way to clear the number elapsed ticks when using OS_Delay?

For example, lets say I have a task that activates every 10 ticks (ie. OS_Delay(10,label)). If after 5 ticks have expired, I need to reset these ticks to 0 and start the task over, do I need to:

1) Just call OSSetTicks(0), or
2) Call OSStopTask(tcbp), OSSetTicks(0), OSStartTask(tcbp).

Thanks.

Nado
 
Posts: 14
Joined: Tue Apr 02, 2002 12:00 am
Location: Westlake, OH, USA

Re: Clearing ticks in OS_Delay

Postby aek » Thu Oct 16, 2003 2:14 am

Hi Nado.

Long time no hear ...

If I understand you correctly, neither way will work.

Setting and clearing ticks has no effect on delays. The system ticker is just a free-running counter that's incremented each time OSTimer() is called. It can be redefined (e.g. cleared), but that has no effect on delayed tasks, since they're handled in parallel ... the delays of delayed tasks are decremented each time OSTimer() is called.

Put another way, ticks are really just for reading elapsed time via OSGetTicks().

If you need to stop and perhaps restart a delayed task, you need to use OSStopTask(), OSStartTask(). The task will resume execution immediately after its call to OS_Delay().

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

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

Re: Clearing ticks in OS_Delay

Postby Nado » Fri Oct 17, 2003 7:46 am

So when I call OSStartTask(TIMER_TCBP), will that reset the delay back to 10 ticks?

Lets say, 5 ticks of OS_Delay(10,label) have expired when OSStopTask(TIMER_TCBP) is called. When OSStartTask(TIMER_TCBP) is called again, will the delay resume where it left off, reset back to 10 ticks, or possibly execute the rest of the task if the remaining 5 ticks expire before OSStartTask(TIMER_TCBP) is called?

Nado
 
Posts: 14
Joined: Tue Apr 02, 2002 12:00 am
Location: Westlake, OH, USA

Re: Clearing ticks in OS_Delay

Postby aek » Fri Oct 17, 2003 8:19 am

Stopping and restarting a delayed task involves pulling the task out of the delay queue, and then making it eligible again.

So, when it (re-)starts, it will begin executing immediately after the OS_Delay(10). Therefore the next delay (assuming that's the only call to OS_Delay() in that task) will again be 10 ticks long.

Keep in mind that you can always use a variable (instead of a constant) as the delay argument to OS_Delay(). Therefore you could use a global, and control it explicitly as part of starting and stopping that task ...

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

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

Re: Clearing ticks in OS_Delay

Postby aek » Fri Oct 17, 2003 8:25 am

If you want to re-start the task from the very beginning, then you'll need to destroy and re-create the task instead of stopping and starting it.

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

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


Return to PICmicro MCUs

Who is online

Users browsing this forum: No registered users and 1 guest

cron