Shop OBEX P1 Docs P2 Docs Learn Events
Interfacing with PS/2 controller: Shift or Serial? — Parallax Forums

Interfacing with PS/2 controller: Shift or Serial?

DlwigwamDlwigwam Posts: 6
edited 2013-05-15 16:19 in BASIC Stamp
What is the difference between SHIFTIN/SHIFTOUT and SERIN/SEROUT? Which would be better for interfacing with a PS/2 mouse controller (e.g., the EM84510, link below)?



http://www.datasheetcatalog.org/datasheets/120/238986_DS.pdf

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-05-11 15:01
    SERIN / SEROUT use asynchronous serial I/O using either one (bidirectional) or two (one input and one output) I/O lines. There's no clock signal since the clock speed is known and the clock timing is set by the falling edge of the first (start) bit which is always zero and the idle state of the signal line is one.

    SHIFTIN / SHIFTOUT is a clocked (synchronous) serial I/O method using a clock line and either one bidirectional data line or an input and an output line. It looks like your PS/2 controller works with a clocked signal which otherwise looks similar to the format of asynchronous serial I/O. It looks like your PS/2 controller needs the clock, so you'd have to use the SHIFTIN / SHIFTOUT and maybe fiddle with the clock and data line at other times with INPUT / HIGH / LOW. Frankly, I'd look for some simpler mouse controller. You could even use a Propeller for this since there is already code in the Object Exchange for working with a PS/2 mouse (and keyboard for that matter) and the Propeller could easily talk to a Stamp.

    The Wikipedia has good articles on both asynchronous serial I/O and clocked serial I/O (SPI for example).
  • DlwigwamDlwigwam Posts: 6
    edited 2013-05-12 11:14
    Thank you Mike, now I see the difference. I am exploring ways to get feedback control for my Boe Bot's servo motors, and the encoders from an old ball mouse were the first thing that came to mind. Maybe the scroll wheel sensor will be an easier route.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-05-12 11:21
    AWC makes a variety of peripheral microcontrollers for use with the Basic Stamps. Here's one that connects to a PS/2 mouse and is straightforward to use with a Stamp. They do make other interfaces as well.
  • DlwigwamDlwigwam Posts: 6
    edited 2013-05-13 10:23
    I found a related discussion for PicBasic microcontrollers, with a well developed code in a similar language (link below). So, to use this for feedback loop control, I could ping the PS/2 IC for position after sending PULSOUT to my servomotors and use the data to update the next pulsewidth.

    It sounds like the CLK signal tends to originate from the PS2 IC, possibly waiting until there is a signal from the encoders or buttons (which I'll bypass). So I can use the onset of a LOW signal to initiate SHIFTIN. The referenced code has some interesting syntax that I might borrow:



    FOR A = 1 to 8
    loop1: IF clock = 1 then loop1
    Key_data.0 = dataline
    Key_data = Key_data *2 ; Shift once to left
    loop2: IF clock = 0 then loop2
    Next A






    Link: http://www.picbasic.co.uk/forum/archive/index.php/t-2736.html
  • Mike GreenMike Green Posts: 23,101
    edited 2013-05-13 13:52
    Even though they look similar, PICBASIC is only superficially the same as Parallax's Basic, particularly with regards to I/O. The PICBASIC examples generally won't work with a Basic Stamp.
  • DlwigwamDlwigwam Posts: 6
    edited 2013-05-15 16:19
    Today I wired the PS/2 to a BS2, and used the following code to read results. I haven't tried sending anything to the board yet through SHIFTOUT, but that's next.
    ' {$STAMP BS2}
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    digbits VAR Word
    dataPin PIN 13
    CLK     PIN 12
    
    
    DO
      SHIFTIN dataPin,CLK,LSBPOST,[digbits\24]
      DEBUG CLS
      DEBUG HEX digbits
      PAUSE 500
    LOOP
    


    The hexcode result displayed by the DEBUG command is FF00, which looks to be a code for RESET. The chip is supposed to echo FA upon receiving most commands, but since I'm not sending any commands, I believe the FF00 is OK.

    The next step is to set the EM84510 to remote mode, where it sends position and other data upon a signal from CLK.
Sign In or Register to comment.