Best way to drive a 5V TTL line with a 3v3 GPIO? - Page 1
Forum section: electronics / beginners

author: nockieboy
author_rank: Super Contributor
timestamp: December 17, 2018, 09:41:59 am
content: Hi,I'm working on an ESP32<->Z80 interface to IoT-enable the Z80 device. One of the issues I'm trying to resolve is the fact the ESP32 is a 3.3v device and the Z80 is 5v, causing a few contentions.This question, however, is specifically how best to drive several of the Z80's lines from the 3v3 GPIO pins on the ESP32. I need to be able to pull INT and RESET low according to the ESP32's desires. I also need to drive IEO, which should either be at 5V or 0V depending on what the ESP32 is doing.I have read comments previously about using a transistor (or pair of transistors to prevent the signal being inverted) to interface the 3v3 line with the 5v line, but that this may cause a lot of current draw through the GPIO. I have to admit I am not nearly knowledgeable enough in electronics to know why, or what issues this may cause, but it sounds bad.I have a rudimentary setup using a 2N3904 transistor to (I think) pull the relevant line low when the GPIO goes high (see below), but I'd appreciate the thoughts of people with far more experience in electronics than I'll ever have on this subject.I have three spare pins on a74LVC4245ADwhich I could use, but would it be able to pull the lines low? Do I need some sort of open-collector setup to do that? The INT and RESET lines have 4K7 pullups. IEO may be connected to a maximum of one other device and, as its name suggests, it forms part of an interrupt daisy chain.Any thoughts or advice would be gratefully received.

author: perieanuo
author_rank: Frequent Contributor
timestamp: December 17, 2018, 10:18:16 am
content: hi,the current trend is mosfet level converters imholike one attached

author: Cervisia
author_rank: Regular Contributor
timestamp: December 17, 2018, 10:58:35 am
content: Please note that "5V TTL" is not the same as "5V CMOS".TTL devices used only NPN transistors, which resulted in an output circuit that cannot drive higher than about 3.5 V, so TTL inputs were designed to accept anything above 2 V as high.This means that you can drive the Z80's TTL inputs directly from the ESP's 3.3 V CMOS outputs.

author: Zero999
author_rank: Super Contributor
timestamp: December 17, 2018, 11:01:05 am
content: Quote from: Cervisia on December 17, 2018, 10:58:35 amYes, if it's TTL, it will work directly from a 3.3V CMOS output.If it's 5V CMOS, then use a 74HCT IC such as the 74HCT14, which can accept 3.3V inputs and shift it to 5V.https://assets.nexperia.com/documents/data-sheet/74HC_HCT14.pdf

author: mrpackethead
author_rank: Super Contributor
timestamp: December 17, 2018, 11:03:29 am
content: Using HCT logic is a useful thing to do to go from 3.3 -> 5V.

author: beanflying
author_rank: Super Contributor
timestamp: December 17, 2018, 11:22:23 am
content: If you are playing and bread boarding on this or other projects then grab some of these bi directional level shifter boards. Fairly sure the circuit diagram @perieanuo posted above is the same as used on them.https://www.ebay.com.au/itm/5Pcs-4-Channels-4CH-Logic-Level-Converter-Bi-Directional-Shifter-Module-3-3V-5V/141690408987?_trkparms=aid%3D555018%26algo%3DPL.SIM%26ao%3D1%26asc%3D52946%26meid%3D2be9356ef7ac4ad7b4d0c9387b4f955d%26pid%3D100005%26rk%3D6%26rkt%3D12%26sd%3D142308774398%26itm%3D141690408987&_trksid=p2047675.c100005.m1851

author: nockieboy
author_rank: Super Contributor
timestamp: December 17, 2018, 12:08:53 pm
content: Thanks for the replies, everyone.Quote from: mrpackethead on December 17, 2018, 11:03:29 amFunnily enough, I was going to ask about using a 74HCT08 - I could run a GPIO output to both inputs of one of the HCT AND gates to drive the 5V line on the other side... I assume the HCT AND gate would be okay sinking the 5V (4K7 pull-up) line on the Z80 side?Would the 74LVC4245 be able to do the same? I have 3 free pins on one of those chips - if they are able to pull the 5V lines low, I could use the remaining pins.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: December 17, 2018, 12:12:14 pm
content: 74HCT is my default way to do it, but be aware that if you care about very low power draw, feeding 3.3v into an HCT can cause slightly higher static power draw.Not an issue for most applications that need 5V as other draws in the system will be way higher

