Board index » delphi » Joystick is slow with INTR 15h

Joystick is slow with INTR 15h

Hello

I am writing a stepper motor control, which needs a frequency of at
least 5kHz (5000 motor steps per second) in "hand-driven" mode. You
can drive per keyboard and joystick. With keyboard there is no
problem, but the joystick is too slow. I like to know if there is a
faster code to get the position of the joystick.
The program works like this. Getting the joystick position at program
start. Save this value. Then I have a loop, which checks if the actual
joystick position is different to the saved position. If it is
different the stepper motors do one step. The Z-axis is controlled by
the joystick buttons. The move of the joystick is displayed on the
screen. (I removed this for testing, an therefore I think it is the
call of the interrupt, which makes the program slow.)
Here is some information of the code.
I am using TP 5.5 and OS is MS-DOS 5.0 . Variables are global. The
program runs in 640 x 480 points at 16 colors. Computer is 286.
VAR joy_x, joy_y, joy-status : WORD;
    register : REGISTERS;
PROCEDURE get_joystick_position;
BEGIN
        register.ah := $84;
        register.dx := 1;
        INTR($15,register);
        joy_x := register.ax;
        joy_y := register.bx;
        register.ah := $84;
        register.dx := 0;
        INTR($15,register);
        joy_status := register.ax;
END;

If you would give me a solution with assembler or inline code, please
add a comment in every line, because I never learnd this.

Thank you for reading.

Martin
--
 Martin Stahl
 e-mail: kram...@uplink.de
 http://www.user.uplink.de/krampus

 

Re:Joystick is slow with INTR 15h


JRS:  In article <38F9E3FB.83265...@uplink.de> of Sun, 16 Apr 2000
18:02:04 seen in news:comp.lang.pascal.borland, Martin Stahl

Quote
<kra...@uplink.de> wrote:
>I am writing a stepper motor control, which needs a frequency of at
>least 5kHz (5000 motor steps per second) in "hand-driven" mode. You
>can drive per keyboard and joystick. With keyboard there is no
>problem, but the joystick is too slow. I like to know if there is a
>faster code to get the position of the joystick.

If you're doing that, I feel entitled to hope that you're some sort of
physicist or electronic engineer, at least on an amateur basis.

All IIRC : a joystick is a cheap device, intended for games; ISTR that
it consists, per channel, of a variable resistor and a capacitor, and
its position is determined by using a digital threshold circuit to
detect its time constant; this takes time (not even constant time!?).

It may be worthwhile to open up the joystick, get direct access to the
resistors, and build a better circuit to measure the settings - perhaps
drive it through a constant-current diode, and measure the voltage with
an 8-bit ADC parallel-connected to the PC.  Or serial-connected; a COM
port will go quite fast, and you don't need to read every character.

--
? John Stockton, Surrey, UK. j...@merlyn.demon.co.uk / JR.Stock...@physics.org ?
 Web <URL: http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
 Correct 4-line sig. separator is as above, a line precisely "-- " (SoRFC1036)
 Do not Mail News to me.    Before a reply, quote with ">" or "> " (SoRFC1036)

Re:Joystick is slow with INTR 15h


Quote
Martin Stahl wrote:
> I like to know if there is a
> faster code to get the position of the joystick.

You can download Pascal source code for my joystick unit, which accesses
the joystick hardware directly instead of going through the BIOS (Int
15h).  It is relatively slow as is, but that is because it is general
purpose.  It is heavily commented and should be relatively easy to
modify to fit specific needs.

--
Will <wdeco...@yahoo.com>
http://www.geocities.com/SiliconValley/Pines/9447
(Please note my public e-mail address has changed)

Re:Joystick is slow with INTR 15h


Quote
Dr John Stockton wrote:

> If you're doing that, I feel entitled to hope that you're some sort of
> physicist or electronic engineer, at least on an amateur basis.

I am sorry, if I disappoint you. I am neither some sort of physicist
nor a electronic engineer. I am just a crazy man, who want to have his
own (selfmade) computer controlled machine. I am working on this for
four years and I will finish in, let me think..., in 10 or 20 years.
:-)
On this world is nearly nothing which can not be learned. ;-)

Quote
> All IIRC : a joystick is a cheap device, intended for games; ISTR that
> it consists, per channel, of a variable resistor and a capacitor, and
> its position is determined by using a digital threshold circuit to
> detect its time constant; this takes time (not even constant time!?).

.. and this is the reason why it is so slow. I understand.

Quote
> It may be worthwhile to open up the joystick, get direct access to the
> resistors, and build a better circuit to measure the settings - perhaps
> drive it through a constant-current diode, and measure the voltage with
> an 8-bit ADC parallel-connected to the PC.  Or serial-connected; a COM
> port will go quite fast, and you don't need to read every character.

Could you please tell me where I can find some informations about
that? I am especially interested in the version with the COM port.

Now I have an other question. You use much of this "short cuts" in
your postings, like IIRC or ISTR. Some of them I do not understand.
Where can I find a list of this "short cuts"?

Thank you for your time and advice.

regards

