On Mon, 7 Jun 1999, Brian Whitman wrote:
> Not sure how many palm coders we have on here, but here goes:
>
> My old timing loop was just a:
>
> EvtGetEvent(&event, 5);
> /* do stuff that should happen every 5 ms */
>
> since I wanted to do something every 5ms. So if there were no user events,
> it would 'time out' after 5ms and execute my time-based code (send out
> controllers, etc...)
You are asking for 5 100Hz ticks, or 50 milliseconds, not 5.
> But this doesn't really work. As in: it sends out controller data every so
> often, but surely not every 5ms. More like every 100ms. Someone brought up
> the fact that other system events will slow it down, since it won't always
> 'time out' at 5-- so he suggested and I implemented:
>
> ticks_per_5ms = (SysTicksPerSecond() / 1000) * 5;
As someone else pointed out, but what I will elaborate on is if these are
integers, you usually do the multiply first to retain precision, i.e.
STPS() * 5 / 1000
But that doesn't help if STPS is 100.
This leaves two possibilities, both involving high rez timing (there was
an article in handheld developers journal). Either you have to double the
clock speed to 200Hz/tick (which will have other side effects), or read
the timer directly to find the subtick (as I do with my MIDI sequencer
code, since I want 600Hz resolution).
One other possibility is to use the UART - set it to the baud rate
corresponding to 5ms/char and check when the character is transmitted (or
recieved as IrDA in loopback).