author: nockieboy
author_rank: Super Contributor
timestamp: December 17, 2018, 12:28:59 pm
content: Quote from: mikeselectricstuff on December 17, 2018, 12:12:14 pmOkay, I'll scrub the transistors and run the GPIO into an inverter (74HCT04) to convert the signal. Thanks!EDIT: Oooh hang on, that won't work though will it? The outputs of whatever is doing the voltage conversion need to be open-collector, as the 5V side has pull-ups and I just need to pull the line down to ground.. *goes off to hunt down open-collector HCTs*

author: Zero999
author_rank: Super Contributor
timestamp: December 17, 2018, 12:49:33 pm
content: Quote from: nockieboy on December 17, 2018, 12:28:59 pmThere are open collector HCT ICs available, such as the 74HCT05, but it doesn't need to be open collector. Shorting the internal pull-up resistor to +5V will do no harm.http://www.sycelectronica.com/semiconductores/74HCT05.pdf

author: nockieboy
author_rank: Super Contributor
timestamp: December 17, 2018, 01:21:46 pm
content: Quote from: Hero999 on December 17, 2018, 12:49:33 pmOh okay, that sounds like a much better option then as I don't want to have to add another chip if I don't have to - I can just use the existing 74HCT04? Actually, thinking about it, I use the 04 to drive power LEDs so yes, I guess it should be fine.

author: emece67
author_rank: Frequent Contributor
timestamp: December 17, 2018, 02:26:49 pm
content: .

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: December 17, 2018, 03:18:26 pm
content: Quote from: emece67 on December 17, 2018, 02:26:49 pmThose bidirectional shifters are pure evil unless you really need bidirectional translation. Doesn't take much capacitance to make them oscillate

author: nockieboy
author_rank: Super Contributor
timestamp: December 17, 2018, 04:09:19 pm
content: Quote from: emece67 on December 17, 2018, 02:26:49 pmI've actually got aTXB0104Din the design doing level translation for the SPI bus from the ESP32 to a couple of MCP23S17s, but I didn't fancy trying to squeeze another chip onto the board, especially if I can make it work using unused inverters on an HCT04 I've got in the system already. The MCPs are connected to the Z80's address, data and control buses (which are 5V), hence the voltage translation as the MCPs are also powered by the 5V supply.Quote from: mikeselectricstuff on December 17, 2018, 03:18:26 pmOh? I've never used them before... in fact, the whole design for the ESP32/Z80 interface exists only in DipTrace at this moment in time, or as a high-level graphical representation to give the idea of how it should all fit together.. I was planning on making another post - probably in the Projects section of the forums - asking for feedback on that design and confirmation that it'll theoretically work before I start trying to prototype it.

author: mrpackethead
author_rank: Super Contributor
timestamp: December 17, 2018, 05:43:27 pm
content: Quote from: nockieboy on December 17, 2018, 12:08:53 pmThere are some LVC Parts that do level translation, such as the 4245, ( its got dual power supplies ), but as a general rule you cant'. most HCT parts (all?) can take a 3.3V input when its on 5V supply ), and get 5V level outputs.

