🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.nativeapi.win32
7 messages
7 total messages Started by Charles Hacker Wed, 06 Aug 2008 22:29
High Priority Code Segment
#36
Author: Charles Hacker
Date: Wed, 06 Aug 2008 22:29
19 lines
1508 bytes
Hi there,

I am updating an old Win98 app, that is used to control a Servo-Motor.
The old Win98 program utilised machine code, with tempoary disabiling
interupts, to get an exact as possible 1ms pulse output.
(i.e. with interupts disabled, Windows did not interfer with pulse
width).

I am now updating the app (to WinXP using Delphi 5, but also have Delphi
7 if needed).
The 'CLI' and 'STI' disable/enable interrupts (obviously) does NOT work
in WinXP.

So I am wondering is there any way of 'increasing priority' of the code
segment (during the 1ms pulse) to limit Windows interrupting the code,
and thus varing the pulse output width?

-- 
Charles Hacker
Re: High Priority Code Segment
#37
Author: Roger Lascelles
Date: Wed, 06 Aug 2008 23:33
27 lines
2240 bytes
"Charles Hacker" <reply.to@borland.newsgroups> wrote in message 
news:489A25D4.BE924FDC@borland.newsgroups...
> Hi there,
>
> I am updating an old Win98 app, that is used to control a Servo-Motor.
> The old Win98 program utilised machine code, with tempoary disabiling
> interupts, to get an exact as possible 1ms pulse output.
> (i.e. with interupts disabled, Windows did not interfer with pulse
> width).
>
> I am now updating the app (to WinXP using Delphi 5, but also have Delphi
> 7 if needed).
> The 'CLI' and 'STI' disable/enable interrupts (obviously) does NOT work
> in WinXP.
>
> So I am wondering is there any way of 'increasing priority' of the code
> segment (during the 1ms pulse) to limit Windows interrupting the code,
> and thus varing the pulse output width?

I recommend you don't  do this. A small microcontroller on a USB or COM port 
will do the job perfectly and will work on any PC.

While you may get some code to mostly work on one particular PC, this is 
never going to be solid.  A desktop OS like Windows is designed on the basis 
that 1ms is miniscule - which is true in terms of human perception.

Roger Lascelles 
Re: High Priority Code Segment
#38
Author: Charles Hacker
Date: Thu, 07 Aug 2008 03:52
24 lines
1872 bytes
Roger Lascelles wrote:
> 
> I recommend you don't  do this. A small microcontroller on a USB or COM port
> will do the job perfectly and will work on any PC.

I realise this, and for a dedicated system I would certainly build a
seperate controller.

However, this is an "Educational Task", to get students to develop a
"Real-Life" task to control an external device.
(I am a University lecturer, at Griffith University, Qld Australia).

The control will not be perfect, and will not necessarily be the way to
go, but it is a task that is possible for students to do.

But in anycase, I was just wondering if there is any way to 'improve'
the response (though it may never be perfect).

I noticed the 'SetPriorityClass' command, and it has 'Real_Time' Class.
So anyone know if that is a good way to go?
Any better (or other) suggestions?

-- 
Charles Hacker
Re: High Priority Code Segment
#39
Author: DJSox
Date: Thu, 07 Aug 2008 04:10
35 lines
2422 bytes
If your machine has is multiprocessor then there is nothing wrong with doing 
your timing in a separate thread with a very high, even real-time priority. 
If you have only a single processor, then you will have issues with starving 
other threads and apps. But in any case you can adjust the priority of the 
thread to a higher value.

Dan

"Charles Hacker" <reply.to@borland.newsgroups> wrote in message 
news:489A7184.365DE8E@borland.newsgroups...
> Roger Lascelles wrote:
>>
>> I recommend you don't  do this. A small microcontroller on a USB or COM 
>> port
>> will do the job perfectly and will work on any PC.
>
> I realise this, and for a dedicated system I would certainly build a
> seperate controller.
>
> However, this is an "Educational Task", to get students to develop a
> "Real-Life" task to control an external device.
> (I am a University lecturer, at Griffith University, Qld Australia).
>
> The control will not be perfect, and will not necessarily be the way to
> go, but it is a task that is possible for students to do.
>
> But in anycase, I was just wondering if there is any way to 'improve'
> the response (though it may never be perfect).
>
> I noticed the 'SetPriorityClass' command, and it has 'Real_Time' Class.
> So anyone know if that is a good way to go?
> Any better (or other) suggestions?
>
> -- 
> Charles Hacker 
Re: High Priority Code Segment
#40
Author: Nobody
Date: Thu, 07 Aug 2008 04:44
27 lines
1745 bytes
Charles,

> So I am wondering is there any way of 'increasing priority' of the code
> segment (during the 1ms pulse) to limit Windows interrupting the code,
> and thus varing the pulse output width?

This is a good place to start...

http://msdn.microsoft.com/en-us/library/ms685100.aspx


   pc := GetPriorityClass( GetCurrentProcess );
   try
     tp := GetThreadPriority( GetCurrentThread );
     try
       SetPriorityClass( GetCurrentProcess, HIGH_PRIORITY_CLASS );
       SetThreadPriority( GetCurrentThread, THREAD_PRIORITY_HIGHEST );
       // do your thing here
     finally
       SetThreadPriority( GetCurrentThread, tp );
     end;
   finally
     SetPriorityClass( GetCurrentProcess, pc );
   end;


Good luck, Brian
Re: High Priority Code Segment
#41
Author: AlexB
Date: Thu, 07 Aug 2008 05:38
9 lines
1215 bytes
Nobody wrote:

> SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_HIGHEST);

PRIORITY_HIGHEST had no good effect for me (OS steals the time).
PRIORITY_TIME_CRITICAL was much better (of course for short time
intervals).
-- 
Alex
Re: High Priority Code Segment
#43
Author: Martin James
Date: Thu, 07 Aug 2008 06:19
33 lines
2348 bytes
"Charles Hacker" <reply.to@borland.newsgroups> wrote in message 
news:489A25D4.BE924FDC@borland.newsgroups...
> Hi there,
>
> I am updating an old Win98 app, that is used to control a Servo-Motor.
> The old Win98 program utilised machine code, with tempoary disabiling
> interupts, to get an exact as possible 1ms pulse output.
> (i.e. with interupts disabled, Windows did not interfer with pulse
> width).
>
> I am now updating the app (to WinXP using Delphi 5, but also have Delphi
> 7 if needed).
> The 'CLI' and 'STI' disable/enable interrupts (obviously) does NOT work
> in WinXP.
>
> So I am wondering is there any way of 'increasing priority' of the code
> segment (during the 1ms pulse) to limit Windows interrupting the code,
> and thus varing the pulse output width?
>

There are some problems with this.  A page-fault interrupt, for example, 
must run to allow the required code to be loaded from disk.  To get round 
this, you would need to make the code pages/s that contain the high-priority 
code as non-paged.  You really need a driver to attempt this sort of stuff 
on Windows and, even then, it is likely to be interrupted by higher-priority 
drivers.  IMHO, you were lucky to get your stuff to work on W98, never mind 
'real' OS like W2k/XP.

As others have said - Windows is not a real-time OS.

Rgds,
Martin
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads