|
here's how I did a fine-grained delay for an IR program to mimic the remote control for my Olympus camera. I needed a precise 'mark' time between sending bursts of IR carrier, but 'systaskdelay' is too coarse because 'systicksperscond' is usually equal to 100, providing only 10 msec increments.
Unit delay;
interface
uses
PalmOS;
procedure Finedelay(delaynum:uint32);
function ticksper1m:uint32;
implementation
procedure Finedelay(delaynum:uint32);
begin
asm
move.l delaynum, d0
@countdown:
add #-1,d0
bne @countdown
end;
end;
function ticksper1m:uint32;
var startcount:uint32;
begin
StartCount:=TimGetTicks;
FineDelay(1000000);
result:=TimGetTicks-startcount;
end;
end.
'ticksper1m' counts how many 'systicks' elapse during 1000000 iterations of the simple asm loop 'Finedelay'. On a 16mhz dragonball, its about 144 ticks. On 33 mhz CLie, its about 112 or so. You'd think it's be 72 but oh well, whatever. From there you can calculate the number you'd pass to 'finedelay' for a given # of uSECs. Since 'systickspersecond' is usually=100, then one loop on my 16 mhz handspring =1.44 uSECs. Do the math from there. This works most of the time but I noticed that 1 out of about 10 IR transmissions failed to trip the camera. I fixed it by sending
the IR code four times. THere is probably some system trap or something that interrupts 'finedelay.' I'm also a newbie and still am after sweating away at this Palm stuff for over 4 years off and on, so there are probably more elegant and bulletproof solutions, but this does fine for me, maybe will help,
Russ
|