Pumpkin, Inc.

Pumpkin User Forums

Using a Real Time Clock & Salvo RTOS

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

Using a Real Time Clock & Salvo RTOS

Postby phil » Mon Dec 12, 2005 10:48 am

Hello,

I'm using an external RTC with PIC18 core running SALVO RTOS. Can anyone give me any advise on the best way to interface the RTC with SALVO. I want to be able to get tasks to be triggered on specific time events. For example, I have a task turnMotor() which I may want to trigger at times:
10/12/2005 15:30
17/12/2005 7:30
20/12/2005 10:14
02/01/2006 1:00
etc

The RTC stores time as BCD hh:mm:ss DD:MM:YY
I am considering writing functions to normalise this and the OSTimer() to seconds. The values could then be subtracted from one another to determine if the task is eligible to run. Does this seem a sensible thing to to do?

Any advice would be appreciated. Thanks Phil

phil
 
Posts: 12
Joined: Mon Dec 12, 2005 12:00 am

Re: Using a Real Time Clock & Salvo RTOS

Postby aek » Mon Dec 12, 2005 11:16 am

Just some comments ...

1) The overall computational load to process an RTC "tick" every 1s is probably low / neglible in your system. So, assuming it's relatively easy for you to isolate each individual task that needs RTC control, you could do something like:

code:
...
OS_Stop();
...

in each such task, and then restart it with an OSStartTask() called from the RTC ISR, with some smarts built in so you know which task needs to be started at a particular time.

2) You could simply run OSTimer() based of the 1s ticks of the RTC -- but then you'd lose the ability to do sub-1s resolution delays. But I can imagine (I haven't done it myself) that it would be pretty easy to link the two (RTC and OSTimer) together. Say You want Salvo ticks at 50Hz. All of your "task-wake-up" stuff can be done with arguments like OS_Delay(YMDHMS_to_ticks(time)*50);, and the task will wake up very close to the specified time (within 1s to be sure, probably within a few ticks). The issue is how to maintain synchronization between the 50Hz ISR that calls OSTimer() and the RTC itself. I doubt that's terribly hard, and here's why -- there is no "hard link" between delays and timeouts and OStimerTicks -- the rule is simply that OStimerTicks is incremented every time OSTimer() is called, and the delay and/or timeout of every delayed and/or waiting task is decremented for every call to OSTimer(). IOW, delays and timeouts are driven solely by the calls to OSTimer(), and not by the value of OStimerTicks (i.e. Salvo's current ticks). That's why you can call OSSetTicks() without affecting delays, etc. So, what this means is that if you were to sync your RTC against OSTimer(), you can always make slight adjustments to the Salvo system timer by calling OStimer() a few extra times, or holding off calling it for a few (50Hz) ticks, in order to maintain synch to the RTC.

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

[This message has been edited by aek (edited December 12, 2005).]

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

Re: Using a Real Time Clock & Salvo RTOS

Postby aek » Mon Dec 12, 2005 11:23 am

I guess I should mention in case it's not obvious that Salvo can handle multiple calls to OSTimer() between calls to OSSched() -- up to 255, in fact. Normally, OSSched() is called more frequently than OSTimer(), but the system will not break if OSTimer() is called more frequently than OSSched().

So if your synchronization code found that you were 5 ticks slow, it would be OK to call OSTimer() 5 times, even if there was a task that had only 2 ticks left in its delay. Said task would become eligible to run in the next call to OSSched(). You'd probably never notice that anything was afoot.

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

[This message has been edited by aek (edited December 12, 2005).]

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

Re: Using a Real Time Clock & Salvo RTOS

Postby aek » Mon Dec 12, 2005 11:26 am

In fact, it might be easiest to intentionally chose a rate to call OSTimer() that is guaranteed to always be a little slow -- that way you always play "catch up" within the 1s RTC synch code, and it makes your algorithm easier. It just means that there will be a larger error, ticks-wise, in your OS delays and timeouts, but if you're at 1s and ticks are at 50Hz, that's probably a non-issue.

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

[This message has been edited by aek (edited December 12, 2005).]

-------
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 1 guest

cron