Image Map Image Map
Results 1 to 6 of 6

Thread: TRS-80 Model 3 keyboard scanning methodology?

  1. Default TRS-80 Model 3 keyboard scanning methodology?

    I'm looking to build an Adruino-based PS/2 keyboard interface for the Model 3 (allowing a PS/2 keyboard to be used on a Model 3 while you spend ages desoldering every key! )

    Anyhoo, I'm trying to understand how the mainboard polls the keyboard and how a digital port might be used to emulate a keystroke.

    From what I can see, the data lines are pulled high, and therefore when an address line is pulled low, the state of the data line reflects that and you derive the pressed key(s). Back to the Arduino side, you could use a FET to simulate a keyswitch and "press" the key based on the state of the PS/2 keyboard, but I'm wondering if there any way to avoid using 53 FETs!

    Thoughts?


    Thanks!

  2. #2
    Join Date
    Sep 2016
    Location
    Melbourne, Australia
    Posts
    530

    Default

    Its a much more complicated task than it first looks, mainly because some software scans multiple address lines at the same time.
    The Arduino should internally keep track of which keys are held down. When the keyboard address block is read from it should read which address lines are high. It then needs translate which data lines to set high based on the pressed keys and address lines.
    The Arduino is not fast enough to do all that before the CPU expects valid data on the bus, so you need to set a latch that pulls the CPU WAIT signal low when any keyboard address is read. When the Arduino has completed its processing and set the data lines to reflect the keys pressed then it should reset the latch to allow the CPU to continue and read the data lines. To prevent conflicts with the internal keyboard you will need eight 2 input OR gates on the data lines one input fed by the internal keyboard and the other by the data outputs from the Arduino. The outputs of the OR gates will need a tristate buffer that is active when any keyboard address is being read.

    If you are not planning to have the internal keyboard connected then, skip the OR gates and run the Arduino data output lines straight to the tristate inputs.

  3. Default

    First off, the idea is for it to -replace- an existing/broken/missing keyboard, not be used in parallel.

    With respect to the address lines, they are connected to a 74LS05, which is essentially an "output-only" open-collector device (the output is the inverse of the input, and is always pulled-up high).

    From what I can see, the CPU can't "read" the state of an address line, you simply have to toggle the corresponding address bit (which pulls a data line low if a key is pressed), and it's the data lines that are parsed to see which keys are being pressed.

    As you say, speed could be an issue, but an ARM-based Arduino should be easily able to keep-up with a 2MHz CPU!

    The FET idea is far simpler since it basically mimics a mechanical keyswitch, and would not need any programming with respect to the Z80, but it's far more cumbersome from a parts perspective!

    Do you know if there's a comprehensive pinout of the Model 3 keyboard connector?


    Thanks!

    P.S. STM32 chips have 5V tolerant I/O, and there's lots of support for those in the Arduino environment...

  4. #4
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    27,635
    Blog Entries
    20

    Default

    FWIW, my view of the STM32 Arduino environment is that the devkits mask much of the usefulness of the MCU in order to implement as much of the Arduino personality as possible. Better to go with native STM32 tools.

  5. #5
    Join Date
    Sep 2016
    Location
    Melbourne, Australia
    Posts
    530

    Default

    I agree with Chuck, the STM boards don't work well in the Arduino environment. Although things may have changed in the 12 months since I tried it.

    If you want to go with 53 fets have fun wiring it, personally I think an Arduino nano with 2 TTL chips is the simpler option. It requires no code changes for the Z80, its all done by the Arduino.
    The code is simple, when a keypress scan code is received, translate it to a bit in an array that has a one byte entry per address line. When you get a key release scan code clear the bit in the array.
    You set an interrupt on change for one pin connected to the select line for the keyboard memory block. When you get an interrupt simply check the input pins connected to the low order of the address bus.
    Do an OR operation of the bytes in the array for each address line that is high. Output the result to the pins connected to the data lines. The clear the wait latch and return from the interrupt.
    Most of the work is in decoding the data from the ps/2 keyboard.

  6. #6

    Default

    Quote Originally Posted by AN7000_Dude View Post
    As you say, speed could be an issue, but an ARM-based Arduino should be easily able to keep-up with a 2MHz CPU!
    When the TRS-80 wants to read the keyboard, you'll need to respond in about 2 Z-80 clock cycles, or 1 us. If your ARM chip is running at 200 MHz, that's only 200 cycles, which is not a lot of time, especially if you're programming in a high-level language.

    Do you know if there's a comprehensive pinout of the Model 3 keyboard connector?
    In the Model III technical reference manual or service manual, you can find the keyboard matrix and how it connects to pins 1-16 of connector J6. Pins 17-20 are undocumented in the schematics, but if you look at the circuit traces in the manuals it looks like on the 8709132-C board (shown in the second printing of the service manual) pins 18 and 20 go to pull-up resistors R15 and R16, and pins 17 and 19 are no connection, and on the 8709132-G board (shown in the October 1981 version of the technical reference manual), pin 17 goes to a component labeled "KANA" (presumably allowing Japanese versions of the Model III to have an extra row of keys) and pins 18-20 are NC. (I'm trying to be "comprehensive" because you asked for it, but I think you should just ignore pins 17-20.)

    If you want to use David's design, you can't just plug in to J6, you would need to also go pick up the keyboard select line and the wait input line from somewhere else on the motherboard.

    If you've really got enough speed, then you can monitor pins 1-8 of J6, and within 1 us of any changes to them, output the appropriate values to pins 9-16. That design would not require any FETs, and you could get all the connections you need through just the J6 connector.
    -Alan

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •