[comp.sys.amiga.programmer] A "legal" way to access a potentiometer ?

nfotis@theseas.ntua.gr (Nikolaos Fotis) (02/19/91)

Dear Netters,

[this is from a friend who's not on the USENET. I'll forward any replies to
him, and I'll make a summary of what comes in to the Net -- nfotis]

  I have tried to connect a potentiometer to the game port of my AMIGA.
The problem is, I didn't find the "legal" way to read the pot values.

  I know that you can do this with the gameport device,but when i tried to
modify a source for the joystick ,nothing worked...
  So,I found a way using some hacks in assembly, but the result wasn't very
good (when the pot had the max value,I read something like : 144 144 31 144
144 144 31 31 ....etc. I think that there is an error in timing...).
So if anyone can send to me full source code in
C and/or assembly for this ,it would be a great help... 
(Also wait for some strange applications of this....)

Thanks,
A.Kranidiotis.

-- 
Nikolaos Fotis			E-mail:
16 Esperidon St.,		UUCP:	mcsun!ariadne!theseas!nfotis
Halandri, GR - 152 32		or InterNet : nfotis@theseas.ntua.gr
Athens, GREECE			FAX: (+30 01) 77 84 578

markv@kuhub.cc.ukans.edu (02/21/91)

In article <1258@theseas.ntua.gr>, nfotis@theseas.ntua.gr (Nikolaos Fotis) writes:
> Dear Netters,
> 
> [this is from a friend who's not on the USENET. I'll forward any replies to
> him, and I'll make a summary of what comes in to the Net -- nfotis]
> 
>   I have tried to connect a potentiometer to the game port of my AMIGA.
> The problem is, I didn't find the "legal" way to read the pot values.

It exists...
 
>   I know that you can do this with the gameport device,but when i tried to
> modify a source for the joystick ,nothing worked...

The gameport.device has no support for the Proportional controllers.
You also cant' just read the pots, you have to manage them.

First, you need to allocate the pot bit for the STARTB bit in the
POTGO register via AllocPotBits().  If you using the whole game port,
you need to allocate the gameport.device via GPTC_NOCONTROLLER (sp?)
to say its allocated with a custom controller.

The Amiga POTs work via a voltage charging some capaciters.  It takes
a certain amount of time for these to charge (about 200 video lines)
before the values stabilize.  Once they stabilize, they hold their
values forever (given the same voltage level).

The best way to do it is either in a VBLANK server like this:

int interrupt VBServer(void)	/* dont need any params */
	geta4();		/* if base relative	*/
	PotVal = custom.pot1dat;	/* or pot2dat depending	*/
	WritePotgo(0xFFFF, STARTB);
	return(0L);		/* continue server chain	*/
}

This assumes Lattice C 5.04 or later.  I use geta4() because I've had
there are inconsistancies of the ability to mix __saveds, __interrupt,
and __asm.  With 5.04 or later, Lattice/SAS does a TST.L D0 on exit
which is essential for any server chains such as VBLANK.

In a task, try this:

while (whatever) {
	WaitTOF();
	WritePotgo(0xFFFF, STARTB);
	WaitTOF();
	PotVal = custom.pot1dat;	/* or pot2dat depending	*/
}

Note that this loop only reads once every other VBLANK because tasks
timings are less precise.
	
>   So,I found a way using some hacks in assembly, but the result wasn't very
> good (when the pot had the max value,I read something like : 144 144 31 144
> 144 144 31 31 ....etc. I think that there is an error in timing...).

I've also had some severe problems with jitter, so I use a running
average of the last 3 values.  The optimum pot value is supposed to be
470K, which works okay on the 1000 and most 500 and 2000s, but the
3000 seems to want even more (I dont get a full 255 value on our 3000
w/470K ohms).

> So if anyone can send to me full source code in
> C and/or assembly for this ,it would be a great help... 
> (Also wait for some strange applications of this....)
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mark Gooderum			Only...		\    Good Cheer !!!
Academic Computing Services	       ///	  \___________________________
University of Kansas		     ///  /|         __    _
Bix:	  mgooderum	      \\\  ///  /__| |\/| | | _   /_\  makes it
Bitnet:   MARKV@UKANVAX		\/\/  /    | |  | | |__| /   \ possible...
Internet: markv@kuhub.cc.ukans.edu
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

jcs@crash.cts.com (John Schultz) (02/22/91)

In <28702.27c2619a@kuhub.cc.ukans.edu> markv@kuhub.cc.ukans.edu writes:


>I've also had some severe problems with jitter, so I use a running
>average of the last 3 values.  The optimum pot value is supposed to be
>470K, which works okay on the 1000 and most 500 and 2000s, but the
>3000 seems to want even more (I dont get a full 255 value on our 3000
>w/470K ohms).

  If you want to get the full 0..255 range, you'll need about 1Meg Ohm
pots, or a couple of .22uf caps. Here's how to adapt IBM analog joysticks
and get full range. I recommend the CH Products Flight Stick. Best analog
joystick I've seen.

                   IBM->Amiga Analog Joystick Adaptor
                            with pass-through
                                   by
                              John Schultz
                            October 25, 1990

Parts:

  1 IBM analog joystick (I recommend the CH Products Flight Stick)
  1 DB-9 female
  1 DB-9 male
  1 DB-15 female
  2 .22 microfarad tantalum capacitors
  16 3-4 inch strips of appropriate gauge wire

Pinout:

            Amiga                     IBM
         DB-9 female              DB-15 female
         -----------              ------------

button 3:     1                       10
button 1:     3                        2
button 2:     4                        7
pot X   :     5                        6 (Future will be 3)
+5 Volts:     7                        1
ground  :     8                        4
pot Y   :     9                        3 (Future will be 6)

Construction:

  Wire the DB-9 female to the DB-9 male straight across. Wire the DB-15
female to the DB-9 female. On the DB-9 female, add the capacitors between
pins 5 and 8 and between pins 9 and 8 (+ on 5 and 9, - on 8).

  The code and adaptor were made originally to work with SubLogic's Jet,
but the documentation for IBM joysticks shows pins 3 and 6 reversed from
what worked properly with Jet. Future versions should reverse those pins
for compatibility with the documentation.