26

I need a simple, single directionnal level shifter for 3.3V -> 5V conversion.

There are many options on the internet, some using a logic ic and some using 2 NPN transistors (converter and inverter), but I never found an option using only a single transistor (and 2 resistors).

My understanding is that when input is at 3.3V, the transistor is blocking and R2 pulls output up ; while when input is 0V the transistor is passing and pulls output down to transistor VCE(sat).

single directional level up shifter

So, why wouldn't such a converter work? There must be a reason...

Nicolas D
  • 1,014
  • 1
  • 8
  • 11
  • 1
    Well for one thing, a 0V input gives a 0.7V output with this design. – shieldfoss Sep 12 '13 at 10:46
  • 6
    @medivh It would give Vce(sat) as the output voltage at 0 Volts input - and for many small signal transistors, Vce(sat) is far smaller than the diode drop, e.g. 0.3 Volts maximum for the [2n2222](http://www.fairchildsemi.com/ds/PN/PN2222A.pdf). – Anindo Ghosh Sep 12 '13 at 10:50
  • 1
    @AnindoGhosh True. Still not equal to 0 though. – shieldfoss Sep 12 '13 at 10:52
  • 1
    @medivh I just simulated it with a 2n2222 spice model, and the voltage goes from 0.14 Volts to 4.92 Volts. A perfect low level of 0 Volts is not really needed for most digital inputs. – Anindo Ghosh Sep 12 '13 at 10:55
  • 4
    Ug. You should draw your schematics more sensibly layed out, especially if you ask others to look at them. What you have is a simple circuit, but I had to tilt my head and think about it to realize what it is actually doing. With a proper layout that would have been immediately obvious, and might help you see what is really going on in the circuit too. (For more info see https://electronics.stackexchange.com/a/28255/4512 . ) – Olin Lathrop Sep 12 '13 at 12:47
  • 19
    The schematic looks pretty clear to me.. – pericynthion Oct 17 '14 at 23:55
  • 8
    Schematic looks fairly good to me also. Olin can be a little picky. It's missing a junction dot on the bottom of R2, and the Q1 designator should be next to the transistor. Also, a part number for the transistor should be shown (e.g. 2N2222). It's got the input on the left and output on the right, which is correct. – tcrosley Oct 18 '14 at 00:23
  • 1
    Something like this is better with a FET: http://electronics.stackexchange.com/questions/97889/is-there-any-bidirectional-5v-3-3v-level-shifter – Fizz Dec 01 '15 at 12:21
  • 7
    Also, you have pretty much rediscovered [US patent 3283180](http://pdfpiw.uspto.gov/.piw?Docid=3283180&idkey=NONE&homeurl=http%3A%252F%252Fpatft.uspto.gov%252Fnetahtml%252FPTO%252Fpatimg.htm), from the 1960s. – Fizz Dec 01 '15 at 14:25
  • I found your solution in a somewhat confusingly written appnote: http://www.silabs.com/Support%20Documents/TechnicalDocs/AN883.pdf They actually do bidirectional translation (on their SDA line), with one direction (low to high) being exactly like yours. They measured only 150mV saturation with a MMBT3904 when doing 1.8V->3.3V translation. – Fizz Dec 01 '15 at 15:04
  • @RespawnedFluff thanks for the biblio! I was pretty certain that it was either wrong or very old tech. Now I know it works and I have the refs - nice! – Nicolas D Dec 01 '15 at 16:05
  • You can use a bi-directional level shifter using n-channel mosfet without logic inversion. See this thread - https://electronics.stackexchange.com/questions/313869/connecting-3v-digital-output-to-arduino-using-bi-directional-level-shifting-mos – Sridhar Rajagopal Jul 07 '17 at 15:28
  • I have a question on this. When the transistor is conducting, doesn't this dump +5v into the 3v3 logic source? A lot of microcontrollers seem to fry if exposed to 5v even at very low current levels. Wouldn't this kill most Arduinos, etc? – Scott M Mar 08 '23 at 13:33
  • @ScottM I don't think so. The transistor is conducting when the input side (which is some kind of digital output) is pulled down; in that situation it's expected to be able to swallow a reasonable amount of current - less than 1mA in the example. – Nicolas D Mar 17 '23 at 13:55
  • @Nicolas D Ok, so the current is low, but I thought Arduinos were sensitive to voltage as well, and anything over 3.3v presented to a GPIO pin would damage them, regardless of current. Is that only true if the pin is an input? – Scott M Mar 18 '23 at 14:11
  • @ScottM Microcontrollers usually have input protection diodes (diodes to Vcc and from ground). If the current is not limited they'll fry all right, along with the rest of the chip ; if the current is limited to a value those input diodes can handle, they'll just clamp the voltage to the rails, up to the forward voltage drop of those diodes. You'll have to refer to the specific microcontroller's datasheet to know the acceptable limits, and adapt resistor(s) values accordingly. – Nicolas D Mar 21 '23 at 15:15
  • @ScottM I'm actually not quite sure I got your question right. On a more basic level, you don't "expose" the pin to 5V if there is a resistor between the 5V and the pin. If the pin is an output (or an input with protection diodes), significant current can flow safely through the pin and the external resistor ; therefore U=RI voltage is dropped. – Nicolas D Mar 21 '23 at 15:21

2 Answers2

21

The single-BJT level shifter in the question would work: If the input impedance of the device on the 5 Volt side is significantly higher than the 6.8 k shown in the question, the expected ~0.3 to ~5 Volt signal would be received (taking a 2n2222 as an example).

However, for lower impedance inputs, the input would act as a voltage divider with the 6.8 k resistor, attenuating the high part of the signal significantly.

For instance, if the input impedance of the load on the 5 Volt side were, say, 100 k, the signal would top out at around 4.6-4.7 Volts. Still not too bad.

Any lower, and the level becomes problematic. This is when one needs an alternative, such as a two-transistor set-up mentioned in the question, to drive the output rail harder.

Anindo Ghosh
  • 50,188
  • 8
  • 103
  • 200
  • 4
    As long as the 3.3V driver can sink, say, 4 mA, the output resistor on the level shifter could be reduced to 1200 ohms. Under these conditions, the base resistor could be raised to 6800 ohms, which still gives plenty of drive (0.4 mA) to saturate the transistor. Total current sunk by the 3.3V driver would be 4.3 mA. – Dave Tweed Sep 12 '13 at 11:13
  • 2
    I didn't think about that, since for my case I expect the 5V-side input impedence to be lots of MΩ. But that totally explains why people go the 2-NPN route! Thanks... – Nicolas D Sep 12 '13 at 13:52
10

I like your solution. Since the question is about simple solutions, I have a few alternatives (some solutions provided by Microchip HERE):

1) Direct connection: If Voh (high-level output voltage) from your 3.3V logic is greater than Vih (high-level input voltage), all you need is a direct connection. (it is also required for this solution that Vol (low-level output voltage) of the 3.3V output is less than the Vil (low-level input voltage) of the 5V input).

2) If the above conditions are close, you can often boost the high-level output voltage slightly with a pull-up resistor (to 3.3V) and direct connect the signals.

3) The pull-up resistor can provide a small amount of high-level voltage increase. For more, you can use diodes and pull-up to 5V. The circuit shown will not pull-up clear to 5V, but it will increase the high-level input voltage to the 5V logic by the amount of one diode voltage drop (appx 0.7v). Care must be taken with this method that you still have a valid low-level as that is also raised by one diode drop. Schottky diodes may be used for a slight increase in high-level voltage while minimizing the undesired increase in low-level voltage. Refer to the above mentioned app note for more on this circuit.:

