# 2-bit DAC from TTL logic using 2 MCU outputs

Basically I am trying to make a 2-bit DAC that can interface to an external device via one signal wire. I want to create a 3-step signal that can be ~0V, 2.5V, and ~5V.

For starters, I tried using two NPN transistors controlled by two 3.3V output pins from an MCU.

Here is the schematic I have simulated in LT Spice...

With this schematic, I can get my ~0V and ~2.5V fine, but I cannot get 5V. When I apply voltage only to Q5 (the top NPN), I only get 3.03V at the output.

Looking this up with google only yield results for a "tri-state buffer" that has the output possibilities of 0V, 5V, and high-z. I cannot find a shcematic or IC to accomplish what I am looking for exactly....but maybe my search terms are incorrect?

I need a suggested schematic mod or an IC to accomplish what I am looking for if anyone has any suggestions! Thanks!

UPDATE:

I found this Fig. in another post which will take care of reaching up to the 5V. I just need to add a second transistor switch and create a voltage divider which I already know how to do. The LED will replaced by an outbound signal.

Image source.

• If you are trying to digitally change the LED brightness you are much better off using PWM. – crj11 Sep 11 '18 at 14:32
• Actually it is to control two LEDs with opposite polarities. I will update the post. – zme Sep 11 '18 at 14:34
• Is there a common terminal between the LEDs that you are driving? In general, it would be useful to show the LEDs in the schematic. Also, what are the forward voltage drops of the LEDs? – crj11 Sep 11 '18 at 14:41
• "only get 3.03V" yes, because there are voltage drops on R7 and Q5. – Long Pham Sep 11 '18 at 14:42
• Q5 is an emitter follower - the emitter voltage will always be about 0.7 volts below the base voltage. You need a PNP transistor on top to pull the output to +5 V. – Peter Bennett Sep 11 '18 at 14:52

The LEDnique image is mine. Here's another.

Figure 1. A bi-colour 2-pin LED can easily be switched to either colour or any blend in between with two GPIO pins. Source: 2 GPIO, 1 bi-colour 2-pin LED.

With a 3.3 V MCU you should be able to drive a red-green LED by decreasing R1 to 100 Ω for about 10 mA through the LEDs.

If you need a higher voltage, such as 5 V to drive white or blue LEDs, then try this.

Figure 2. 2 x GPIO controlling a higher voltage LED from a 3.3 V GPIO. Source: 2 GPIO, 1 bi-colour 2-pin LED.

See the linked article for an explanation of how it works. The circuit will work for 12 or 24 V LEDs too.

• Cool thanks! I pointed out in an edit to the original post that it will be a single output signal line interfacing to external devices. Can you provide insight to the updated question I added at the end? – zme Sep 11 '18 at 19:08
• Your original post could do with a clean-up. Read it back to yourself from the point of view of someone who has no idea what you are really trying to do. If you're trying to control LEDs then why do you want a 2-bit DAC? Delete the last schematic and ask it in a new question explaining what it's supposed to do. – Transistor Sep 11 '18 at 19:12
• Thank you for your patience. I did not want to seem like I was spamming questions. electronics.stackexchange.com/questions/395531/… – zme Sep 11 '18 at 19:28
• There isn't a problem with a series of well asked questions. They are preferred to a jumble of questions in one post - especially if it keeps getting added to! I'm not convinced that I've answered your question completely. See my previous comment two up from here. – Transistor Sep 11 '18 at 19:46
• I cleaned up the post to simplify the requirement to only needing an output signal (what it connects to is irrelevant now) that can be 0, 2.5, or 5V. The image I used of yours in the OP "update" is the answer to how to get the 5V on the output. – zme Sep 11 '18 at 19:55

An NPN makes a poor high-side driver. The emitter voltage can never be higher than the base voltage minus $V_{BE}$. As you observed, you won't get more than 3.0V at the emitter under the best of circumstances.

You need to add a PNP transistor between +5V and R7. Use Q5, (along with resistors to limit the current) to provide the base current to the PNP.

I suggest that what you want is called an H-bridge. Assuming that your coding is A high gives LED 1 on, B high gives LED 2 on, A and B low gives neither on, and A and B are never high at the same time, something like

simulate this circuit – Schematic created using CircuitLab

When B is low, Q4 is on and Q3 is off. When A is high, Q1 is on and Q2 is off. This provides voltage across LED 1. When A is low and B is high, Q2 and Q3 are on and Q1 and Q4 are off, turning LED 2 on. When both inputs are either low or high, the voltage across the LEDs is zero.

Now, a big gotcha. A and B, when high, MUST be greater than about 4.5 volts (one diode drop below 5 volts). Likewise, when low, they MUST be less than about 0.5 volts. Failure to comply with either of these limits will cause both transistors to turn on at the same time, and they will fry. This means that the transition from low to high and high to low must be fast. This is not normally a problem, but you must be aware of it.

In this circuit, the 5k values provide enough base drive (about 1 mA) to provide 10 to 20 mA to an LED. But you MUST make sure that your logic sources will drive 1 mA and still go above 4.5 volts. I don't know what logic family you're dealing with, but not all will do this reliably.

• Doesn't the OP need a "both on" option? – Scott Seidman Sep 11 '18 at 17:21
• @ScottSeidman - I dunno. He doesn't say. It's not what you call a clear spec, and it's a good example of an xy problem. He also doesn't specify what "opposite polarity" means. That's why I specified. – WhatRoughBeast Sep 11 '18 at 18:30
• This output interfaces to different types of external devices. The requirement is simply to get an output voltage of 0, 2.5, or 5 volts and allow up to 40mA current flow. – zme Sep 11 '18 at 18:41