author: nick_d
author_rank: Regular Contributor
timestamp: December 18, 2018, 12:44:28 am
content: The problem with the 74LVC4245 would be that the DIR and /OE pins are ganged to all 8 of the transceivers. So if you already have it set up in the direction that the 3.3V side is an input and the 5V side is an output, and you're either going to keep it set up this way permanently, or else you can live with the /RESET only being driven at particular times, then of course you can use it drive /RESET (it need not be open collector). On the other hand, under these restrictive conditions you'd be better advised to swap out the 74LVC4245 for a simpler, one-way device anyway.You mentioned that you have a 74HCT AND gate, if this is already present for some other reason, and is powered from 5V and you have spare gate(s) on it, then definitely it would be the preferred solution. Since its input threshold is about 1.2V, this will be approximately halfway between 0V and 3.3V, giving you fairly good noise immunity. It has been stated earlier that having a 75HCT input at 3.3V for extended periods of time might increase current draw. I don't think that's a problem. It will be more than 2V above threshold, so the gate won't be even partially on.If you don't have the 74HCT AND gate available, and you don't want to add an extra package just for this, you still have some options. The transistor is a good option, you could use a 2N7002 FET, which would require zero extra components since you only want open-collector operation. The 3.3V might be a bit marginal to turn on the 2N7002, check the datasheet, but I think it would turn it on ENOUGH at any rate.Another option would be simply to connect the 3.3V output directly to the 5V /RESET input. This might be slightly risky, but I believe it would work. When you're at 3.3V you'd be 0.8V above the nominal 2.5V threshold of the /RESET input. Although, you had better check if /RESET is a Schmitt trigger input. Often it is, so you can connect an RC network to it, instead of using a reset generator. This has a slow rise time requiring the Schmitt. If the /RESET input is Schmitt, then the high-going threshold might be around 3.3V which would be too marginal, so you'd need the HCT solution or the FET. Mind you, your actual "high" output would likely be 3.3V plus a diode drop, which may be just OK -- see next paragraph.The risk you would have with the 3.3V driving the /RESET directly is that the /RESET is pulled up internally. So what would happen is either you'd have /RESET pulled low by your 3.3V device and all would be well. Or you'd have /RESET floating or pulled high (would not matter which) and the actual voltage on /RESET would be 3.3V plus a diode drop. Because the protection diode on your 3.3V /RESET output would prevent the voltage getting more than a diode drop above 3.3V, whereas the internal pull-up on /RESET in your 5V device would supply a trickle of current trying to make this happen. Since the internal pull-up would be about 50K in most 5V devices, this would not damage your 3.3V device at all.A minor problem with this setup is that it will be difficult to power off the 3.3V device, since the 5V circuit will be trying to power it up through the /RESET output. If you weren't planning to power off the 3.3V device, then it could be OK. Anyway, it may be bad practice, even if it works.cheers, Nick

author: Cervisia
author_rank: Regular Contributor
timestamp: December 18, 2018, 07:48:51 am
content: Quote from: nick_d on December 18, 2018, 12:44:28 amTTL-compatible inputs are designed to handle a high level of about 3.5 V, but there is no guarantee that there are no cross currents. TI says:Quote

author: nick_d
author_rank: Regular Contributor
timestamp: December 18, 2018, 09:02:29 am
content: QuoteThat is interesting. Thanks for the research. I didn't know that. I assumed that being 2V above the reduced threshold of a 74HCT device would have similar power consumption to being 2V above the normal threshold of a 74HC device, i.e. it would be fine, but I see now that that's not the case.Having said that, bear in mind that 74A** devices are much more aggressive in this regard than 74HC devices. According to an NXP datasheet for a 74HCT00 device that I just looked at, the delta-Icc is only expected to be about 160uA at 25 deg C, it does increase significantly with temperature though. Interestingly there's no data for 74HC.cheers, Nick

author: nockieboy
author_rank: Super Contributor
timestamp: December 18, 2018, 09:07:43 am
content: Quote from: nick_d on December 18, 2018, 12:44:28 amI actually have two 4245's - one permanently configured for input to the ESP32, the other for output to the relevant 5V devices it connects to. If I can drive /RESET, /INT and /IEO from these then that is preferable as it means I'm using the entire chip and can free up the inverters for some blinkenlights.Quote from: nick_d on December 18, 2018, 12:44:28 amOh okay - if there's a more appropriate (read: cheaper) device I can use, I'm all ears. This is a hobby project and I'm (at best) at hobby electronics level, so I'd appreciate any suggestions for suitable replacements. My system for finding parts to solve a problem are shaky - I tend to Google for solutions, hence how I ended up with 4245's.Quote from: nick_d on December 18, 2018, 12:44:28 amIdidhave... All the gates are now used in glue logic for the WAIT generator and data buffer enable. I have got three spare inverters in a 74HCT04 though, but if I can use the remaining 4245 pins (or whatever replacement for it I find), then that frees up the inverters to drive a couple of LEDs, which I could do with.I'm on a budget with this design - to a lesser degree, cost and PCB space (it has to fit an existing form factor) but most critically, pin count - I've reached the 500-pin maximum that my copy of DipTrace allows on its user licence. Whilst I'm in the process of familiarising myself with KiCAD, I haven't gotten any further than designing schematics on it - I know there's plenty of tutorials etc, but I don't want to have to invest hours of work learning how to design a specific PCB shape, size and component placement to meet the form factor I'm designing to for the sake of half a dozen pins, if that makes sense? I'd kick DipTrace into touch completely if it weren't for the fact I find it far more user-friendly than KiCAD, but that's a conversation for another post.Quote from: nick_d on December 18, 2018, 12:44:28 amI originally went down the route of a transistor pulling /RESET low when switched on because there's a number of other devices on the /RESET line - not sure that would make any difference to be honest, as there's still only one 4K7 pull-up, but I felt the need for something with some chops actively pulling the line low and connecting a 5V line directly to a 3v3 GPIO pin violated some subconscious sensibilities...Quote from: nick_d on December 18, 2018, 12:44:28 amIs it? I have an external pull-up on the /RESET line, didn't know it had an internal pull-up? Have just checked the datasheet and can find no mention of one either. It's a Z84C0008, if that matters?Quote from: nick_d on December 18, 2018, 09:02:29 amThanks Cervisia - though I'm not sure I can read the implications as well as Nick has done?I'm using 74HCT parts almost exclusively for the glue logic, with the exception of a 74F part in the /WAIT generator, but this is interfaced via a 4245 to the ESP32.

