Re: Pullup resistors (Was: Commodore joystick ports)

From: Marko Mäkelä (msmakela_at_gmail.com)
Date: 2007-05-09 17:41:23

On Wed, May 09, 2007 at 10:00:47AM -0500, Jim Brain wrote:
> Marko Mäkelä wrote:
> >On Wed, May 09, 2007 at 01:56:20AM -0500, Jim Brain wrote:
> >  
> >>LO->HI:   switch DDR to input, then switch logic level to high to engage 
> >>pullup.  Doing it this way ensures you never drive pin with 5v directly
> >>HI->LO:   disengage pullup, then switch DDR to output.
> >>    
> >
> >Oh, I did remember something about setting the PIN bit on the AVR
> >when composing my answer.  That was for engaging the pullup resistor
> >when outputting a logic 1.  But I don't think it should be necessary
> >for the joystick port, because mechanical joysticks do not contain any
> >pullup resistors.  And I think you can safely leave the PIN bit
> >initialized to 1 at all times.
> >  
> I think you mean 0.
> 
> PORT=0, DDR=0, input, no pullup
> PORT=0, DDR=1, output, low

I think you confused PIN and PORT.  I didn't say anything about PORT,
and I previously wrote that you should set PORT=0 for open-collector
operation.  We have the following truth table:

PORT=0,PIN=0,DDR=0: input, high-Z ("disconnected")
PORT=0,PIN=0,DDR=1: output 0
PORT=0,PIN=1,DDR=0: output weak 1 with a pull-up resistor
PORT=0,PIN=1,DDR=1: output 0 

The first line is equivalent to outputting 1 if there
is a pull-up resistor somewhere else in the circuit, like I believe
there is in the joystick port.

> In my defense, I wrote the joystick code after the initial IEC code, so 
> I was in IEC mode when writing it. 

In 1991 or so I wrote a joystick recorder for the Commodore 64.  The
output would be hooked from the user port to another computer's joystick
port.  The program could also generate some effects, such as autofire
and left-to-right and up-to-down movements (combining them would give
you rotation, useful in the cycling event of Summer Games).  I didn't
give much thought to pull-up resistors or anything else back then.
Because it was a direct cable, it might well have been able to fry the
joystick port.  Luckily, it didn't. :-)

Actually, I don't think you can fry the CIA by connecting two opposing
CIA outputs together.  In fact, you can distinguish the left shift key from
shift lock by making both the column and the row of the keyboard matrix
to outputs.  Normal keys have a larger resistance than the shift lock.
Only the shift lock will be able to pull the output '1' to '0'.  I
didn't invent this idea myself; it was some other Finn who used this
trick in some demo.  I guess this might be dangerous if the outputs were
left connected like that for extended periods of time.  If the pin is
polled and one of the ports is configured back to input very quickly
when a connection is detected, there shouldn't be any damage.

Note that other chips, such as the AVR microcontollers, will be able to
source more current than the CIA.  When you try to sink it with the CIA
to 0, damage may result.

	Marko


       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail pre-2.1.8.