6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Mar 29, 2024 5:33 am

All times are UTC




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Fri Apr 01, 2022 6:43 pm 
Offline
User avatar

Joined: Tue Apr 03, 2018 2:10 pm
Posts: 125
So, I want to hook up the two ports on a 6522 VIA to GPIO pins on a Raspberry Pi. Obviously, this is going to need some level shifting as the 6522 is running at 5V and the RPI's pins are 3V3.

I decided to use a couple of TXB0108 chips, which are bidirectional. But I ran into a snag.

Long story short, when an output pin on the RPi wants to bring a signal low, the TXB0108 seems to have trouble pulling down the 5V side of the chip. It pulls the level down to about 2.5V. This results in unreliable behaviour, as you'd expect.

I've been poring over the 6522 datasheet, and my limited skills suggest to me that pins set as inputs (or outputs, for that matter) have pullup resistors. Is that right?

The TXB0108 doesn't always play well with pullups because it relies on overwhelming whatever else is going on on a signal line to determine in which direction it's translating. The datasheet suggests that any pullups, for example, should be no stronger than 50KΩ.

I would just like a sanity check here. I tested the circuit with the VIA disconnected, and applying a low signal from the RPi's GPIO pin to the 3V3 side did, indeed, cause the corresponding 5V pin to go to 0V. It's only when the VIA is connected that the signal won't go below 2.5V (and with a lot of noise, to boot). I tried using pulldowns on the line, but no joy.

Is there anything else I could do to counter this, or is the 6522 just too strong?

I'm contemplating switching from the TXB0108 to something like the SN74LVCC4245. This would involve using another line from the 6522 to switch which direction it's translating in, but that's okay. My main concern is my need to be able to have a bidirectional 8-bit data bus between RPi and 6522, and programmatically determining direction is not a problem.

Signals on the other port will be permanently either input or output. For signals going from the 6522 to the RPi, I can use some simple level shifter or even just resistor dividers. Those going the other way won't need translation.

_________________
I like it when things smoke.
BlogZolatron 64 project


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 01, 2022 7:41 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
What kind of 6522 are you using? Even the two modern variants have very different output buffering to each other.

I would have thought a simple resistor divider would work fine in general, and the 6522 should be happy reading 3V3 as high even through a reasonable resistor (the top half of your divider).


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 01, 2022 7:59 pm 
Offline
User avatar

Joined: Tue Apr 03, 2018 2:10 pm
Posts: 125
It's a WDC 65C22N.

I hadn't thought of the resistor divider working bi-directionally. What would you define as a 'reasonable' resistor?

_________________
I like it when things smoke.
BlogZolatron 64 project


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 01, 2022 9:54 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
That one has current limiting resistors - see pages 32-35 of the datasheet. They don't specify a value, but do say that it can source 3mA at 1.5V, which I guess from a 5V supply implies around 1K built-in resistance? The exact amount may not be very reliable.

If it is 1k, and you put 2k between each output and ground, you might get around the 3.3V output level you're looking for, and I don't think it will affect inputs much.


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 02, 2022 7:26 am 
Offline
User avatar

Joined: Tue Apr 03, 2018 2:10 pm
Posts: 125
I’ll give that a go and see what happens. Thanks.

_________________
I like it when things smoke.
BlogZolatron 64 project


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 02, 2022 8:41 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8412
Location: Southern California
For bidirectional translation, you could do something like this for each line:
Attachment:
3v3to5Vbidirectional.gif
3v3to5Vbidirectional.gif [ 8.43 KiB | Viewed 1113 times ]

  • This assumes the '22 will recognize the RPi's high output voltage as a valid 1.
  • It won't work with non-WCC VIAs which do not present a true CMOS input in input mode. (I got bit by this with Rockwell's.)
  • The 15pF is there to keep the 4.7K*input_capacitance time constant from slowing things down.
  • For steady-state DC, the 4.7K will not reduce the RPi's output to the '22. If the RPi can still output 3.3V with the 10K load, the '22 will get the full 3.3V.
  • Going the other way, the '22 pulling up to 5V will result in the RPi getting 10K/(10K+4.7K)*5V=3.4V. (You could go down to a 4.3K, but I figured you're more likely to have 4.7K, and the extra .1V should be fine. Actually the resistors will have some tolerance too. Maybe it'd be best to go to 4.3K. Most people on this forum don't have the resistor collection that I do; so if this is your situation and you don't want to have to order and wait, let me know what values you have, and we can figure out something that will work.)

_________________
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: Sat Apr 02, 2022 9:59 am 
Offline
User avatar

Joined: Tue Apr 03, 2018 2:10 pm
Posts: 125
Thanks for the feedback. I tried Gfoot’s suggestion with various resistors. A 1K resistor gave a 3.3V signal, which seemed okay to me when I was reading it on the multimeter. But looking at it on the scope showed a very noisy signal (perhaps because this is a breadboard prototype) with spikes up to 4.4V!

A680Ω resistor gives a max of about 3V and an average of 2.5V. But there are some nasty transients. Again, this might be a breadboard problem.

My resistor collection is limited: I certainly don’t have a 4.4K - the nearest I have either side are 3.3K and 4.7K. Also, since I dropped my resistor box on the floor this morning (and because I haven’t mastered the colour codes) picking a resistor is now akin to Russian roulette. I’ll see if I can have a play with that circuit, though. After all, I’m only in this for the fun!

I did also wonder about using a 3V3 Zener attached between each line and ground.

_________________
I like it when things smoke.
BlogZolatron 64 project


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 02, 2022 10:01 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1392
Location: Scotland
What about something like this? https://www.adafruit.com/product/757

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 02, 2022 2:17 pm 
Offline
User avatar