author: Cervisia
author_rank: Regular Contributor
timestamp: December 18, 2018, 10:00:55 am
content: Quote from: nick_d on December 18, 2018, 09:02:29 amThat 150 µA is a typical value. In the chart above, AHCT might be even lower at 2.9 V. But the worst-case maximum is indeed higher.Anyway, even the worst-case *HCT cross currents are lower than what TTL devices would use during normal operation.QuotePlease note that AC and AHC are quite different families: AC is as fast as possible, while AHC has deliberately weak output drivers to prevent the switching noise from being higher than HC.QuoteHC is not meant to be driven by TTL-level signals.

author: nick_d
author_rank: Regular Contributor
timestamp: December 18, 2018, 10:05:47 am
content: Yes, you can use the remaining 74LVC4245 pins for this, provided they're going in the right direction -- if you have spares in the 3.3V->5V direction, then absolutely you can use them to drive the /RESET and other pins.However, I checked the datasheet for the device you specified, and there is a significant simplification that has been missed so far, see here:https://au.mouser.com/Search/Refine.aspx?Keyword=Z84C0008&FS=True&Tb=datasheetsThis device has HCT inputs, see page 34 "DC CHARACTERISTICS (Z84C00/CMOS Z80 CPU)", a low level input is up to 0.8V and a high level input is 2.0V or more. The reason why the device has HCT inputs is because it's designed as an almost drop-in replacement for the earlier NMOS Z80.So the buffering in the 3.3V -> 5V direction is completely unnecessary, provided you're willing to live with a small extra current draw as has been discussed for the 74HCT00. Although I didn't dig deeply for any delta Icc, you can take it that all characteristics will be similar to an HCT gate.You're right, there's no pull-up resistor on /RESET, I thought you were saying there was one, I hadn't checked this. And the /RESET is not Schmitt. As far as I can see it also doesn't require open-collector drive. So, direct drive all 5V inputs from 3.3V outputs, including /RESET. This eliminates the transceiver in the 3.3V->5V direction. Although this may seem offensive, and will cost a slight power draw, it is MUCH simpler.Now as to the 5V->3.3V conversion. One simple approach is a 1k resistor, but I do not really recommend that. Like I said earlier, it will make it difficult to power off the 3.3V device since you'll have potentially quite a lot of 1k resistors trying to power it up through the protection diodes of its inputs. The ideal way is with an octal buffer powered from 3.3V, which has 5V-tolerant inputs. What you want is a 74AHC541. See here:https://assets.nexperia.com/documents/data-sheet/74AHC_AHCT541.pdfReferring to page 5, it says that Vcc can be up to 5.5V, Vi can be up to 5.5V (indepently of Vcc) and Vo can be up to Vcc. Perfect!This is a cool project, I am learning a lot from doing this researchBy the way, I am a Z80 guy, I have plenty of vintage Z80 chips and Z80 peripherals that I bought from Ebay to tinker with. I haven't done much with them but I did a lot with Z180s commercially. Recently I bought some 3.3V Z8L180s that will go up to 20 MHz (if I recall correctly), and I was thinking of making a 3.3V Z180 system driving a graphic LCD.Credit to whoever wrote this page:http://forum.fritzing.org/t/74x541-octal-tristate-buffer-level-translator/5141cheers, Nick

author: Cervisia
author_rank: Regular Contributor
timestamp: December 18, 2018, 10:09:22 am
content: Quote from: nockieboy on December 18, 2018, 09:07:43 amWe were talking about theoretical limits. In practice, HCT will work fine (because it was designed for such voltage levels).When you're driving an HCT input directly with 3.3 V, the current will be approximately zero. Even if you get a chip with marginal parameters and run it at extreme temperatures, the current will be harmless, and probably not noticeable when measuring the entire circuit.