Martin
--
 Martin Stahl
 e-mail: kram...@uplink.de
 http://www.user.uplink.de/krampus

Re:Joystick is slow with INTR 15h


JRS:  In article <38FCAEE5.AA687...@uplink.de> of Tue, 18 Apr 2000
20:52:21 seen in news:comp.lang.pascal.borland, Martin Stahl

Quote
<kra...@uplink.de> wrote:
>Dr John Stockton wrote:
>> It may be worthwhile to open up the joystick, get direct access to the
>> resistors, and build a better circuit to measure the settings - perhaps
>> drive it through a constant-current diode, and measure the voltage with
>> an 8-bit ADC parallel-connected to the PC.  Or serial-connected; a COM
>> port will go quite fast, and you don't need to read every character.

>Could you please tell me where I can find some informations about
>that? I am especially interested in the version with the COM port.

>Now I have an other question. You use much of this "short cuts" in
>your postings, like IIRC or ISTR. Some of them I do not understand.
>Where can I find a list of this "short cuts"?

In TOOTKA.

From my news-use.htm :
TOOTKA (tootka = Terms One Ought To Know About) is an old list of acronyms :
<A HREF="ftp://ftp.demon.co.uk/pub/doc/general/tootka.txt">FTP demon.txt</A>,
<A HREF="http://www.orbital.co.za/tootka.htm">HTTP za.htm</A>;
try also another, vast, list at
<A HREF="http://www.astro.umd.edu/~marshall/abbrev.html">HTTP umd.edu</A>.
An online computer dictionary can be found at
<A HREF="http://wombat.doc.ic.ac.uk/">Imperial College</A> (?), London.
Or see FYI18.

To what I suggest, alas, you really do need experience of some sort in
electronics.  If I still had the facilities to build and test one, I  
might be able to describe it so that it could be copied; or if you were
experienced, you could work from such suggestions.  But as is, the
combines risk of damage or failure is too great.  Perhaps if you were to
ask in a local newsgroup, you could find someone nearby to work with?

My page pc-urls.htm has a number of general references to use of serial
& parallel ports, but the serial port link is marked as gone :-(

PC <A HREF=
"ftp://rtfm.mit.edu/pub/usenet/news.answers/pc-hardware-faq/"

Quote
>Hardware FAQ</A> - get part# for # = 1..5.

Filip's <A HREF="http://www.paranoia.com/~filipg/">PC Ports</A>
- used to be at this URL - site is changing ...

The <A HREF="ftp://ftp.phil.uni-sb.de/pub/staff/chris/The_Serial_Port">Serial
Port</A> (Gone? Where?)

"The <A HREF="http://www.lvr.com/ibmlpt.txt">document</A> (FNF)
contains a full description of using the parallel port this way," (Gone?)

The <A HREF=
"http://www.strangecreations.com/strange/library/hardware/parallel.txt">
Parallel Port</A> (FNF).
There may be another parallel port FAQ?

Kris Heidenstrom's Parallel Port
<A HREF=
"http://home.clear.net.nz/pages/kheidens/ppmfaq/khppmfaq.htm">mini-FAQ</A>.

Jan Axelson's <A HREF="http://www.lvr.com/">Lakeview Research</A> :
<I>"The source for information and tools relating to parallel ports,
RS-232 and RS-485 serial communications, 8052-Basic microcontrollers,
and making printed-circuit boards."</I>

"Interfacing to the IBM-PC Parallel Printer Port", Ian Harries,
<A HREF="http://www.doc.ic.ac.uk/~ih/doc/par/">IC</A> : links and
details.

Here's a thought : the standard joystick drivers are likely to have been
written long ago, for slow PCs.  IF the joystick circuit is as I think,
and if you were able to reduce the capacitor, you might be able to run
it faster on a modern machine with RDTSC.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 Web <URL: http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
 Proper 4-line sig. separator is as above, a line exactly "-- " (SonOfRFC1036)
 Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

Re:Joystick is slow with INTR 15h


Thank you very much for your list of links. I will take a look at all
this information. I think it will bring me a big step forward.

regards

Martin
--
 Martin Stahl
 e-mail: kram...@uplink.de
 http://www.user.uplink.de/krampus

Re:Joystick is slow with INTR 15h


Quote
Martin Stahl <kra...@uplink.de> wrote in message

news:38FCAEE5.AA68794A@uplink.de...

Quote
> Dr John Stockton wrote:

> > If you're doing that, I feel entitled to hope that you're some sort of
> > physicist or electronic engineer, at least on an amateur basis.

> I am sorry, if I disappoint you. I am neither some sort of physicist
> nor a electronic engineer. I am just a crazy man, who want to have his
> own (selfmade) computer controlled machine. I am working on this for
> four years and I will finish in, let me think..., in 10 or 20 years.
> :-)

Sounds like "electronic engineer ... on an amateur basis" to me :)

Quote
>...
> > It may be worthwhile to open up the joystick, get direct access to the
> > resistors, and build a better circuit to measure the settings - perhaps
> > drive it through a constant-current diode, and measure the voltage with
> > an 8-bit ADC parallel-connected to the PC.  Or serial-connected; a COM
> > port will go quite fast, and you don't need to read every character.

