From: JTKIRK@urp.edu.pe
Newsgroups: comp.sys.atari.8bit
Subject: ATARI controllers notes
Date: Mon, 18 Mar 96 14:36:40 -0800

These are my revised notes on different types of ATARI controllers.
Thanks to Ivo van Poorten for pointing out a silly mistake I had made.
I finally took the time to determine the circuital diagram of the STM1 mouse.
I'd have liked to add also the ATARI Light Pen, but unfortunately my nephews
have thrown it away, although I could rescue the ATARIGRAPHICS cartridge.

Joysticks
---------

     circuital diagram                           pin assignments
     -----------------                           ---------------
                                                  ___________
    org   blk                                     \5 4 3 2 1/
     |     |                                       \9_8_7_6/
     O-----+                                       
           |    wht
           |     |                               pin wire 
           +-----O                                #  col  function
           |                                     -----------------
           +-----\                                1  wht  ^ (up)
           |     |                                2  blu  v (down)
      grn -O     +-----O- bwn                     3  grn  < (left)
                 |                                4  bwn  > (right)
                 |                                6  org  fire
                 |                               (7  red  +5V) (*)
                 O                                8  blk  GND
                 |
                blu                              (*) only used in joysticks
                                                     with autofire switch

     autofire circuit
     ----------------

                   red                    firing frequency:
                    |
         /----------+                     f=1,44/[(R1+2*R2)*C]
         |          |
         Z       /--+                     ( T=0,694*(R1+2*R2)*C )
      R1 Z    .__|__|__.
         |    |  8  4  |                  
         +----7        |                  typical values:
         |    |        3----- org
         Z    | LM 555 |                  C1=0,42 nF
      R2 Z  /-6        5----\             R1=10 K
         |  | |        |    |             R2=10 K
         +--+-2        |    = C1          C=100 nF
         |    |___1____|    |
         |        |         |            (These are the values I selected.)
         \---||---+---------/
             C    |
                 blk


Paddles
-------

     circuital diagram                           pin assignments
     -----------------                           ---------------
                                                  ___________
             pushbutton          R                \5 4 3 2 1/
               __I__        /---NNN--              \9_8_7_6/
               o   o        |    ^                 
               |   |        |    |               pin wire
     L        grn blk      yel  vio               #  col  function
    ------------------------------------         -----------------
     R        bwn blk      yel  red               3  grn  L button
                                                  4  bwn  R button
                                                  5  red  R paddle
         R=1M                                     7  yel  +5V
        (R=500K for Commodore)                    8  blk  GND
                                                  9  vio  L paddle


Keyboard controllers/Video touch pad
------------------------------------

     circuital diagram                           pin assignments
     -----------------                           ---------------
                                                  ___________
     grn  vio  wht       blu                      \5 4 3 2 1/
      |    |    |         |                        \9_8_7_6/
      +-NN-+-NN-+         |
      | R    R  |         |                      pin wire
      O---------O---------O----- bwn              #  col  function
      |         |         |                      -----------------
      |         |         |                       1  bwn  row 1
      O---------O---------O----- red              2  red  row 2
      |         |         |                       3  org  row 3
      |         |         |                       4  yel  row 4
      O---------O---------O----- org              5  grn  col 1
      |         |         |                       6  blu  col 3
      |         |         |                       7  vio  +5V
      O---------O---------O----- yel              9  wht  col 2

          R=4,7K

     Readings
     --------

     The following program appeared in COMPUTE!, 2/87, "Readers Feedback"
     section, page 30. It allows to read a keyboard controller (or video
     touch pad, since they are internally identical) connected to port 1:

     1 GRAPHICS 0
     10 DIM ROW(3),I$(13),BUTTON$(1)
     30 GOSUB 6000
     60 POSITION 2,7:PRINT "CONTROLLER # 1:";
     80 GOSUB 7000:POSITION 19,7:PRINT BUTTON$;
     120 GOTO 80
     6000 REM
     6010 POKE 54018,48:POKE 54016,255:POKE 54018,52:POKE 54016,221
     6030 ROW(0)=238:ROW(1)=221:ROW(2)=187:ROW(3)=119
     6040 I$=" 123456789*0#"
     6050 RETURN
     7000 PORT=54016
     7010 P=1:PAD=0
     7020 FOR J=0 TO 3
     7030 POKE PORT, ROW(J)
     7040 FOR I=1 TO 10:NEXT I
     7050 IF PADDLE(PAD+1)>10 THEN P=J+J+J+2:GOTO 7090
     7060 IF PADDLE(PAD)>10 THEN P=J+J+J+3:GOTO 7090
     7070 IF STRIG(0)=0 THEN P=J+J+J+4:GOTO 7090
     7080 NEXT J
     7090 BUTTON$=I$(P,P)
     7100 RETURN