author: nockieboy
author_rank: Super Contributor
timestamp: December 18, 2018, 11:15:10 am
content: Quote from: nick_d on December 18, 2018, 10:05:47 amMore than happy to live with the extra current draw - the device is powered from USB or external power supply, so I don't have to worry about maximising the life of a battery supply (just yet).The only thing I can see being a possible sticking point is that the ESP32 can also be used to provide the system clock to the Z80 and its peripherals. It uses two PWM GPIOs, one for the main system clock (which can be varied under software control) and the other for specific peripherals. I have a hard time deciphering some of the technical speak and charts in datasheets, but I'm guessing that the ESP32 won't be able to produce a suitable clock signal at 3.3v for the Z80? This will still need to go through some form of level translator?I guess I could use a TXB0104 just for the clock outputs, as I'm using one of those for the SPI signal, but that leads me on to another thought - if the ESP32 can drive the Z80 at 3.3v acceptably, do I need to bother with voltage translations for the two I/O extenders? I've got twoMCP23S17s, powered at 5V as they interface directly with the data, control and address buses of the Z80, so they will be expecting 5V SPI signals...Quote from: nick_d on December 18, 2018, 10:05:47 amOkay, cool. Does it have to be AHCT though? Would HCT suffice as I might actually have one or two HCT541's in my box of tricks? The Z80 is held WAITing while the ESP32 does its stuff, so what's a few nanoseconds between friends?Quote from: nick_d on December 18, 2018, 10:05:47 amHaha, thanks! I've been working on the whole thing for about two years now, on and off. I'd get a website/blog set up if I thought anyone would be interested, detailing my journey from complete and utter electronics luddite with a burning interest in 80's computers (when I started with my first computer) to where I am now (an electronics idiot), but everyone else seems to have beaten me to it. Just about everything I now know about electronics and 8-bit computer design is thanks primarily to this forum and some fantastically helpful people here (and Grant Searle's website, which kicked the whole thing off for me).Currently I have a working Z80-based computer that has a custom-written monitor ROM (learning Z80 assembly 30-40 years late, but it's fun!), runs CP/M 2.2 and 3.0 from CompactFlash, takes up to 4MB of memory, plays authentic 80's chiptunes via the AY-8910 PSG and with plans to IoT-enable it (with a web-based console) via the ESP32 and eventually develop a graphics card for it so I can run it as a completely standalone system.Have a look here:https://youtu.be/YjoUeCCG7PcIt's a small video I did back in the summer on a 3D model of the computer and simulation I put together to test it all out. Currently I only have the CPU, memory and serial cards in proper PCB form, the CF card is interfaced via a breadboard and the rest doesn't exist yet (though it did originally, all on one beast of a breadboard, but it was so unreliable I had to move to PCB-production as the prototype died one day and refused to work again!)Quote from: nick_d on December 18, 2018, 10:05:47 amWell, maybe this will motivate you again?

author: Cervisia
author_rank: Regular Contributor
timestamp: December 18, 2018, 12:56:39 pm
content: Quote from: nockieboy on December 18, 2018, 11:15:10 amThis works only if the device has overvoltage-tolerant inputs (see page 18 of NXP's Logic Selection Guide:https://www.digikey.com/Site/Global/Layouts/DownloadPdf.ashx?pdfUrl=755DA3330E4E422EAEF6B9FF5092A9CB).Only AHCT has them.With HCT, you would need to add a current-limiting resistor (see the bottom of page 23), which would prevent you from using fast signals.

author: nockieboy
author_rank: Super Contributor
timestamp: December 18, 2018, 01:13:27 pm
content: Quote from: Cervisia on December 18, 2018, 12:56:39 pmAh, thanks for that Cervisia - was hoping I could use existing parts but AHCT541's don't seem too expensive, will add them to my BoM.

author: nick_d
author_rank: Regular Contributor
timestamp: December 18, 2018, 01:33:32 pm
content: Referring to this:https://assets.nexperia.com/documents/data-sheet/74AHC_AHCT541.pdfIt's actually the AHC that's called for in the 5V->3.3V conversion role. Because the AHCT is only specified for 4.5~5.5V operation, whereas what we want to do here is operate the AHC at 3.3V to produce the correct output levels, while taking advantage of the 5V-tolerant input (I guess both AHC and AHCT have the 5V-tolerant input, but this doesn't give you much extra margin with the AHCT whose minimum recommended VCC is 4.5V).cheers, Nick