Pumpkin, Inc.

Pumpkin User Forums

Fine adjustment of Timer

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

Fine adjustment of Timer

Postby luben » Sat Dec 23, 2000 8:36 am


If you want to generate the ticks exactly every 0.1s or 1 s there are 2 possible ways - to find a crystal (like 32KHz) that will produce some subtick that's 1/2 1/4 .. etc. of the desired tick rate.
The second way is to make some adjustment of the timer - putting some non zero value after it generates overflow.

void interrupt INT()
if (T0IF && T0IE)
TMR0 = adjusted_value;

in this case I short the whole cycle of the timer. So, putting some value in the timer I can adjust fine the frequency of the ticks.

Now the problem - if your interrupt latency is big the timer could generate the interrupt and until you go to interrupt service it could contain some non zero value. The solution is - to do
TMR0 += adjusted_value;
In this case your accuracy is much better.

So, my question is - is it possible to implement this construction when I use Salvo's RTOS. I mean, if I do this adjustment before OSTimer(), will this crach the Salvo's routines?

And here is an idea - you can do such fine adjustment into your OSTimer() function. It's not big deal to implement it inside of your source code. So, in salvocfg.h you could add
OSTimerAdjust value;
The value represents how many cycle will do the TMR0 before generating overflow. Inside of Salvo code it will be corrected with
real_value = 256-value;

The problem of such implementation is that every processor has different number of timers and everybody uses one or other of them with the same success.


P.S. By the way I think that you have problems with your WEB page - I received notification 3 times for one and the same reply from you. I mean your single reply generated 3 notifications. But it's not Salvo's topic - chease the guys who made the WEB page :-)

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

Re: Fine adjustment of Timer

Postby aek » Sun Dec 24, 2000 10:13 am

Hi Luben.

You can do the timer += new_value method of maintaining accurate timer ticks as you described -- we do it here, too, in test code. It will not affect Salvo's built-in timer.

We will not be adding any fine adjustments to the timer routine, because (as you pointed out) it's too target-specific.

The v2.2 timer routine is extremely short, just a few instructions, with no function calls.

So, fine-tuning should / must be done outside of OSTimer(), inside the ISR.

The reason why you received three notices, but saw only one response, is that I deleted the first two ...

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

Return to Coding

Who is online

Users browsing this forum: No registered users and 1 guest