USB to Quadrature Mouse Adapter
- Posted by Simon Inns
- Posted on October 14, 2016
- Acorn, AVR Microcontroller, Retro Computers, USB
- No Comments.
Contents
SmallyMouse is a project that creates a USB mouse adaptor for 8-bit Acorn computers including the BBC Micro and Master series machines. SmallyMouse can emulate the two most popular user-port mice made for the BBC – the AMX mouse and the Marconi RB2 trackball (as used in the BBC Domesday project) and provides a small switch allowing the mouse emulation mode to be easily selected on-the-fly.
Update: Please note that this project has been superseded by SmallyMouse2. Please follow the link to the project for details!
Although the adapter is designed for Acorn computers, the quadrature emulation is suitable for a wide-range of machines sold during the same era (such as the Acorn Archimedes, Commodore Amiga, etc.). Before the advent of serial and PS/2 mice, nearly all mice and trackball devices worked by sending a stream of pulses from a mechanically based quadrature encoder arrangement. The host computer would simply count the pulses from the mouse and convert this into movement on the screen.
The design fits in a small case and is connected to the BBC Micro or Master by a short 20 pin ribbon cable. The USB Host supports both wired and wireless mice provided they follow the industry-standard USB HID Mouse protocol. You can see SmallyMouse in action in the following YouTube demonstration video:
Hardware
Schematic
SmallyMouse uses an AT90USB1287 microcontroller from Atmel that supports both USB device and host modes. A host-mode compatible processor is required as SmallyMouse acts as the ‘computer’ rather than the device; it supplies power and control to the USB mouse device. The following EagleCAD schematic shows the required components and connectivity:
As can be seen in the schematic, SmallyMouse consists mainly of two halfs; the USB host interface is provided to a female USB A-connector along with the required supporting components and the AVR is then connected to the Acorn user-port for communication with the 8-bit computer. 10 GPIOs are connected to the user-port IDC connector in order to make the creation of adapters (for other 8-bit machines) as simple as possible.
The design also contains a 500mA PTC which acts as a fuse to protect the Acorn computer’s user-port and power supply. The PTC will automatically cut-out if more than 500mAs is drawn from the user-port. PTCs are ‘self-resetting’ so, if the PTC is tripped, removing and reconnecting the power will reset the device.
The design also includes a switch (for selecting the emulation mode) and a JTAG header in AVR standard format for both debugging and programming the microcontroller.
PCB Design
The PCB design can be seen in the following diagram:
The PCB is designed to be made either double-sided (if you are using a PCB fabrication service) or single-sided (where the bottom-copper traces can be replaced by link wires). Tolerances are suitable for UV transfer production of the board. Full EagleCAD schematics and PCB design are provided at the end of this article.
The PCB fits in a G026N case from Kemo Electronics, you will need to cut holes in the case for the USB connector, the switch and the ribbon cable.
Note that the IDC connector, the USB socket and the header pins are mounted on the lower side of the board (i.e. inverted), this is to allow for hand-soldering (since it is not possible to solder under the devices) – therefore the device is mounted ‘upside down’ in the case.
Firmware
The SmallyMouse firmware functions by using the LUFA USB stack to communicate and control an attached USB mouse device. The USB mouse periodically sends position update reports to the host (at a rate of around 120 reports a second when the mouse is moving). This style of updating generates problems for quadrature emulation since, in a quadrature mouse, the output would be a constant flow of information with the frequency of the pulses indicating how far the mouse has moved.
SmallyMouse emulated the quadrature output using the AVR’s timers (one timer for X and another for Y) – and sends the quadrature at a variable rate depending on how fast the mouse is moving. The quadrature output is timed so the device can send as much of the movement information as possible before another USB report is received.
With the original AMX and RB2 devices it was possible to move the device faster than the host computer could detect – this would cause spurious updates with the mouse pointer seeming to bounce around the display. SmallyMouse contains a rate limiting algorithm that prevents the device from overrunning the host computer. Two defintions in the firmware control this, namely RATELIMIT and LAGLIMIT. The ratelimit sets the maximum frequency of the quadrature output generated by SmallyMouse. This prevents the device from outputting faster than the 8-bit host can count. Since there is only a limited time between USB reports, any extra position updates that cannot be sent to the host will be lost. The laglimit parameter specifies how much overrun should be allowed before updates are disregarded. By altering these two parameters it is possible to tune the quadrature output for other computers.
The firmware supports both the AMX mouse and the Marconi RB2 trackball; although these two devices were electrically identical the pin-out used to the BBC computer was not the same. The firmware uses simple GPIO reconfiguration to be able to support either pin-out as required. A toggle switch controls which pin-out is currently in use.
Conclusions
SmallyMouse is part of a larger project I am working on to recreate the BBC Domesday hardware (a BBC Computer Literacy project from 1986). The Domesday project used a Marconi RB2 trackball as the primary control device. However, the ability to replace legacy 8 and 16-bit mice with modern USB devices is potentially very useful, so I designed the firmware/hardware to be as simple as possible to modify. Since this is an open source project you are, of course, welcome to make your own, or even make them for others.
Files for download
This zip file contains the Atmel Studio 7 firmware project files for the project:
SmallyMouse_1_1_Studio_7_files
This zip file contains the EagleCAD files for the project (schematic and PCB design):
Donate to waitingforfriday.com:
If you like this site and want to help support future projects, or you just want to show appreciation for a project you built, used or enjoyed, please consider leaving a PayPal donation. It’s quick, secure and helps us to run the site and fund future projects!