schematic

simulate this circuit – Schematic created using CircuitLab

4) If you can deal with a logic inversion (and don't require active pull-up), a mosfet and pull-up resistor may be used:

schematic

simulate this circuit

5) I know you aren't looking for a logic ic solution, but for completeness I will mention one (of probably many). The MC74VHC1GT125 is a "Noninverting Buffer / CMOS Logic Level Shifter with LSTTL−Compatible Inputs" in a SOT23-5 or SOT-353 package. Small simple and cheap.


Apparently this subject was also discussed the other day: Step up 3.3V to 5V for digital I/O although the solution there is incorrect (thanks Dave Tweed).

Tut
  • 4,195
  • 1
  • 21
  • 38
  • Yes, but they got it wrong in that other question. – Dave Tweed Sep 12 '13 at 12:42
  • It looked a little suspect to me ... I'll edit to mention that. – Tut Sep 12 '13 at 12:44
  • I like that 3rd solution, but I think it's subject to the same input impedance limitation as my original schematics... right? – Nicolas D Sep 12 '13 at 13:56
  • 1
    Not exactly. Your 3.3V circuit must sink both the collector current and the base current (sufficient to saturate Q1), but should then deliver a lower Vol to the 5V logic. The diode circuit need only sink enough current for the 5V logic (and the added pull-up resistor) which may be quite low in the case of CMOS (for example), but will have a higher Vol due to the diode drop. Consult the data sheets to determine which works best. If you have sufficient margins, don't overlook direct connection which is quite common. – Tut Sep 12 '13 at 14:38
  • 1
    Shouldn't something be said about switching times? With a 10 pF load, the time constant is 100 ns for one of the transitions for the last circuit. – Peter Mortensen Feb 10 '18 at 02:34
  • Just needed one of your number 4s. – Paul Uszak Apr 16 '19 at 11:59