Page 1 of 1

Time accuracy in Salvo

PostPosted: Fri Nov 24, 2000 7:34 am
by luben

One another question - if my time slice is for example 10ms, what is the accuracy of this time. I mean, how exactly is the time. I know that you use timer interrupts, but if some other events occure this time could be changed a little bit. I'm sure that this is not one machine cycle (for 10ms). I'm sure that your timing is very accurate, just asking - how much +/- cycles (for some high precision time projects).

Luben Christov

Re: Time accuracy in Salvo

PostPosted: Sat Nov 25, 2000 12:57 pm
by Salvo Tech Support
The accuracy of the timer has two components -- that of the system tick counter, and that of time-based Salvo task services (e.g. OS_Delay()).

1. The accuracy of the system tick counter is dependent on your interrupt service routine (ISR). Since the system timer can be read via OSGetTicks() from anywhere (not just from inside a task), it's up to you, the user, to provide an ISR with as little jitter as possible to call OSTimer().

Your (user) code might look something like this on a PIC16C77:

void interrupt IntVector(void)
if ( TMR2IF && TMR2IE )
TMR2IF = 0;

The jitter of this ISR will depend primarily on the longest time that interrupts are disabled. For example, assuming that Salvo disables interrupts longer than any other part of your program, then a Salvo application with a couple of tasks might disable interrupts for a maximum of 120 cycles. On a 4MHz PIC, that means 120us, which means that the accuracy of the system tick counter will vary <1.5% from 10ms.

2. Now we look at what happens with OS_Delay(). If we have:

void Task7 (void)
for (;;)

which means we want a 10ms delay in Task7(), then there are two extreme cases: 1) OS_Delay(1) happens just before the timer interrupt -- then the delay will be very short, say, only 1ms; or 2) OS_Delay(1) happens just after the timer interrupt, in which case the delay will be approximately 10ms. Therefore task delays have an inherent accuracy of +0, -1 timer ticks.

Also, keep in mind that even after the delay in Task7() above expires, the task will not run again until it is the highest-priority eligible task -- it may be blocked by other, higher-priority tasks, which will increase the delay.

Chapter 6 FAQ of the User Manual contains additional information on the Timer.

[This message has been edited by Salvo Tech Support (edited November 25, 2000).]