Re: Commodore joystick ports

From: Hársfalvi Levente (
Date: 2004-10-22 00:17:26

Hi guys! :-)

Jim Brain wrote:
>>more, it appears that it bangs the 6 bit position data digitally (why it
>>would do this on the POT port, I don't understand...) Is this what you
>>getting from this?:
> Yes.  It does that to "feed" 1uS chunks of 5V to the capacitor used by SID
> to determine the pot position (using the idea that you can detect voltage
> by charging a cap to that voltage and measuring how long it takes to
> discharge.)  The more 1uS chunks of 5V I feed, the more charge the cap
> has, the higher voltage is recorded.  Primitive, but I was amazed that it
> works pretty well.

That doc was written by me.

The digital "bit banging" trick is possible because of the A/D 
conversion method of the SID chip. This is a "single slope" A/D. Analog 
resistance measurement is done by means of time measurement. The rest 
are just dirty details. The input whose signal level triggers the end of 
time measurement is a digital input. If you feed this input with a 
clever (well controlled =)) digital signal, you can trigger it to 
measure whatever time intervals, actually pretty regardless of the 
presence or absence of the capacitor that is normally used for the 
"resistance --> time" conversion.

So, as an answer to the question at the top above: this method was quite 
logical IMHO for Commodore engineers, who only had digital (NMOS) 
electronics to realise the 1351 mouse. In fact, I found their way pretty 
"creative" ;-). They knew how the SID worked, so they hacked it... nice 

Thinking it over, the above method could be jitter-free and maybe full 
8-bit, provided that the oscillator of the external unit (a 
microcontroller, or whatever) could be synced to the "frequency" derived 
from the POT line frequency (Phi0/512, as the SID's measurement cycle is 
512 clock cycles long). For that, either the external clock should be 
higher by an order or so (the clock resolution could be higher, so some 
"clever" method could be programmed into the microcontroller to avoid 
the jitter), or the clock should be derived from a PLL (...a pretty 
tricky PLL I think... because the SID isn't always connected to the 
joystick port).

The mouse interface described above uses the "simple" digital method, 
cloning the 1351; the doc may sound complicated, but in fact... it 
wasn't the method itself that was complicated: it was the way to figure 
out the method of the SID A/D, without good documentation and 
measurement tools, and later the implementation of the 1351 emulation 
process on a microcontroller like the '16c84. ...It's been a great fun 
to figure out, BTW... ;-) On the other hand, today, with the knowledge 
of the SID A/D internals and with a much better microcontroller, I guess 
it isn't hard to code a similar, but more sophisticated routine anymore.

>>I would think it would make more sense to simply emulate a paddle. In
>>case, you could use a transistor to create a current source on each pot
>>which would emulate a paddle. It is a little early for me this morning to
>>think clearly, but I will look at this later tonight and try to help more
>>someone doesn't already answer you.
> Because I loathed this bit-bang the POT line approach, I tried a bunch of
> other ideas first.
> My initial idea was to use PWM through a low pass RC filter to create the
> correct voltage, but that did not work at all.  I'm still not sure why
> this simplistic approach did not work.

Actually, you need to "emulate" a resistor, or you could also "emulate" 
a current source (not voltage source).

As you see, the paddle resistors are always connected between the POT 
line and +5v. For each measurement cycles, the internal capacitor beside 
the SID discharges completely, and then -- with the start of the 
measurement -- it charges up by the current flown from Vcc through the 
paddle resistor, to at least the trigger level of the SID digital input 
(in this case 2.5v, Vcc/2) (provided that it's a valid measurement 
cycle). After that the process repeats. Now let's suppose there isn't a 
resistor between Vcc and the capacitor, but there is another capacitor 
and a resistor (your RC filter), whose other end is continously 
alternating by the PWM signal of the microcontroller. ...This will, at 
the best case, give a fully random series of values captures by the SID 
A/D. Or (if the resistor of the RC filter is high enough) it will simply 
"look like" (from the point of the SID) a "too high" external 
resistance, thus it'll never capture anything but $ff-s.

It could work, if the PWM output was fed to a small operational 
amplifier, whose output was connected to the POT input through a 
resistor. ...Probably... Even this case, the output voltage of the 
amplifier would have to be always higher than 2.5v to produce any effect 
in the SID. In the 2.5v to 5v region there could be a "proportional" 
segment, where the increasing of output voltage resulted in decreasing 
values read from the POT registers in the SID.

It could also work (probably) if the PWM controlled a current 
amplifier... Or if you used a "current output"-type, preferably static D/A.

> I then looked at serial DACs, as Maxim has some low cost dual SPI DAC
> parts, but Could not determine if that would work, so abandoned the idea.

They could presumably work, provided you connect it to the joystick POT 
input through a resistor. Their output is "static", in the sense that 
they don't ripple like PWMs. They may need an external opamp like the 
above pwm example, though (depending on their capability to drive a load).

Best regards!,


       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail pre-2.1.8.