COMMO PAD

HOME   CONTACT
downloads

What is the commo pad?

The commo pad is a device that is intended to be used on a Commodore 64 computer. It is to be connected to the joystick port, it can act like a KoalaPad, joystick or 1351 mouse. But it can also be connected to the USB port of a PC and act like a regular 2-button and scrollwheel mouse.

The commo pad uses a 4 wire resistive touchscreen. This means that it can only detect one object on the pad AND it requires a significant force for accurate control. However, generating enough force is no a problem when using a stylus. A blunt plastic object incapable of making scratches on the surface. But in case of an emergency you can always use the backof an ordinary plastic ballpointpen (never use the tip of a ball point, you'll damage the device in multiple ways).




The commo pad has 3 button. When connected to a C64 these buttons can be used to configure the device to one of the 3 modes. Holds the button for the desired mode while turning your C64 on.
By pressing the top button while switching the C64 on, the koala mode is selected (mode 1).
By pressing the middle button while switching the C64 on, the joystick mode is selected (mode 2).
By pressing the bottom button while switching the C64 on, the 1351 mouse mode is selected (mode-3).
After changing the mode setting of the device, this will be automatically stored, so the next time you turn your C64 on, the commo pad will operate in the mode you selected earlier. In order to indicate the mode used, the commo pad will beep 1, 2 or 3 times depending it is in mode 1, 2 or 3. This is all indicated on the background of the touch area.

The touch area has a circle in the middle, this is to be used for the joystick mode. Although the joystick mode uses relative position changes, it may help to use the absolute center of the touch pad. This way you have an indication on how far you need your stylus to move in order to generate a joystick up/down action. However, the joystick mode is more of a gimmick that that it has practical value. Because when playing joystick games, you really want something to limit your movements. This is something that a touchpad cannot offer. Although a cardboard template could be made to limit the movements on the touch pad, it will remain difficult to return the stylus to the center of the movement circle.

The device automatically detects whether it should be in USB mode or in C64 mode. Simply by sensing the power source.
When it is connected to the USB port, it will act like an ordinary PC mouse



When the 5V of the joystick port is detected, the device goes into the C64 mode and will act like one of the 3 possible devices (KoalaPad, joystick, 1351 mouse)




How did I make the frame?

3D printing is nice... but nothing is right the first time and if you do not know exactly what you need then 3D printing can be a waste of time (especially considering the size of the frame). Therefore, sometimes it's easier to take some scrap pieces of wood, MDF and lot's of glue and see how it goes from there.



It took about a weekend of tinkering to get to this shape, then a day of sanding and priming and then another day of painting it to the desired color. Now did I save time compared to 3D printing, who knows. But what I do know is that it was nice to get away from the computer for a few days.

Why did I create it?


When I discovered that resistive touch panels (meant to be used in combination with LCD screens of the same size) were relatively easy to buy and fairly cheap. I started to imagine how it would be like to use such a touch panel for controlling my PC and C64, instead of a regular mouse. Wouldn't it be nice if you can build a KoalaPad for your C64 with modern components? This all  seemed like a nice excuse for me to buy such a panel and play with.

So I bought one, waited a few weeks for it to arrive and when it came in I realsized that such a panel was useless without a decent frame (to prevent it from breaking) so I glued some pieces of scrap wood together and wasn't satisfied with the result. I put it in a corner of the room and quickly forgot about it... many months later when I cleaned up the room I decided that it was time to make a decent frame for it so that I could safely experiment with it in combination with an Arduino Pro Micro. This was pretty easy considering I could use the basic mouse example with only a few modifications and I could use a touchscreen library straight from the internet. This heavily reduced the required tinkering time to get it to work and I could go straight to the details of the user interface. We really live in a great time and age where we can benefit from the great libraries that are available for the entire Arduino community. So with the PC part being functional I could now diveinto the retro computing part. This is the exiting part (from a technical point of view). My intention is to make it work like a KoalaPad and perhaps even like a 1351mouse if all goes well (spoiler alert... it did go well, very well actually).



The koalapad is the famously forgotten input device of the 80's. It could have revolutionzed the world, the way we wrok with machines, but unfortunately, the mouse took over. The image above shows someone working with the koala paint drawing program. She's holding the pad a bit strangely, but I guess that's all to get it into the fcenter of the image. Anyway, the KoalaPad acts like a set of paddles BUT it is much more then a pair of overlapping resistors. The koalapad first measures the position of the pen on the touch surface then translates that to an X and Y coordinate, then it fakes the behaviour of the effect of a paddle on the pot-input of the computer. More about that further on.

And as soon as a KoalaPad mode was implemented, a joystick mode followed and then the obvious 1351 mouse. And the name, well... I could not name it KoalaPad II, that would be confusing, misleading etc. So because I made it for the Commodore 64 and because it is a pad, the name commo pad would be nice. Mostly because it sounds a bit like koala and because this name did not exist so would be easy to find using google. Also the word commo would be very easy to remember for the public it is intended for, Commodore users.

Is it usefull?

Actually, yes. It works pretty well. In all modes, USB and C64. But since the touchpad doesn't detected pen pressure very well, you still need to click a button. This means that you must work with two hands. One hand on the buttons, the other on the pen. Not a big deal, but a major disadvantage when compared to an ordinary mouse. So I'm planning on solving that issue by making a simple "pen" that does have buttons (one of them in the tip). This way clicking can become much more natural simply by pushing harder on the pen until you hear/feel a click. So that's a thing on my to do list. But despite that, the KoalaPad had the same problem, so this whish is actually more intended for regular PC usage and not for the C64. Although I am pretty sure that the C64 usage experience improves just as much.

The pen I have in mind will be connected to the commo pad via a wire, this not only keeps the whole device very simple, it also prevents the pen from being lost.

Technical info

Important info to prevent the C64 from damage

Because the C64 is an old lady that needs to be treated with care and respect but also because replacement parts are becoming expensive and sometimes hard to find.

The device connects to the joystick port of the C64, now technically the joystick port expects signals that are pulling a line down. So a line connected to ground (via a switch) or open. In other words, it's designed to connect to a simple switches. Now the Arduino Pro Micro has sort of 3-state IO-pins. Two states are the logical output states (0V(low output), +5V(high output)) and the third state is the high impedance state, which can be created by setting the IO-pin to input. The IO-pins used are not open collector, but by carefull programming an open collector situation can be faked. Just by toggling the pin between output (with value 0) or as an input (to simulate the high impedance situation). Therefore technically it can generate the required open-collector behaviour the C64 expects perfectly fine. However... accidents do happen... especially during development. And we do not want to apply the +5V from the IO-pin directly to the input of the C64, because this input pin is directly connected to an CIA chip that is easily damaged. So knowing myself, I decided that is was perhaps a bit better to actually make a true open collector IO-connection for the joystick port lines UP/DOWN/LEFT/RIGHT/FIRE. This way nothing can go wrong and therefore I do not have to worry about anything when I work on the firmware of the Arduino. Regarding costs this only adds 5 transistors and 5 resistors to the bill-of-materials which is nothing compared to the costs of the entire device or the costs of the repair of my C64 (which always happens at the most inconvenient moment).

The ADC of the POT inputs is able to handle a direct connection to +5V, so technically we do no need to worry about protection (other then ESD) on that pin, however it doesn't hurt to add a resistor to limit the current a littlebit therefore between the POT pin of the C64 and the IO-pin of the Arduino is a 100 Ohm resistor, although technically the IO-pin of the Arduino would be the real current limitting factor.


Paddle or POT ADC programming tips

Below is a table of registers that are important for working with the paddle / POT inputs.
Decimal value Hex value $ Specification Status
56320 $DC00 Control-Port 1 selected Control-Port 1 selected (bit7=0 and bit6=1)
Control-Port 2 selected (bit7=1 and bit6=0)
54297 $D419 Paddle X value bit7...0 = value range 0..255
54298 $D41A Paddle Y value bit7...0 = value range 0..255
56321 $DC01 Paddle in port-1 Paddle X fire button = bit2 (0=Firebutton pushed)
Paddle Y fire button = bit3 (0=Firebutton pushed)
56320 $DC00 Paddle in port-2 Paddle X fire button = bit2 (0=Firebutton pushed)
Paddle Y fire button = bit3 (0=Firebutton pushed)
The table above shows only 2 paddle rigisters, but the C64 has 4 POT inputs how is this possible if the SID has only 2 ADC inputs. It can do so by using a 4066 multiplexer/switch which the computer must control in order to select which POT lines are to be sampled.



This means that the programmer must first select the control port (also known as joystick port). Then wait... Because conversion takes time and we do not know where the free running ADC is at this moment, it might be in the middle of a conversion while we changed the source of the input. So if we would read the value from $D419 or $D41A directly after selecting the channel, we would get invalid data. So we must make sure that we allow for a full measurement cycle to have taken place which takes 512us, but we must be aware of the fact that we have to wait out for the invalid conversion to be completed, which also takes 512us. Because the discharge cycle is of no big importance (but only as long as we know for sure that there is no additional capacitance added in the paddle itself). Therefore we should wait for at least 2 measurement cycles which would be 1024us, because this way we know for absolutely for sure that a full discharge cycle and a complete measurement cycle has taken place.This delay is no big deal if you are only interestd in the data of one controlport, because then you'll only need to change the mutiplexer setting once and wait once.
But if you are constantly changing the controlport multiplexer this IS a big deal, so it would be wise to program clever in order to save precious CPU time.
You might be tempted to have a delay of only 512us and you'll see that it also works most of the time. Although you will encounter a false value from time to time because of an unreliable conversion. So therefore always wait for 1024us after changing the control port multiplexer settings and you'll be fine no matter what you have connected to your control port.




Now you must not forget to disable the keyboard scanning (one way would be to disable all interrupts with a simple SEI instruction), because the keyboard also uses the lines from $DC00 bit 6 and 7. Meaning that the keyboard scanning heavily interferes with the POT multiplexer!

POT ADC inner workings

How the ADC connected to the POT lines in the C64 work?
Well this ADC isn't an ADC you'll find in modern equipment. This ADC cannot really convert a voltage, it's more a conversion for current. And it does so by measuring the time it takes to fill a capacitor to a known value. Now the ADC logic is inside the famous SID chip of the C64, the capacitance required is outside the SID chip and has a value of 1nF. Below is a very simplistic schematic of the ADC. You can see the counter with increments every microsecond, you can see the comparator for detection of the thresshold level and you see the discharge circuit.



Basically, it works like this: the longer it takes to charge the capacitor to it's thresshold value, the lower the current coming from the paddle must have been. So for a value of 0 of the ADC, the potentiometer of the paddle must be set to a position with a low resistance and vice versa. Technically this is very easy to implement. Because in the hardware all you need is a set of timers and somthing that can act like a discharge switch.

The ADC in the SID has basically two states, the discharge state and the measurement state.
The discharge state has a duration of 256us and is nothing more then a period of applying a small load to the capacitor and therefore effectively discharging it.
Note: the discharge state is not a short, because if it were things might get ugly when the user would tie the pot input to the +5V line, which could very easily happen because paddles are nothing more then a potentiometer tied between the +5V and the POT line. But also if the users would add more capacitance to the POT input. So the discharge cycle takes a fairly long time (256us) to ensure a proper discharge. This was a wise decisssion as it allowed to increase the capacitance to the POT line by placing an additional capacitor in the paddle if this was to be desired. This may be helpfull to reduce noise or to compensate for potentiometers that would otherwise have a resistance that would be too small to be practical.

The measurement state, is nothing more then a counter value being captured when the capacitor's voltage passes through the trigger thresshold. So at the beginning of the measurement cycle, the counter is reset and every us the counter is incremented by one. As soon as the voltage over the capacitor has reached the trigger level, the counter value is captured and we have the ADC value. If the counter reaches the value of 256, the max has been reached, no matter if the capacitance has reached the thresshold, the ADC value will be 255 and the measurement cycle is complete.

Now the discharge state begin again and it all repeats itself over and over again...
Below is a visualisation of what you would see if you would measure the voltage at the POT pin of the control port. Shown are 3 situations of the paddles possition, max, center and min. This is a sketch, not a scope image, therefore keep in mind that the charging curves are not exactly like the real thing but the sketch is good enough to show the principle.




Creative use of the POT ADC (forcing the ADC value)

So now we know how the POT ADC works, we can (just like the KoalaPad and the 1351 mouse do) connect other things than ordinary potentiometers. Because if we can detect the discharge state, we know when the measurement state happens and this means that we can control the moment the trigger level occurs by quickly bringing the capacitor to it's thresshold voltage. So technically the device will be forcing the POT-X or POT-Y registers to the desired value. And this is how you can do that with any microcontroller, though it is important to use a microcontroller with a decent set of timers and interrupt capabillities. For a single POT channel is required: one IO-pin, two resistors and two interrupts are required, see a part of the schematic below.



Now all the firmware in the microcontroller needs to do is:
- Set it's IO-pin to input, the pull-up resistor of 8K2 should make the input a logical 1.
 - Setup the microcontroller to generate an interrupt on the falling edge of the same IO-pin.
 - Now when the discharge state happens, the IO-pin will be pulled down, this results in a falling edge and the interrupt will trigger.
 - Inside the interrupt we set the IO-pin output with a logic value of 0, this prevents the IO-pin from charging the capacitor once the discharge cycle ends.
 - In the same interrupt we also reset a timer that can count microseconds and we define the capture compare register of that timer to trigger after 256us (the duration of the discharge state) + the required ADC value (for example: if we want an ADC value of 128, we set the compare regsiter at a value of 256+128=384us).
 - And last but certainly not least, we enable the capture compare timer interrupt to fire when the compare value has been reached.
 - When the compare value has been reached, the capture compare interrupt will fire and from within that interrupt we will set the IO-pin to input, so that the 8K2 resistor can charge the capacitor (the carefull reader most likely wonders that this charging also takes some time, but considering that that time is very well known we can compensate for it by reducing the compare value slightly, it's just an offset).

With the IO-pin set to input we are back to square one and are capable of detecting the discharge cycle of the next measurement.
Below is an image of the voltage on the POT pin of the control port.



Fortunately, the POT-X and POT-Y ADCs are synchrounous, meaning that they discharge at exactly the same time and therefore measure at exactly the same time. This is great because it allows us to combine multiple functions (required to control the two pot values X and Y) into the same interrupt. Thanks to the excellent timers inside the ATmega 32u4 microcontroller on the Arduino Pro Micro we can even use a single timer for the two required timer compare values. But for those details please check the firmware or download the ATmega 32u4 microcontrollers datasheet.

How the koalapad works

The KoalaPad is an absolute pointing device, the position of the pen on the pad corresponds directly to a position on the screen of the computer. The KoalaPad, sends it data over the POT-X and POT-Y lines of the control port (a.k.a.joystick port). It has a range from 0-255 for both the X and the Y channel of the touch pad. This means that the data can be send directly over the POT wires by forcing the digital value as described above. This also means that any program that can use the KoalaPad can use paddles. There is no technical reason why you can not control a program written for the KoalaPad with paddles, sure it would be far from practical, because you'd be controlling the program (for example koala paint) like an etch a sketch.

The 1351 mouse

A mouse is by definition a relative pointing device, meaning that it sends changes in position, rather then a position itself. It effectively can sense speed and direction. And it does this with two encoder wheels, one for the X and one for the Y direction. These encoderwheels are driven by a ball at the bottom of the 1351 mouse. These encoders are read by a chip in the 1351 mouse, this chip uses these pulses to in- or decrement a 7bit counter. The mouse sends it's data over the pot lines by forcing the digital value as described above. The X and Y counter values from the chip are send directly. To reduce noise/jitter in the forced POT value, the least significant bit of the POT value is to be discarded by the mouse drived in the computer for both X and Y. And the POT value has only a range from 64 to 192.
So, this basically means that all the mouse driver in the computer has to do is to compare the previous ADC value for the X-direction and compare it with the current value, when it increments, the mouse moves to the right and vice versa. Sure there are some challenges because the counter wraps around in both directions, so this may cause problems, especially for fast movements, but this can be detected and therefore does not have to be a big problem. But technically, for normal usage, it doesn't really matter how fast the mouse driver reads the POT values, because the position changes and direction can always be calculated by comparing with the last read value. Hoewever, for a decent user interface experience, it is important that this sampling of the position value should be done at a reasonable and regular interval.

Availability, costs and ordering information:

The commo pad is a diy project.
If you want one, feel free to download the schematics and make one yourself.

Keep in mind that the touch panel is glass with a special plastic coating on the front. The cable coming out of the panel is fragile and needs to be treated with care. Therefore always support the back of the panel with a perfectly flat (and clean) surface (in order not to break the glass by pushing it when testing). And always prevent bending of the cable as much as possible. Although it's not a very difficult project, if you do not have any electronics experience or know how to handle delicate electronic components then perhaps this is not the project for you.

Downloads

The project design and firmware for the Arduino can be download from my github page