Joined: Tue Apr 03, 2018 2:10 pm
Posts: 125
Interesting. I'd rather not use boards like this, but this might be simple enough to reverse engineer to incorporate into my own design. Looks like two 10K resistors and one FET per channel. (Mind you, that still adds up to 48 components in total!)

_________________
I like it when things smoke.
BlogZolatron 64 project


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 02, 2022 4:04 pm 
Offline
User avatar

Joined: Tue Apr 03, 2018 2:10 pm
Posts: 125
So that Adafruit board basically works by connecting the source & drain connections of an N-channel enhancement mode FET to the 3V3 and 5V signal pins. The gate is connected to 3V3. Each side is also pulled up with a 10K resistor to the relevant voltage (3V3 or 5V).

Attachment:
Screenshot 2022-04-02 at 18.00.25.png
Screenshot 2022-04-02 at 18.00.25.png [ 451.3 KiB | Viewed 1080 times ]


I don't know enough about FETs to really understand what's going on here. But would I be right in thinking that whatever is on the receiving side needs to be open drain?

_________________
I like it when things smoke.
BlogZolatron 64 project


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 02, 2022 6:18 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
No, it's fully bidirectional in the sense that either side can drive or not at any point in time. The receiving side needs to just be high impedance as usual for something that's receiving a signal. You need to choose the right transistors though (with a rather low gate threshold voltage), and put them in the right way around.

To understand it, I think it helps to separate the two cases based on which side is inputting and which is outputting.

If the 3V3 side (left) is in input mode and the 5V side (right) is in output mode, then if the 5V side outputs low then the body diode in the MOSFET will pull the 3V3 side low as well, winning out over the weak pull-up resistor on the 3V3 side; and if the 5V side outputs high then that won't happen, and the pull-up resistor on the 3V3 side will pull it high.

On the other hand, if the 3V3 side is outputting and the 5V side is inputting, then if the 3V3 side outputs low then it drives the MOSFET's source terminal to 0V, while the gate is held at 3V3, and (if you choose wisely) that's enough higher than the source terminal that the MOSFET will conduct enough to pull the 5V side low (beating the weak pull-up resistor on the 5V side). And if the 3V3 side is outputting high, then as the gate of the MOSFET is also at 3V3, that's not enough higher than the source to allow the MOSFET to conduct, and the 5V side's pull-up resistor will pull it all the way to 5V.


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 03, 2022 7:04 am 
Offline
User avatar

Joined: Tue Apr 03, 2018 2:10 pm
Posts: 125
Great explanation. Thanks. The Adafruit product uses the BSS138, which seems to be readily available.

_________________
I like it when things smoke.
BlogZolatron 64 project


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 03, 2022 3:15 pm 
Offline

Joined: Thu Apr 11, 2019 12:31 pm
Posts: 33
This is also described in the Philips document Bi-directional level shifter for I2C-bus and other systems.


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 11, 2022 10:17 am 
Offline
User avatar

Joined: Tue Apr 03, 2018 2:10 pm
Posts: 125
Just thought I'd do a quick catch-up on this, and also invite comments as to whether my conclusions are sane.

I've tried a number of level-shifting approaches. For the control signals, I've connected directly between RPi and 65C22 for signals that are outputs from the Pi, inputs on the VIA. With signals going the other way, I've used a simple resistor voltage divider with 2K2 and 3K3 resistors. (I wondered about using 220Ω and 330Ω – comments?). That's also fine.

It's the eight-bit data bus that's tricky, because it needs to be bidrectional. I tried a number of things but am currently toiling away with, again, using a simple resistor divider with the same values. Which was fine for outputs from the 65C22 but not so good for inputs. Again, I found that when the VIA's port is in input mode, the signals never get pulled down much below 2.5V.

So I looked again at the schematic for the WDC 65C22N, which was the device I was using.

Attachment:
WDC65C22N-port-A-buffer.png
WDC65C22N-port-A-buffer.png [ 136.38 KiB | Viewed 897 times ]


Now, I'm no expert (!), but my reading of the schematic is this. In input mode, DDR will be 0 (DATA doesn't matter). The inverter will turn this into a 1 and then the NOR gate will turn this into a 0. With the P-channel FET, this will cause the FET to be ON, because there is negative voltage at the Gate relative to the Source (which is at +5V). I know the resistor is a current-limiting one, but it feels to me like it would act as a pullup in this situation. (The N-channel FET will be off).

On the WDC 65C22S, however, the arrangement is different.

Attachment:
WDC65C22S-port-A-buffer.png
WDC65C22S-port-A-buffer.png [ 132.74 KiB | Viewed 897 times ]


Here, when DDR is 0, the NAND will output a 1 and the NOR a 0, meaning that both FETs are OFF.

So I tried replacing the N device with an S device, and now it's working much better!

Is that a sensible interpretation?

_________________
I like it when things smoke.
BlogZolatron 64 project


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 11, 2022 4:27 pm 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
speculatrix wrote:
Is that a sensible interpretation?

Yes, but watch out for that bus holding device - it will weakly drive the bus to retain its last state, if nothing else is driving it more strongly. This could interfere with what you're doing as well. It might be weak enough that it doesn't matter.

Reading this thread back, I wonder whether you might just end up with so much circuit on the device side of the 6522 that you might as well not be using the 6522. It might be easier to just build whatever you actually want from other components that already provide 3.3V tristate I/O pins - then you only need to do level shifting on the CPU-side interface of the device, which is hopefully less bi-directional and has less need for "smartness" in the level shifting.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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: