[fpc-pascal] Microsecond Delay Suggestions?

James Richters james at productionautomation.net
Wed Jul 27 00:13:06 CEST 2016

Thank You I found the sleep procedure....  Thank you for explaining that it
was looking for a pointer, that was helpful.  A little cutting and pasting
and now I have 3 more ways to sleep... Sleep_S will probably be sufficient
and is the most flexible, because if you have 1,000,000,000 seconds you
don't need precision down to 100nS.. but you have it anyway, you could
specify 1000000000.0000001 seconds and it would work... it comes out to
10000000000000001 intervals... I'm not going to wait over 31 years to test
it though :)    

Thanks for the help everyone, now I can adjust my delay from 36uS for
baudrates of 250000 all the way to 30mS for a baudrate of 300.   I know
sleep isn't exact, it's more of a minimum and then you need to also wait for
the processor to get back to you, but I think it will be close enough
without excessive delays.

I posted it on github if anyone happens across this doing a search they can
find it here:

>You need to declare a LargeInteger and pass the pointer to it to
NtDelayExecution(). LargeInteger itself is declared as a case-record 
>consisting of two 32-bit values (LowPart and HighPart) and a 64-bit value
(QuadPart). Best is you assign your value to QuadPart, as
> that sets the record in one go.
>Oh and I forgot to mention that you need to use a negative value for
relative sleeps (otherwise you'll wait until that time from the 
>system start on has passed, so "1" would be a no-op basically ;) )

>For an example see the implementation of Sleep in the SysUtils unit of the
NativeNT target: rtl/nativent/sysutils.pp (near the end of the file)


More information about the fpc-pascal mailing list