6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 11:51 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri Dec 11, 2020 4:42 am 
Offline

Joined: Sat Mar 11, 2017 1:56 am
Posts: 276
Location: Lynden, WA
I am using a micro controller for keyboard and DOS duties in my build. So far, its just been keyboard, which has always been a one way data flow (6522 receives data from micro controller.)

Now that I am implementing my DOS, I need to send AND receive. I'm concerned that if I improperly switch the DDR registers, I could cause a short. Lets say there is 5 volts output on a microcontroller pin, and I switch the VIA pin on the other end to be an output also, that happens to be outputing 0 volts. Would this not cause a short?

I'm using an atmega1284p for the micro. I don't recall if ports on that chip can be tri-stated, which would probably solve the whole thing.

My question is, is there a proper order in which to switch the DDR on the VIA and the micro respectively?

EDIT: It appears the pins on the micro can indeed be tri-stated. Does this mean that, as long as I don't use the pull-ups on the micro, I'm safe to do whatever?


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 11, 2020 5:06 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
There are a few ways it could be handled. If the short is of short duration (like a few milliseconds—it's definitely not necessary to go down to microseconds), you definitely won't damage anything, but the jerk on the power and ground connections could be impressive. You could put a 470Ω resistor between the ends, with a 47pF capacitor across it so the RC formed with the ICs' input capacitance doesn't slow down response time. If it's a WDC W65C22S, the resistor could be a lot higher (even 10K or even quite a lot more); but Rockwell and other brands offered an LS-TTL-type input on the port pins when in the input mode, and pulling them down to a valid logic 0 may not be possible with much of a resistance in the line. I was bit by this years ago. WDC's '22 gives a true CMOS input on port pins when they're in the input mode, avoiding a lot of problems.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 11, 2020 6:18 am 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
Firstly, a GPIO pin set to "input" mode is indeed tri-stated. That just means it isn't being driven as an output, either high or low.

The best way to change drive direction is to tri-state the device currently driving a line before activating the device currently tri-stated. So, set the MCU to input mode, then set the VIA to output mode; in reverse, set the VIA to input mode, then set the MCU to output mode. You'll want to have an explicit external signal to correctly handshake this.

If you have MCU pins that cannot be tri-stated, then you can exclude the corresponding VIA pins from the DDR mask, keeping them in input mode while others go to outputs. Or you can insert a 74HC-series tristate buffer between the MCU and the shared bus.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 11, 2020 9:54 am 
Offline
User avatar

Joined: Sat Dec 01, 2018 1:53 pm
Posts: 730
Location: Tokyo, Japan
Just a couple of other thoughts on ways to deal with this:

If you have the ports and pins, you can just use separate ports for each direction. The Apple 1 worked this way, using one port of the 6820 for ouptut to the video subsystem and the other port to read the keyboard. In the RC6502 Apple I clone SBC an MCP23S17 I/O expander is added to give the microcontroller that emulates the keyboard and video subsystems plenty more I/O lines.

For safer bidirectional communication on shared I/O lines, you could put pull-ups on the lines (or use internal pull-ups in the PIA or microcontroller) to hold them high by default and use only open-collector connections to them, ensuring that if more than one party tries to "talk" at the same time they're both just sinking currents from the pull-ups and doing no harm to each other or anybody else. This is how the Commodore serial bus used for VIC-20 and C64 drives and other peripherals works.

Bidirectional communications requires some sort of protocol of course, and the Commodore one is not simple. (I don't know if it's really possibly to do this simply.) So if you decide to proceed down the bidirectional path, you should keep in mind that there's always the two-channel option in case things get too complex and annoying.

_________________
Curt J. Sampson - github.com/0cjs


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 11, 2020 3:33 pm 
Offline

Joined: Sat Mar 11, 2017 1:56 am
Posts: 276
Location: Lynden, WA
I am considering using dedicated ports as you say. I'm running out of pins on the micro, but nothing a shift
register wouldn't solve.

I was gonna roll my own "protocol". Basically device one interrupts device 2, whom then send an ACK. At that point, relevant DDRs are switched, and the 6522s built in handshaking is used.

I don't know why I'm being so stingy with using up another VIA port. Plenty of room to add a second chip if more stuff is needed.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 11, 2020 5:40 pm 
Offline
User avatar

Joined: Thu May 14, 2015 9:20 pm
Posts: 155
Location: UK
Connect the pins of the microcontroller and the VIA together using 100Ω resistors, but aim to operate them as detailed by Chromatix’s post. Just two lines can be used for signalling. One, microcontroller to VIA, and one, VIA to microcontroller.

In the event of a bus clash (when two chips are driving the same line or lines) the 100Ω resistors should limit any ‘short circuit’ current to a level that the chips will survive, and which will limit the draw from the power rails. But at 100Ω, is low enough not to affect the signals too much. I assume that transmission of data between the two is not at a high speed, therefore the time to charge up stray/input capacitance should not be a problem?

Mark


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 12, 2020 12:54 am 
Offline

Joined: Sat Mar 11, 2017 1:56 am
Posts: 276
Location: Lynden, WA
Nothing faster than 8Mhz. I like the 100R resistor idea. That way, I'm protected from getting my code backwards. Easy to get confused going back and forth between coding for the two chips.

I'll still consider just using separate ports for each direction too.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 68 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: