Basics of Design Research & Design Hub

A Digitally Controlled Voltage Source

Written by Joseph Corleto

In this article, we’ll look at how we can control a voltage source with a microcontroller (MCU). I’ll show a few different methods, but with a strong emphasis on one particular circuit.


  • What is a digitally controlled voltage source?
  • What are the advantages of a digitally contolled voltage source?
  • How do I implement a digitally controlled voltage source?

  • Digitally controlled voltage sources
  • OPA549

  • Texas Instruments

Recently, at work, I was tasked with designing a system that required the control of a thermoelectric cooler (TEC). If you are not familiar with what a TEC is, to put it simply, it’s a device that’s usually square and has two sides, with some thickness. It has two wires coming off of it across which a voltage can be applied. When running current one way, one side of the device cools and the other side heats up. Flipping the current’s direction causes the opposite behavior. This means it is possible to both heat and cool a surface with a TEC, using one of its sides. The higher the current, the greater the heat flow between the two sides. In general terms, more current translates to a hotter or colder temperature. For the purposes of this article, you won’t need to understand TECs beyond that information. But if you’re interested, Wikipedia has an in-depth description [1].

The takeaway is that you need to have a certain amount of current going through the TEC. Because its resistance is reasonably constant, this can be achieved by varying the voltage across the device. Since the system I was tasked with requires the TEC to be controlled by a microcontroller (MCU), there is a need for a digitally controlled voltage source. And that, my friends, is what I will be showing you in this article. What I’ll discuss in this article can be used for TECs, DC motors, heaters, LEDs, or really anything that requires a digitally controlled voltage source.

VOLTAGE SOURCES & POSSIBLE SOLUTIONS

A voltage source, when first introduced in a circuits course, is described as a two-terminal device that has a fixed voltage across it. Its symbol is shown in Figure 1. In the case of an ideal independent voltage source, no matter what the load resistance might be, the voltage remains fixed, and will always supply as much current as required to “satisfy” the load. By definition, there is no external way to control its voltage by physically influencing it with another voltage source, current, or resistance.

Of course, there is no such thing as an ideal independent voltage source in the real world. For example, take a battery. A battery’s voltage decreases over time from causes due to aging and use. If a large current is drawn from it, the voltage will dip lower due to a voltage drop from its internal resistance, as shown in Figure 2. It cannot supply infinite current as there is a limit to how much can be drawn at one time, and eventually the battery dies when all of its energy has been used up. And worst of all (for us, at least), we cannot control its output voltage directly.

A voltage divider can take a voltage source and produce a different voltage that is equal to or less than the input voltage. This is shown in Figure 3. Looks like we are on the right track, perhaps? We can easily place a potentiometer in the divider and vary the output voltage. Voila, we just created a voltage source constructed from a voltage divider. Better yet, if we use a digital potentiometer, we can now digitally control the output voltage. This circuit works just fine for loads that draw very little current.

— ADVERTISMENT—

Advertise Here

FIGURE 1
An ideal independent voltage source provides a steady voltage and passes any amount of current.
FIGURE 1
An ideal independent voltage source provides a steady voltage and passes any amount of current.

FIGURE 2
Here is a battery represented with an ideal voltage source and a series resistance. As the battery ages and gets discharged, the series resistance becomes more prominent.
FIGURE 2
Here is a battery represented with an ideal voltage source and a series resistance. As the battery ages and gets discharged, the series resistance becomes more prominent.

FIGURE 3
Shown is a voltage divider circuit. We can attach our load to the output so long as the load does not change the values of the resistors in the divider.
FIGURE 3
Shown is a voltage divider circuit. We can attach our load to the output so long as the load does not change the values of the resistors in the divider.

But this is almost never useful for applications where we need to power a load that requires a significant amount of current. This can even mean currents in the milliamp range depending on the application. There are a few reasons for this:

  • The current sent to the load has to go through the divider’s resistor, which will drop some voltage and inevitably make the implementation less efficient.
  • If the load varies at all, the voltage across it will vary as well. Not so good for most applications.
  • There is no voltage regulation. If the input voltage changes, so does the output voltage.

The lesson here is to (almost) never use a voltage divider as a fixed or controllable voltage source directly.

— ADVERTISMENT—

Advertise Here

So, if we can’t use a resistor divider directly, perhaps we can try to use an op-amp? Let’s see. Figure 4 shows our same voltage divider but with an op-amp in between, instead.

FIGURE 4
A buffered voltage divider. The op-amp configured as a unity gain buffer copies the voltage, lightly loads the divider, and outputs the same voltage but with more current output.
FIGURE 4
A buffered voltage divider. The op-amp configured as a unity gain buffer copies the voltage, lightly loads the divider, and outputs the same voltage but with more current output.

This certainly addresses our load regulation issue. The input to our unity gain amplifier will have a high input impedance and will draw very little current from the voltage divider’s output. If the load varies in current draw, the op-amp will maintain its output so long as we size it to have the current output specification we need it to operate within. Typical op-amps on the market can’t provide current to power large loads, but such op-amps do indeed exist. For my TEC, I need about 2A for the temperature control I require. “Thumbing” through the catalog on DigiKey, I found a beast of an op-amp: the OPA549.

The OPA549 can be powered with up to 60V, and can output 10A! The suggested application circuits in the device’s datasheet include implementations of a programmable power supply [2]. These are shown in Figure 5 and Figure 6. A programmable power supply has the same behavior that we want from our digitally controlled voltage source.

FIGURE 5
Here is an example circuit of a resistor-controlled power supply from the OPA549 datasheet.
FIGURE 5
Here is an example circuit of a resistor-controlled power supply from the OPA549 datasheet.

— ADVERTISMENT—

Advertise Here

FIGURE 6
This is an example circuit of a digitally-controlled programmable power supply from the OPA549 datasheet.
FIGURE 6
This is an example circuit of a digitally-controlled programmable power supply from the OPA549 datasheet.

This must be the answer, right? Well, not exactly. There is still no voltage regulation, at least not for the circuit shown in Figure 5. The circuit in Figure 6 overcomes this by using a digital-to-analog converter (DAC). Still, this circuit is expensive. The OPA549 costs over $20 per unit in quantities of 100. For high-power applications, it will require a substantial heatsink because it’s a linear device. Op-amps do excel in precision and accuracy, but unless you need these two parameters to be up to a tight specification, they’re not well-suited for most applications. It’s worth noting that many of us have battle scars from supply chain issues caused by COVID-19. We should usually avoid picking a specialty part lest we find ourselves with empty shelves again.

ENTER THE VOLTAGE REGULATOR

Is all hope lost? Do we have to buy a professional lab supply and somehow duct tape it into our design? Not at all. As they say, you need to use the right tool for the job, and this is no different in circuit design. We can use something called a voltage regulator. The benefits of a voltage regulator in our situation are many. Here are a few:

Voltage regulation & stability: Voltage regulators have fantastic voltage regulation (it’s in the name!) and stability. A voltage regulator closely mimics an ideal voltage source in the respect that if the load or input voltage changes, it will maintain its output voltage, or at the very least recover from it quickly. It also maintains its target voltage within a specified tolerance.

Current: Unlike op-amps, there are way more options for regulators that can output large currents with better efficiencies.

Efficiency: Since voltage regulators are designed to be a voltage source, manufacturers optimize efficiency as much as possible compared to the techniques we talked about before.

Protection: This one is a bonus. Voltage regulators oftentimes have built-in protections that we would otherwise need to build from scratch. These include protections from overcurrent, overvoltage, and overtemperature.

HOW THEY WORK & DIFFERENT TYPES

There are two main types of voltage regulators: linear and switching. Many of us understand the basics of how each one works. Some even know in greater detail different configurations for each type. But I, personally, didn’t have much of a clue until I started to do some digging into basic power electronics. The reality is you don’t need to understand them in great detail. If you get the basic concept, that will be enough to create a digitally controlled voltage source.

Linear and switching regulators do the same thing; they convert DC voltage into another level of DC voltage, and ensure this level stays the same despite the load or input voltage variations. Figure 7 shows the basic idea for a linear voltage regulator.

What‘s interesting is that a linear voltage regulator is composed of a voltage-controlled current source. Sounds strange at first, but it makes sense. If the load resistance were to decrease, causing a rise in current, the voltage across the load would rise. To regulate that voltage, the sense/control circuitry measures this rise in the load voltage and then quickly adjusts the voltage-controlled current source to provide less current. In effect, this lowers the voltage back to its original programmed voltage output. The input command in this control system is the reference voltage scaled by the resistor divider sensing the output. The controlled variable is the voltage output. To see an example of an implementation of a typical linear regulator, see Figure 8. For the curious, more implementations can be found in a convenient guide provided by Texas Instruments, a link for which is available at Circuit Cellar’s Article Materials and Resources webpage [3].

A weakness of the linear voltage regulator is that it essentially uses a transistor as a variable resistor. This can cause power to be wasted in the form of heat. However, the tradeoff is that it doesn’t require a whole lot of parts and is easy to understand. Of course, we can go into much greater detail regarding its operation. But as I mentioned, a basic understanding is enough for what we want to build.

Let’s move on to switching regulators. The way these regulate voltage is a bit different. Take a look at Figure 9.

FIGURE 7
Pictured is a functional block diagram of a linear voltage regulator.
FIGURE 7
Pictured is a functional block diagram of a linear voltage regulator.

FIGURE 8 Here’s an implementation of a linear voltage regulator.
FIGURE 8
Here’s an implementation of a linear voltage regulator.

FIGURE 9
Shown is an implementation of a switching regulator. This configuration is called a buck converter.
FIGURE 9
Shown is an implementation of a switching regulator. This configuration is called a buck converter.

Ignore the capacitor and diode for now. The idea here is that by quickly turning on and off a transistor with varying duty cycles, resulting in a pulse-width modulated (PWM) signal, it’s possible to change the output voltage level and the current going through the inductor. When the switch is closed, the inductor resists this increase in current. It will “charge up” the current until it reaches a steady state. Open the switch, and the inductor will yet again resist this decrease in current. If you do this fast enough, the output will have a triangular-looking voltage drop across it due to this manipulation of current by “charging” and “discharging” the inductor. The capacitor further smooths this triangular voltage, while the diode protects from large voltage spikes during the discharge cycle. This particular flavor of switching regulator is called a buck regulator. There are many more, such as boost, buck-boost, flyback, and so on. Again, check out Circuit Cellar’s Article Materials and Resources webpage if you want more information on those [4].

Now there is still something missing from our buck regulator—a form of feedback. Without any feedback, a change in load resistance (or input voltage) will cause a different output voltage than desired. Much like the linear regulator, a voltage divider feeds back a portion of the output voltage into a feedback sense/control circuit and corrects it against a reference. But instead of controlling the transistor to act as a resistor, it changes the duty cycle to rapid on-off switching.

The advantages of a switching regulator are that it is far more efficient and produces less wasted energy as heat, and there are more flavors, so if we need to have a voltage higher than the input voltage, we can switch to a boost converter. The disadvantage is that the output voltage is not as clean as a linear regulator—with a ripple as a consequence of the use of the inductor, the filter capacitor, the switching frequency, and so forth. In practice it is easy enough to get an output with tens of millivolts, which is perfectly okay for many applications. It certainly was for my TEC. Figure 10 shows what a typical output looks like.

FIGURE 10
This is a typical output from a switching regulator. A small ripple is common in the range of tens of milli-volts.
FIGURE 10
This is a typical output from a switching regulator. A small ripple is common in the range of tens of milli-volts.

MESSING WITH THE FEEDBACK SYSTEM