> Could you please tell me where I can find some informations about
> that? I am especially interested in the version with the COM port.

You could try looking up some microcontroller ICs, there are lots of
different types so see what your local shop or Conrad or whatever have in
their catalogue. And what you can get data sheets for off the web :) Maybe
you could get something related to the MC68HC705 that would have both a
serial port and an ADC on-board, to make it easier.
 http://www.mot-sps.com/products/ follow "Microcontrollers").

Then your only problem is how to program it. I messed around with a 68705 a
few years back and it had software in ROM for programming the onboard EPROM,
so you don't necessarily need to have an EPROM programmer (depends on the
chip).

If a chip with built-in ADC is too expensive or hard to find in your local
shops, there are versions with a serial port at least, which you could use
as an interface to an ADC. A quick web search threw up
http://www.kullen.rwth-aachen.de/users/dschlich/esp95/index.html as an
example (although you might want a faster ADC: 100s conversion time? Must be
a typo.)

(You'll probably need some sort of buffer so you get reasonable RS232
voltages but there's chips for that too, e.g. MAX220-MAX249 from Maxim)

FP

Re:Joystick is slow with INTR 15h


Quote
Martin Stahl wrote:
> I am writing a stepper motor control, which needs a frequency of at
> least 5kHz (5000 motor steps per second) in "hand-driven" mode. You
> can drive per keyboard and joystick. With keyboard there is no
> problem, but the joystick is too slow.

OK, now I know why the joystick is slow and how I can solve this
problem. Thank you all for your help.
But before I go to library and get tons of books, I ask myself, if the
mouse works faster. If the mouse works faster, I could reconstruct a
trackball. (Because I am a better craftsman than a programmer ;-) )
This construction could have a bar which is hold in the middle by
spring. Then one can use the trackball like a joystick.
The program could look like this:
- Set mouse position to definite value.
- Register the change of mouse position.
- Evaluate the direction.
- While mouse position is different to definite value turn motor (X/Y
axis)
- While mouse button is pressed turn motor (Z axis)
- When mouse position is definite value (+/- tolerance) stop motor.
Writing such a program should be no problem for me. The only thing is
that I do not know about the speed of mouse compared with the
joystick.
What do you think about this idea?
Do not call me crazy, I know this already :-)

Thank you for reading.

Martin
--
 Martin Stahl
 e-mail: kram...@uplink.de
 http://www.user.uplink.de/krampus

Re:Joystick is slow with INTR 15h


JRS:  In article <38FF411E.E920A...@uplink.de> of Thu, 20 Apr 2000
19:40:47 seen in news:comp.lang.pascal.borland, Martin Stahl

Quote
<kram...@uplink.de> wrote:
>OK, now I know why the joystick is slow and how I can solve this
>problem. Thank you all for your help.
>But before I go to library and get tons of books, I ask myself, if the
>mouse works faster. If the mouse works faster, I could reconstruct a
>trackball. (Because I am a better craftsman than a programmer ;-) )
>This construction could have a bar which is hold in the middle by
>spring. Then one can use the trackball like a joystick.

Some mice work differently.

But many mice have two channels; for each, the ball bears on a wheel
which turns a slotted disc within the jaws of an opto-detector.
Assuming that you are willing to risk the lives of a few mice, you could
dismantle the mechanics entirely, and craft another means of moving
suitable slots within the jaws.  Note that the opto must detect
direction, so must have two sensors per channel.  It's probably easier
to re-do the mechanics completely.  It may not be necessary to match the
slots in size.  They need not, I think, be actual holes, just something
alternately transparent & opaque; you could make your own by [computer-]
drawing and photographic reduction.

ISTM that a mouse, plus standard drivers, works fast enough to keep up
with a human being; and that you perhaps want the motor to do what would
be necessary to drive a mechanical mouse in the same way as the screen
pointer behaves.?

Quote
>Do not call me crazy, I know this already :-)

You're crazy enough for you to have noticed; but not so crazy as to
disbelieve it!

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.

Re:Joystick is slow with INTR 15h


Quote
Martin Stahl wrote:
> But before I go to library and get tons of books, I ask myself, if the
> mouse works faster. If the mouse works faster, I could reconstruct a
> trackball. (Because I am a better craftsman than a programmer ;-) )

[snipped]
I wrote a little program to test the speed of the mouse and the
joystick. I must admit that the method of measuring may be inaccurate
(because I do not know ho much time the GETTIME() needs), but it is
good for me. I found out, that the mouse is about 150 times faster
than the joystick. The program is counting how often I can call
interrupt $15 respectively $33. The result is: Joystick about 20 times
and mouse about 3000 times.
With this result I calculated a frequency of the stepper motor by
about 2000 steps/second. Motor has 200 steps/turn. Spindle gradient is
10 mm. That makes a axis speed of 100 mm/second. And that should be
fast enough.
Now my problem is solved.

I want to say "Thank you very much" for all your help.

Martin
--
 Martin Stahl
 e-mail: kram...@uplink.de
 http://www.user.uplink.de/krampus

Other Threads