Re: Commodore joystick ports

From: Hársfalvi Levente (
Date: 2007-04-11 07:59:30

Jim Brain wrote:
> Yeah, I skipped this portion, for brevity, and because I didn't want to 
> offend the PIC folks.  Some PICs come in 40MHz variants, which means 
> 10MHz effective, though I believe you have to use a Xtal for that.

Facts are no offenses...

> My solution to prevent jitter was to use the internal oscillator 
> function in AVRs (some PICs have this as well, just to be fair).  I set 
> the oscillator up for 8MHz (fastest), and then start watching the POT 
> line.  When I see a zero-clamping of the POT line, I check the timer and 
> reset it.  If the number is != 8*512, then I trim the oscillator using 
> the OSCCAL register to speed up or slow down the oscillator.  I use a 
> threshold factor for the trigger (4096+-16 or so) to prevent constant 
> "hunting" for the right speed and to deal with the limited resolution of 
> the OSCCAL.  As a result, you see the interface "hunt" for a few periods 
> at the beginning.  If the number is way off (the 4066 selects the other 
> paddles, and then switches back, the code ignores and continues.
> But, I won't guarantee the code is great.  It's good enough.  Perfection 
> is a luxury not enjoyed much anymore.  It's not half bad C at that, but 
> it's by no means innovative.  In short, standard disclaimer about my 
> code not being truly "hacker" worthy applies.

That's good as it is... I probably won't have started this in C, but I 
also haven't (and probably won't) made any steps, whilst your code is up 
and running... which is a difference.

There could be another option to avoid jittering... it could also work, 
if you leave the oscillator as it is, and instead that, measure the 
length of the SID cycle and scale all duty-cycle timings accordingly... 
it probably needs some multiplications (but this should be executed fast 
on these newer AVRs). A possible benefit is that you then don't have to 
live with the low resolution of the OSCCAL register.

> The only issue I have is if both paddles are exactly at the same 
> position.  Since both are running on their own timer, and I use the 
> output compare IRQ, both then fight to be triggered first, and one 
> loses, delaying by 1uS or so (in reality, if you turn one paddle to 27, 
> and then turn the other one from 80 to 25, it'll go 29,28,26,25).  
> Changing the code to run one compare when both values are equal could be 
> done, but the resulting code got heavy and hard to debug, and I decided 
> I didn't need that level of perfection.

Yes, I see (I have met this obviously, but 1.) I had no choice :-D (the 
PIC was far slower), 2.) a lowlevel language is less hard to debug in 
such borderline cases). Usually, this (as long as some analog source is 
measured by an ADC and sent to the SID) should never be a problem.

> Begging forgiveness for my ignorance, is it Mr. Levente, or Mr. 
> Hársfalvi?  (ie, which is first name, and which is surname?)  Are there 
> some general rules someone less cultured like I can use to denote which 
> is which?

I certainly feel some level of sarcasm in this comment >-), ...but O.K., 
here you go. In the usual Western (better said, 
anything-but-Hungarian-and-Japanese) notation I'm Levente Hársfalvi. As 
a general rule, surname-first is the usual notation in HU. In email 
addresses, the name is usually shown like this. The e-mail addresses 
themself sometimes show the full name (like 
"levente.harsfalvi@somehost.shomedomain")... those usually show the 
first- and surnames swapped (being the provider companies usually 
multinational). Some people indicate their name like "firstname, 
surname" (like "Levente, Hársfalvi")... which should be easy. And some 
just write the name in the Western notation... which creates some 
ambiguity, but is more "standard", should someone change lots of e-mails 
with foreigners... Personal emails (and similar) are usually signed by 
the firstname.


       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail pre-2.1.8.