STM1 Mouse
----------

     circuital diagram                           pin assignments
     -----------------                           ---------------
                                                  ___________
     (Are you nuts? It consists of                \5 4 3 2 1/
      23 resistors, 2 capacitors,                  \9_8_7_6/
      2 movement sensors and an
      LM 339N quad-comparator IC!)               pin wire
                                                  #  col  function
      Well, at least the buttons:                -----------------
                                                  1  bwn  L/R sense
         L button    R button                     2  org  L/R reference
           __I__       __I__                      3  grn  U/D sense
           o   o       o   o                      4  blu  U/D reference
           |   |       |   |                      6  yel  L button
          yel blk     wht blk                     7  red  +5V
                                                  8  blk  GND
                                                  9  wht  R button

      Well, here's the rest (at last!):
                                                 +5V (red)
      [Note: | means GND (blk)]                   |
             Y                                    +----+  
                                                  |    | +
                                              R23 Z    = C1
                                                  Z    | -
                                                  |    Y
     +----+------+--------------------+-----------+
     |    |      |                    |   org     |
     |    |      |                 6|\|3   |      |
     |    |      |     +-----+------|-\ 1  | R14  |    Values:
     |  :"|""""""|"""""|":   |      |  >---+--NN--+    -------
     |  : V __   |  _|/  :   |   +--|+/    |      | 
     |  : -  '-> |   |\  :   |   | 7|/|12  Z R16  |    R1=2,2K
     |  : |      |     | :   |   |    Y    Z      |    R2=3,3K
     |  : |      |     | :   |   |         | R17  |    R18=1,5K
     |  : |      +-----+ :   |   +---------+--NN--+    R19=2,7K
     |  : |      |       :   |             |      |
     |  : |      |       :   Z R1          Z R21  |    R3,R4,R5,R20,
     |  : |      |       :   Z             Z      |    R21,R22=270 ohms
     |  : |      |       :   |             |      |
     |  : |      |       :   Y             Y      |    R23=22 ohms
     |  : |      |       :                        |
     |  : |      |       :                bwn     |    R6,R7,R12,R14=3,3K
     |  : |      |       :         4|\     |      |
     |  : |      |     +-----+------|-\ 2  | R12  |    R8,R10,R15,R17=6,8K
     |  : |      |     | :   |      |  >---+--NN--+
     |  : V __   |  _|/  :   |   +--|+/    |      |    R9,R11,R13,R16=100K
     |  : -  '-> |   |\  :   |   | 5|/     Z R13  |
     |  : |      |     | :   |   |         Z      |    R1-22 are 1/4 W, 5%
     |  ""|""""""|"""""|""   |   |         | R15  |    R23 is 1/4 W, 10%
     |    |      +-----+     |   +---------+--NN--+
     |    |      |           |             |      |    C1,C2=47 uF, 10 V
     |    Z R3   |           Z R2          Z R22  |          electrolytic
     |    Z      |           Z             Z      |
     |    |      |           |             |      |
     |    Y      |           Y             Y      |    The dotted boxes are
     |           |                                |    supposed to be the
     +----+      |                        blu     |    optical sensors.
          |      |                 8|\     |      |
          |      |     +-----+------|-\ 14 |  R7  |
        :"|""""""|"""""|":   |      |  >---+--NN--+    LM 339N pinout:
        : V __   |  _|/  :   |   +--|+/    |      |    ---------------
        : -  '-> |   |\  :   |   | 9|/     Z R11  |           ____ ____
        : |      |     | :   |   |         Z      |          |    U    |
        : |      |     | :   |   |         | R10  |    OUT2 [|1 _____14|] OUT3
        : |      +-----+ :   |   +---------+--NN--+          |  |      |
        : |      |       :   |             |      |    OUT1 [|2 _____13|] OUT4
        : |      |       :   Z R18         Z R20  |          |  ___<_  |
        : |      |       :   Z             Z      |    V+   [|3      12|] GND
        : |      |       :   |             |      |          |  |_|_|  |
        : |      |       :   Y             Y      |    IN1- [|4      11|] IN4+
        : |      |       :                        |          |  |_|_|  |
        : |      |       :                grn     |    IN1+ [|5    _ 10|] IN4-
        : |      |       :        10|\     |      |          |  |_|_|  |
        : |      |     +-----+------|-\ 13 |  R6  |    IN2- [|6 _____ 9|] IN3+
        : |      |     | :   |      |  >---+--NN--+          |  ___/_  |
        : V __   |  _|/  :   |   +--|+/    |      |    IN2+ [|7       8|] IN3-
        : -  '-> |   |\  :   |   |11|/     Z R9   |          |_________|
        : |      |     | :   |   |         Z      |
        ""|""""""|"""""|""   |   |         |  R8  |    The numbers around the
          |      +-----+     |   +---------+--NN--+    comparators in the
          |                  |             |      |+   circuital diagram are
          Z R4               Z R19         Z R5   = C2 the corresponding pins
          Z                  Z             Z      |-   on the IC.
          |                  |             |      | 
          Y                  Y             Y      Y

     readings
     --------

     The STM1 Mouse works as an inverted trackball (which is, in fact, what
     it is). The left button corresponds to the joystick trigger; the right
     button must be read in more or less the same way as the keyboard
     controllers, I guess (I had to return the mouse I borrowed before
     finishing my analysis).

     Mouse rolling forwards (up)     Mouse rolling backwards (down)

          U/D U/D                         U/D U/D
          REF SNS                         REF SNS
          -------                         -------
            0 1                             0 0
            1 1 <-\                         1 0 <-\
            1 0   |                         1 1   |
            0 0   |                         0 1   |
            0 1 --/                         0 0 --/
            ...                             ...


     Mouse rolling left              Mouse rolling right

          L/R L/R                         L/R L/R
          REF SNS                         REF SNS
          -------                         -------
            0 1                             0 0
            1 1 <-\                         1 0 <-\
            1 0   |                         1 1   |
            0 0   |                         0 1   |
            0 1 --/                         0 0 --/
            ...                             ...

     I tried to write a resident handler which should convert the mouse
     readings into joystick values and put them into the shadow register
     for joystick 2 (remember that on the ATARI XL/XE only joysticks 0
     and 1 are in effect, and 2 & 3 just contain repeats of 0 and 1).
     Then, if you read STICK(2), you would have the translated values;
     STRIG(2) would give you the status of the right mouse button; and
     for the left button, you would still use STRIG(0). Unfortunately,
     the routine got hanged sooner or later, and I had to return the
     borrowed mouse before I could finish debugging it. Maybe I can
     borrow another and resume the task...


Light Pen
---------

     circuital diagram                           pin assignments
     -----------------                           ---------------
                                                  ___________
     Sorry, I couldn't dissect the                \5 4 3 2 1/
     light pen because it was not                  \9_8_7_6/
     mine while it was still in            
     working order, and it was lost
     later.                                      pin wire 
     What I can say is that the                   #  col  function
     circuit is different from the               -----------------
     Commodore light pens, since I                5  ???  ??? (pot B) (*)
     tried one with the ATARIGRAPHICS             6  ???  pushbutton
     cartridge and it didn't sync                 7  ???  +5V
     properly.                                    8  ???  GND
     The circuits aren't inside the               9  ???  ??? (pot A) (*)
     pen, but inside the little black
     box around the connector.                    (*) pot A, pot B probably
                                                      used for H/V sync

     Marco Antonio  Checa  Funcke
     Botoneros 270
     Lima 33
     Peru

     reachable at jtkirk@urp.edu.pe


Craig Lisowski (clisowsk@mcs.kent.edu)