Pumpkin, Inc.

Pumpkin User Forums

time errors of Delays in SALVO

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

time errors of Delays in SALVO

Postby luben » Sat Jun 16, 2001 1:02 am

Hello,

I have some questions about OSTimer() functionality.

First what I saw is that you removed the option SUPERTIMER, maybe in the new SALVO it’s not necessary at all.

Second:
Imagin that I have project with OSTimer() that runs every 10ms. And I want to make delay of 10ms in some of the tasks. Because the setting of OS_Delay(time_10ms,…) in the task is asynchronously to the timer operation, it could appear:
. very close before ISR will call OSTimer()
. immediately after ISR called OSTimer()
. somwhere in the middle

My question is about the time errors.

If the task periodically delays (it’s the delay for waking the task), then this mistake is not so big, and could be bigger only in the first execution of the OS_Delay(time_10ms,….). But what about some process that comes from time to time? Is the error of delays one tick?

In the new manual is not enough explanation about the OSTimer(), prescaller and how they work. From one side the error should be one tick (the biggest possible error), from other side for periodical processes (like perioodical wake up of the task) it’s much lower – the worst case of executing all other tasks before the current or tasks with higher priority length.

From what I know about SALVO the precision will be +/- one tick. That means, I should call more frequently the OSTimer(). If I use prescaller to the timer, does this reduce the time error, or prescaller just reduces the rate.

I meant, the error of delays in SALVO are different for periodical and single processes and this si not menshened in the manual.

In the example I gave (10ms delay with 10ms tick rate) the error is too big – up to 100% !!!! This is not acceptable. Maybe I have to speed up the rate and to use bigger values in OS_Delay(), or if prescaller effects the OSTimer – to use some prescaller value. Would be grate if the prescaller in the new SALVO has the functionality of the OSSUPERTIEMER of the old SALVO.

What I can imagine right now that will be in “SALVO style”, is to run other timer in the processor (let’s say TMR1 in PIC) and to use some BinSem to show the completion of the operation. Using standard delays with loops is absolutely out of the SALVO style – they totally occupy the resources of the processor.

From other side the abcense of information in the manual is fully compensated with really excellent and perfect support in the net :-)

Regards
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: time errors of Delays in SALVO

Postby luben » Sat Jun 16, 2001 6:50 am

Hi,

I think that you missed something - the described prescaller has different behaviour then the SALVO2.2 - if value is 0 it will make rate 1:256, but in SALVO is 1:1

It's not big deal to add:

code:

char timerPS = INIT_TIMER_PS;

void interrupt ( void )
{ ...
if ( --timerPS == 0 || (INIT_TIMER_PS == 0))
{
timerPS = INIT_TIMER_PS; OSTimer();
}

...

}


well... maybe it will bring error message for wrong comparision, but will work.

Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: time errors of Delays in SALVO

Postby aek » Sat Jun 16, 2001 8:33 am

NOT a good idea -- no reason to use extra instructions when they're not necessary.

The full Salvo code (v2.2) uses the preprocessor to avoid the case when the prescalar is 0. You can do this:

code:
#define INIT_TIMER_PS  5


#if INIT_TIMER_PS >= 1
#define ENABLE_PRESCALAR TRUE
#else
#define ENABLE_PRESCALAR FALSE
#endif


#if ENABLE_PRESCALAR
char timerPS = INIT_TIMER_PS;
#endif


void interrupt ( void )
{
...
#if ENABLE_PRESCALAR
if ( --timerPS == 0 ) {
timerPS = INIT_TIMER_PS;
OSTimer();
}
#else
OSTimer();
#endif
...
}


This way you use the fewest instructions possible, and avoid problems when INIT_TIMER_PS is 0 or 1. Also, timerPS is allocated only when INIT_TIMER_PS is >= 1.

The INIT_TIMER_PS=1 case is allowed simply to test code size, btw ... otherwise you could do >= 2.

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

Re: time errors of Delays in SALVO

Postby aek » Sat Jun 16, 2001 10:18 am

The "new" timer in v2.2 is in every way equal to or better than the SuperTimer-based one in v2.1 and earlier ... the SuperTimer is no longer necessary in v2.2.

quote:
Imagin that I have project with OSTimer() that runs every 10ms. And I want to make delay of 10ms in some of the tasks. Because the setting of OS_Delay(time_10ms,…) in the task is asynchronously to the timer operation, it could appear:
. very close before ISR will call OSTimer()
. immediately after ISR called OSTimer()
. somwhere in the middle

and

quote:
In the example I gave (10ms delay with 10ms tick rate) the error is too big – up to 100% !!!!

This is a typical situation, and you _will_ get timing errors equal to one tick (maximum) in this situation. It would be much better to set the timer tick to 2ms (i.e. call OSTimer() every 2ms), and then, for a 10ms delay, call OS_Delay(5).

We've taken a very conservative approach to the specification for the timer. Simply put, all timing errors ("periodic" or "single process", as you describe them) are +/- 1 system tick. Of course, they're usually much, much less, but you need to know the worst case. This is the only Salvo timing "rule" you need to know.

So, for reasonably accurate delays of 10ms, choose a system tick rate that's 5-10 times faster, i.e. call OSTimer() every 2ms or 1ms, then "scale" your delays accordingly.

The prescalar is useful when you already have an interrupt that runs much faster. By having a prescalar, you can use a single interrupt source to drive both your own (faster) interrupts and OSTimer().

Let's say you already have a periodic interrupt occuring every 104.6us (e.g. software 9600bps UART). To achive a system tick rate of 200Hz (i.e. 5ms), set the prescalar to 48 and call OSTimer() (at 9600Hz). System ticks will then be processed at 200Hz, or every 5ms, since 9600Hz/48 = 200Hz. The prescalar is just like a hardware prescalar between your interrupt source and OSTimer(). The prescalar overhead inside OSTimer() is very, very small, so it's OK to call it at high rates. Note: This example is for a 20MHz PIC, where a single bit time represents 520 instructions, which should be plenty for OSTimer() to do its job when a task's delay expires.

I will look into adding some more examples of using the timer to the User Manual.

[This message has been edited by aek (edited June 16, 2001).]

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

Re: time errors of Delays in SALVO

Postby aek » Sat Jun 16, 2001 10:34 am

One more thing ... Salvo Lite does not support the prescalar (since it wasn't compiled into the libraries). But you can do that quite easily like this:

code:
char timerPS = INIT_TIMER_PS;

void interrupt ( void )
{
...
if ( --timerPS == 0 ) {
timerPS = INIT_TIMER_PS;
OSTimer();
}
...
}


[This message has been edited by aek (edited June 16, 2001).]

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

Re: time errors of Delays in SALVO

Postby luben » Sun Jun 17, 2001 5:41 am

You're right - the idea of SALVO is to bring the whole power to useful commands and to remove any extra, void cycles. From this point of view my approach is wrong.

Maybe you have to add in the manual, that you don't sell only SALVO code, but and SALVO "style" too. Both they are equal worth :-)

Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria


Return to Coding

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

cron