A commonality between both of these regulators is the need to sample the output voltage. With some linear regulators and pretty much all switching regulators, you can program a fixed voltage value with the values chosen for the resistor divider. I know what you’re thinking: a digital pot for a feedback resistor is a practical implementation of a digitally controlled voltage source. And you are correct, this is perfectly a valid way of doing it. But there are some drawbacks. A practical one is that digital pots don’t always have so many taps. For example, a typical digital pot might only have 128 values to choose from. That might be enough for your application. But another drawback is that the capacitance on digital pots can introduce stability problems. The feedback pin (where the voltage divider output is fed to) is sensitive, which could affect loop stability. This might pose a problem if you’re using this circuit in a control system where you want to control relatively quickly.

Instead, a much better way is to pull current from or push current to the feedback node. Think of it this way—if we wanted to change the output voltage, we can use the formula shown in the following equation.

This is the equation used to program the output voltage for either a linear or switching regulator. It’s valid for linear or switching regulators. The reference varies on the regulator and is given in the datasheet.

Changing either resistor will change the output voltage. Note that changing the resistor changes the amount of current going through the voltage divider. Changing a resistor can essentially be thought of as decreasing or increasing the current to and from the feedback node. With this in mind, it’s possible to instead add a third resistor (Figure 11).

Doing so also changes the amount of current in the voltage divider, but instead of changing our resistors or using a digital pot, we can increase or decrease current at the feedback node by varying the control voltage. The control voltage can be from a voltage DAC. Or, if you prefer, you can replace the resistor and voltage DAC and directly hook up a current DAC. Alternatively, it’s possible to use an RC filter with a PWM wave to replace the voltage DAC if desired.

For the sake of an example, let’s choose the voltage DAC and resistor solution. The DAC can output a voltage from 0V to 3.3V. If you were to hook up Figure 11, you might find that 3.3V is not enough voltage to get to the voltage range out of the switching regulator. Or maybe it can achieve the highest voltage at which you want to program the regulator, but the resolution to achieve that is much higher than that of the DAC. Whatever the case may be, a simple solution is to use an inverting amplifier, with the control voltage as the input. This is shown in Figure 12.

FIGURE 11
Manipulating the feedback pin of a regulator using an external voltage source (such as voltage DAC) and a resistor.
FIGURE 11
Manipulating the feedback pin of a regulator using an external voltage source (such as voltage DAC) and a resistor.

FIGURE 12
Manipulating the feedback pin, but this time by using an inverting amplifier.
FIGURE 12
Manipulating the feedback pin, but this time by using an inverting amplifier.

First, why use an inverting amplifier? Logical simplicity, because as the control voltage is increased, the op-amp voltage will decrease. In other words, a control voltage of 3.3V will yield a programmed regulator voltage output to be at its maximum. If we used a non-inverting amplifier, 0V would be the programmed maximum. There’s nothing wrong with that, but it’s a nicer and more logical hardware interface to have the control input and output both increase together.

Second, what should we choose each component value to be? And how does it affect the regulator output? Let us work our way from the control voltage input. R7 is there to ensure there is a positive shutoff should the DAC fail to open or become disconnected. In other words, if we lose the input control signal, the programmed output will also be 0V, essentially de-powering our device (remember, in my case, this was a TEC). R1, R2, and R3 are chosen to influence the gain of the inverting amplifier. For my circuit, and other ones I have come across, having these all the same value creates a unity gain inverting amplifier. C1 is completely optional. Should you ever want to replace the DAC with a PWM signal, this capacitor will filter the pulses into a steady DC signal. And finally, VR, the reference voltage going into the op-amp’s non-inverting terminal: Since the input and output of this stage are constrained to the voltage range 0 to 3.3V, we’ll have to set it to the middle of that range, or 1.65V.

The equation below connects all of these ideas together. This is the equation used to program the output of the voltage regulator controlled through the inverting amplifier. Please reference the below equation with Figure 12.

I know, it’s a little ugly. But if you throw this into an Excel sheet, it’s much easier to deal with. In fact, there’s one already available for download from the Mosaic Industries website [5]. This was the best I could find, after many days of searching the internet for already-made solutions to a digitally controlled voltage source for a device that consumes a few amps. It lists examples and further design considerations. To wrap this example up, Figure 13 shows what I came up with for my design.

