Changes
PS2Mouse
,The main component on the board is the PIC16F84A. This is a small micro-processor which is pretty much dumb without some firmware to tell it what to do, I will go further into detail about the firmware below. The processor is running at 4 MHz, so the low cost version is all that’s required (there’s a slightly more expensive version which can go up to 20Mhz which would also work). I have used a 4 MHz resonator to save space, but you can also use a 4 MHz Crystal with two 22pf capacitors if you prefer . The other chip seen above is the 74LS240. This is a TTL buffer chip which is triggered by the CPC each time the Amstrad polls the joystick port, this eases the µPs job, because it doesn’t need to constantly watch what the CPCs up to. The two transistors are used to trigger the Scroll-wheel inputs. The rest of the circuit is just the usual smoothing capacitors (to remove glitches in the 5V supply and a few pull-up resistors to ensure a clean switch between Logic 0 and 1 signals. Note that because the layout is single sided, I was forced to use some wire bridges in the design, don't forget to add these, two of them are hidden under IC1 and IC2.
The PIC has two configurable ports RA and RB. In this circuit RB , which has 8 pins, is configured as all outputs, seven of them are used to control the signals to the CPC(four directions and three buttons), while the eight pin controls the LED. RA has only 5 pins, but it is a little more complicated, the first two pins are connected to the Clock and Data line of the mouse port, these change direction permanently from inputs to outputs, depending on which way the communications are going (yes, the mouse needs to get info too). The next two are always outputs and control the scroll wheel signals to the CPC. The last pin is an input connected to one of the small red dip-switches, which can be used to make a setting in the PIC, but more on that later.
== Parts List ==
As I mentioned above, one of my priorities is always to keep the price as low as possible, and according to my local supplier, the cost of the entire board should come in at under 8€7€. Here’s the Parts list and their approximate prices:
{|{{Prettytable|width: 700px; font-size: 2em;}}
|''Component''||''Quantity''||''Price''||''Total''
|-
|PIC16F84A-04P||1||2.4040€||2.4040€
|-
|4 MHz Ceramic Resonator||1||0.1010€||0.1010€
|-
|74LS240||1||0.2727€||0.2727€
|-
|2N3904||2||0.0404€||0.0808€
|-
|100µf 16V Electrolytic Capacitor||1||0.0404€||0.0404€
|-
|100nf Ceramic Capacitor||1||0.0303€||0.0303€
|-
|10K 1/4W Resistor||3||0.0505€||0.1515€
|-
|4K7 1/4W Resistor||3||0.0505€||0.1515€
|-
|470ohm 1/4W Resistor||1||0.0505€||0.0505€
|-
|3mm LED Green||1||0.0707€||0.0707€
|-
|18 Pole IC Socket||1||0.0404€||0.0404€
|-
|20 Pole IC Socket||1||0.0404€||0.0404€
|-
|9 Pole D-Sub Connector 90°||1||0.2424€||0.2424€
|-
|6 Pole Mini DIN Socket||1||0.5353€||0.5353€
|-
|2 Pole DIP Switch||1||0.2323€||0.2323€
|-
|5V Power Socket||1||0.1212€||0.1212€
|-
|5V Power Plug||1||0.5858€||0.5858€
|-
|160x100x1.5mm 35µ Single Sided photo-resist PCB||1||1.7070€||1.7070€|-|||||||6.82€
|-
|}
== The Firmware ==
The firmware is the clever bit, it is written in PIC assembler. Its more or less a PS/2 driver with a little bit added to convert every movement into signals the Amstrad can work with, its first job is to get the mouse to life, it sends the required initialisation sequence and sets up some variables available in the mouse. Among other things, I have slightly de-sensitised the mouse, so that a single twitch doesn’t send the arrow shooting across the screen. As well as this, it checks automatically recognises whether the mouse has a scroll wheel and turns it on if it does. After that, it just continuously asks the mouse if it has moved and collects the data the mouse sends back, this is then converted into the corresponding up/down/left/right and fire inputs that the CPC needs. I have also added plug and play detection, so if the mouse is unplugged at any time, the PIC recognises this and re-initialises the mouse when it has been re-connected. This also means that is is possible to swap between different mice (even between PS/2 and USB) during operation, without a re-start. The driver is purely a PS/2 driver, this means that even if a USB mouse is connected, it is being forced into PS/2 mode, so if the mouse does not support the PS/2 protocol it will not work with this device, but luckily all standard USB mice seem to still support PS/2. I haven’t published the source code here, but if anyone is interested, I may be willing to share it for educational purposes.
== Installing the Firmware ==
I have supplied a pre-compiled HEX file, so you don’t have to worry about installing additional assemblers or having to compile things yourself. You will however need to get the program onto the chip. If you don’t know how to program a PIC, I would suggest you do some research on the JDM programmer, an even smaller PCB that allows you to program the chip through an RS232 port using freeware software such as PikLab if you’re a Linux user or ICProg if windows is your preferred PC OS. A quick warning: I'm told that the JDM doesn't work on Laptop Com-ports because they don't supply the required 12V, so keep this in mind if you build one. The total price to build a JDM programmer should be under 2€.
The Oscillator and Fuse settings in ICProg or PikLab should be: Oscillator = XT, WDT = Unchecked (off), PWRT = Checked (On) and CP = Unchecked (Off). Make sure these are set properly before programming the PIC, otherwise your mouse adapter won't work.
== Construction Tips ==
As with the original AMX Mouse, the only connections needed to the CPC are through the joystick port and to the 5V supply. I have kept the PCB size to a minimum, to allow the board to be connected directly to the joystick port without getting in the way too much or tearing the connector off the side. You may choose an alternative layout to mine, but remember that if it is too large, it may damage the joystick port and would be better with a fly-lead connection.
The board presented here measures just 38mm x 60mm and should cause absolutely no stress to the CPCs connector. As well as that, remember that there are connectors left and right of the joystick port that you might want to use simultaneously, the layout here has been designed to keep both the sound socket and tape port free.
A note to beginners: When soldering the parts to the board, always solder the most heat resistant parts first and leave the sensitive ones to last, this avoids destroying a successfully soldered transistor while trying to solder a resistor that’s right beside it. Also, although you may notice that I have soldered the 74LS240 into place, I wouldn’t advise beginners to try this, you will destroy it. Splash out on the extra 7 4 cents it costs for a suitable socket. If you’re an absolute beginner, there are even sockets available for transistors, but the spacing on this layout probably isn’t correct for them. Also remember that there are wire bridges under each of the ICs! These are really difficult to assemble, if the socket is there alreadysoldered into place!
The 9 way Sub-D connector used usually has two small bolts protruding left and right of the connector, if you remove these, the metal surround will fall off. I used some superglue to re-attach the metal part. It will work without the metal surround, but this will cause the circuit to bend the CPCs joystick pins over time, so I would recommend you do the same. I also added to two M3 screws to hold the Sub-D connector to the PCB, this takes the stress off the pins below the connector, which could otherwise develop cracks in the solder over time as well. If you intend only using USB mice with the device, it may make more sense to use a USB socket instead of the PS/2 socket plus adapter. I may add the layout for this at a later stage if requested.
== Using The Mouse ==
There are two switches on the PCB, the inner one (beside the power socket), allows should in most cases be left in the user to choose whether OFF position. This is the Auto-detect position. The firmware will auto-detect which type of mouse is connected and initialise it as required, if however you have a scroll mouse which is not being used recognised correctly (Error lamp flashes or not. In the incorrect output), switching this switch ON position will tell the PIC will try not to initialise auto-detect and to assume a scroll wheel type 00 mouse, if the (standard mouse has with no scroll wheel an error will occur. In or extra buttons) and may allow you to continue using the OFF position a non scroll-wheel mouse will be assumed, . The position of this setting switch should work with all micebe chosen before power is applied. In some cases, even if they although you have a chosen auto-detect, the PIC may recognise that the mouse is incompatible and dis-enable the scroll wheelalthough one is present, but the mouse should however continue to work as a non-scroll function will be ignoredwheel mouse. This The second switch needs to be set before power is appliedfor turning the scroll wheel signals on and off. The second Switching this switch ON allows you the PIC to pass the scroll wheel movements on to the CPC, when both switches are . If a correctly recognised scroll wheel mouse is connected and this switch in ON, movement to the scroll-wheel will cause a “5” (Joy2 UP) for each roll upwards and a “6” (Joy2 DOWN) for each scroll downwards, this may have negative effects with software which has assigned these characters to other functions, so for this reason I chose to include the switch allows you option to block the messages, this it. This switch can be used at any time without resetting.
[[Image:PS2Mouse_PS2.png|360px|centre]]
== Testing The Mouse ==
In BasicBASIC, moving the mouse should produce the arrows usually seen when a joystick is connected. Pressing the left button will produce an X and the right button produces a Z. The centre button will not show any visual feedback in Basic, but can be sensed using the Inkey(78) command.
== Compatibility ==
Like I mentioned above, I’ve never seen an AMX mouse, so I don’t know exactly how they react to movement, how fast they were or how they “felt”. Technically speaking, the mouse adapter described here is fully AMX compatible and works perfectly with AMX compatible packages. I have tuned the feel of the mouse to closely resemble a PC mouse, but if you build this and find that it’s not quite the “AMX feel”, let me know and I might be able to tune it back to the 80s. And remember, if you are used to only using a PC mouse, don't expect an 8-Bit mouse to have the same lightening response time, moving the mouse really fast will not have the same result as on a PC, the Amstrad can only read the Joystick port at a certain rate, so moving the mouse slower will give a much smoother and accurate result. The adapter should work with any PS/2 compatible mouse and almost any USB mouse using a USB to PS/2 adapter plug. If you have a fancy 28 Button Star-Fighter special edition all singing and dancing cyber mouse, don't expect anything more than the basic movements to work.
[[Image:PS2Mouse_USB.png|360px|centre]]
[[File:PS2Mouse_Components.pdf]] - PCB Component Layout
[[File:PS2Mouse_V09CPC_PS2_Mouse_V10.HEX]] - Firmware V0V1.90
== Further Info ==
If you have any further questions regarding this project, please contact me through the Wiki Forum.
Bryce.