FIGURE 13
Here is my final implementation of a digitally controlled voltage source. This will be used for a TEC control circuit system.
FIGURE 13
Here is my final implementation of a digitally controlled voltage source. This will be used for a TEC control circuit system.

I have bench-tested this circuit for the op-amp and regulator that I chose for my application, and it works rather well. I do have some things to note. I had to split up the feedback resistors, R4 and R5, to be composed of two resistors in order to get the values I required. The Mosaic example instead uses R5 with two resistors in parallel and keeps R4 as a single resistor. My control range and values yielded different values so I elected to get to the resistor solution as shown before. I do not need to use C1 because I will be using a DAC, but I placed a jumper just in case, for some reason, the DAC is dropped (for example, to lower cost). I can always short this jumper and “activate” this feature. There is no harm in keeping it there with a DAC, but the capacitor will change the overall response and I wish to keep it as fast as possible. I ended up choosing a completely different regulator. Most regulators should work—but there is always a possibility it may not work as well as you expect, because the loop stability is different for each regulator. I was lucky to have the opportunity to bench-test it and verify my implementation this way.

CONCLUSION

This circuit technique is definitely going into my bag of tricks should I need something similar and inexpensive in the future. In fact, I was able to shave off about $20 and gained more board space relative to a previous design. Having a digitally controlled voltage source that can pack a power punch is surely something useful to have around my circuit cookbook. I hope you feel the same way, and that you find a use for this as well. Before I let you go—if you follow my column regularly, you might be surprised to not see my second article in my series introducing control systems in this issue. I have not forgotten about it. I haven’t yet been able to collect the control data to present here. But I plan to get it to you all, soon. Thank you for reading! 

REFERENCES
[1] Wikipedia article on “Thermoelectric cooling”: https://en.wikipedia.org/wiki/Thermoelectric_cooling
[2] Texas Instruments OPA549 Op-Amp Datasheet: https://www.ti.com/lit/ds/symlink/opa549.pdf?HQS=dis-dk-null-digikeymode-dsf-pf-null-wwe&ts=1687100033735&ref_url=https%253A%252F%252Fwww.ti.com%252Fgeneral%252Fdocs%252Fsuppproductinfo.tsp%253FdistId%253D10%2526gotoUrl%253Dhttps%253A%252F%252Fwww.ti.com%252Flit%252Fgpn%252Fopa549
[3] “Linear and Switching Voltage Regulator Fundamental Part 1” from Texas Instruments: https://www.ti.com/lit/pdf/snva558
[4] Texas Instruments Guide to Switching Regulators: https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/196/snva559.pdf
[5] “Dynamically Program Voltage Regulators,” via Mosaic Industries: http://www.mosaic-industries.com/embedded-systems/microcontroller-projects/electronic-circuits/program-regulator-voltage

RESOURCES
Texas Instruments | www.ti.com

Code and Supporting Files

PUBLISHED IN CIRCUIT CELLAR MAGAZINE • DECEMBER 2023 #401 – Get a PDF of the issue

Keep up-to-date with our FREE Weekly Newsletter!

Don't miss out on upcoming issues of Circuit Cellar.


Note: We’ve made the Dec 2022 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.

Would you like to write for Circuit Cellar? We are always accepting articles/posts from the technical community. Get in touch with us and let's discuss your ideas.

Sponsor this Article

Joseph Corleto holds a Master’s Degree in Electrical Engineering. Aside from working as a full-time Electrical Engineer, he has a small business (Bit Bang Gaming LLC), which creates video game electronics hardware, and is actively pursuing the creation of a project-based video course using the ESP32. He describes himself as an Electrical Engineering handyman since he has skills in firmware, R&D, PCB design, PCB assembly, and automated testing. You may reach him anytime via his email: Corleto.joseph@gmail.com.

Supporting Companies

Upcoming Events


Copyright © KCK Media Corp.
All Rights Reserved

Copyright © 2024 KCK Media Corp.

A Digitally Controlled Voltage Source

by Joseph Corleto time to read: 15 min