# Help using DAC to control DC-DC Buck converter

I'm deep down the rabbit hole and getting out of my depth. I realise this has come up several times previously and have read and tried to understand these previous posts:

DAC controlled buck regulator

Is it possible to control a DC/DC buck converter's output voltage with the DAC of an ESP32?

I have a buck converter based on the XL4016 chip, datasheet here: https://www.makerfabs.com/desfile/files/XL4016-Datasheet.pdf

I am taking a 12 V supply voltage and using the converter to regulate a range of around 4-10 V. The total current will be around 4-6 A. The use case is thermostatic control of Peltier modules.

I am trying to use a microcontroller - Arduino Uno and a DAC the MCP4725, to control the voltage regulation instead of the onboard trimpot, inspired by Curious Scientists videos on Youtube and his website:

https://curiousscientist.tech/blog/mcp4725-szbk07-circuit-control

My understanding is that via the feedback pin, I can use current to imitate the usual feedback loop and make the IC vary its output voltage. I've realised the chip on my buck converter is different to his example..

With Kirchhoff's law of current and reading through the above site, my understanding is that at the the FB pin, where the voltage is maintained at the Vref of 1.25 V, the net current into the pin is 0, i.e. I1 = I2 + I3. By changing I3, the FB pin will regulate Vout and therefore I1.

By my calculations and measured resistances in my scenario, I2 is 3.7 mA (1.25 V/340 Ω). For a desired Vout of say 6 V, I1 would be 5.4 mA (4.75 V/880 Ω). I3 therefore should be 1.7 mA, which say could be Vdac of 1V with a R3 of 147 Ω.

Whilst this makes sense on paper, my prototyped setup does not behave well. I have managed to get some voltage regulation by altering the DAC output, but it fluctuates wildly, has a steep gradient of change over a tiny variation of output voltages. I've tried different resistor values for R3 at 100 Ω, 470 Ω, 1000 Ω etc. with no significant change. By my calculations and measurements, I only manage to regulate the voltage with an I3 current into the node rather than sinking it. e.g. Vdac of 2.85 V with R3 of 470 Ω produced a Vout of 7.1 V, suggesting I3 of 6mA, although when I tried to measure it it was around 3.5 mA.

I guess my questions are many:

• Am I measuring some things wrong? Could I2 be completely different, since otherwise
• The DAC in this case always going to act as a current sink?
• Is my breadboarded setup with wires all over the place causing significant interference?
• I have done the tests with the presence of a load on the Vout, is this wrong?
• Is this beyond the limits of my DAC? (I read about voltage DAC vs current DAC control - DS4432 being a good choice)

• Should I just change DAC to the DS4432 as mentioned in another post?
• Am I better off using a digital potentiometer rated to the max Vout (12)?
• Is there something about the XL4016 compared to the LM25116 (found on the SZBK07 used by Curious Scientist) that is preventing me from succeeding?

Edit 1:

Many thanks for all of the input so far. Some of it I understand, some of it is a bit too advanced.

To clarify a few points:

1. The intended load on the buck converter is going to be 4x Peltier modules in parallel operating at around 5 V 1.25 A each giving approx. 20-30 W total power. The microcontroller will act as a thermostat and therefore I will ideally be able to vary the voltage to the modules.
2. The buck converter is a pre-made item that I bought online and is almost identical to the photo below. I have just found this datasheet which I assume is also identical.
3. I have removed the V-adj trimpot and I am feeding my Vdac into pins 2/3 of that.
4. I had chosen those values of resistors for R3 based on the measurements for R1 and R2 I made, in order to achieve the current sink by my calculations at 0-5 V.

Edit 2:

I've tidied up my breadboarding and my DAC control. I've tested the output of the DAC and it is stable with no fluctuation. It is a 12-bit converter. The 'useful' range of outputs is across 20 bit values - suggesting only modulating Vdac by around 25 mV!

The regulated Vout fluctuates by around 50 mV at its worst which for a Peltier module I don't think is awful?

https://cdn.shopify.com/s/files/1/1509/1638/files/XL4016_Step_Down_Buck_DC_DC_Converter_2c6dab48-c097-4da9-bf9d-99171a9e32f8.pdf?v=1653643325

• Try using 10k-100k resistors. With 100 ohms the current you are demanding from the DAC is very high. Commented Aug 4 at 16:17
• What is your exact schematic? What is your load? (You say you have one, but don't specify what!) Have you looked at the waveforms? Is the supply stable at any setpoint? Is the DAC output stable? Why choose such low resistor values, what calculation is driving the selection (or if none -- should that be a sub-question)? What is your layout like, could switching noise be screwing everything up? Commented Aug 4 at 16:18
• I've done this lots of times to make MCU controlled voltage rails and in general it works very well. However, it's not clear what you're actually doing. If you're trying to build a high current DCDC converter on a breadboard, that's not going to work for reasons unrelated to your question. If you've got a working converter and you want to hack in external control, then show what you actually did. Commented Aug 4 at 16:34
• Why not a digital potentiometer in feedback?
– TQQQ
Commented Aug 4 at 18:17
• I've updated the post to include some key information @TimWilliams - I hope that helps. Commented Aug 4 at 19:29

The DC-DC chip operates a bit like an opamp wired as non-inverting amplifier, with the opamp's positive input tied to the internal 1.25V reference, and its negative input being the FB pin.

Just like an opamp, the chip will control its output voltage to ensure the FB pin is equal to the internal 1.25V reference. This only works within the output voltage limits of this particular DC-DC converter, of course, but we can model and simulate it with a generic opamp instead of the DC-DC chip:

With Kirchhoffs law of current and reading through the above site, my understanding is that at the the FB pin, where the voltage is maintained at the Vref of 1.25V, the net current into the pin is 0, i.e. I1 = I2 + I3. By changing I3, the FB pin will regulate Vout and therefore I1.

Correct

By my calculations and measured resistances in my scenario, I2 is 3.7mA (1.25V/340ohms). For a desired Vout of say 6V, I1 would be 5.4mA (4.75V/880ohms). I3 therefore should be 1.7mA, which say could be Vdac of 1V with a R3 of 147ohms.

Correct... in theory.

In practice, I don't like this design because it has one big flaw: when the DAC output is zero, the DC-DC's output voltage will be at its maximum value.

This means, depending on supply sequencing, whether the MCU boots faster than the DC-DC starts up, and other factors... at power-up, the output voltage is probably going to spike to the DC-DC's maximum before it settles to the value you want.

This can be a problem if you use it to power something that will not tolerate that voltage, and especially if you use it as a bench power supply. I mean, if I set the bench supply to 3V3 then use it to power an ESP32... then turn it off and back on... I expect it to deliver a smooth ramp from 0V to 3V3, not start up with a 12V spike that kills the ESP32 instead.

If you use it on a boost DC-DC then it can also cause the boost chip to commit suicide by excessive output voltage.

Also your feedback resistors are way too low. This causes two problems: first, asking the DAC to deliver a high output current, which will reduce its accuracy via output impedance and self heating. Second, if the DAC is unpowered, the low value resistor on its output means it will still receive current on its output, potentially powering it by its output pin.

So it's a design that works in some cases... but not for every use.

IMO it is much better to wire the DC-DC chip so it will output its minimum voltage by default (1.2V) and then inject a current into the feedback node to raise the voltage. That way, while the microcontroller handling the DAC boots, it will output a safe low voltage. Likewise if the DAC loses its power supply.

Example:

When the DAC outputs 0V, then M1 is off and the DC-DC outputs its default voltage of 1.2V. This also works if the opamp on the left (X2) is unpowered, so there are no startup issues. It's pretty foolproof, as M1 needs to be controlled to increase the output voltage.

Then the DAC can control the opamp, which together with M1 forms a current sink, that pulls the feedback voltage down to increase the output voltage. A capacitor may be needed in parallel with the feedback resistor to compensate for M1's capacitance and keep the DC-DC stable.

Note this circuit will not bring the output voltage to 0V as it only sinks current from the feedback node. This can be fixed with a constant current source into the feedback node (not shown).

A simpler implementation would be to use a current output DAC instead of voltage output, there are some specifically designed for this purpose. Some are source/sink, which will bring output voltage to zero.

Another example:

This uses an opamp as Howland current source to source/sink current into the feedback node. If this opamp is powered from the DC-DC's input voltage there should be no startup issues. It will go down to zero volts output, but this requires 0.3V on R6, which can be done by replacing R6 with a voltage divider from 3V3 having the same impedance. In this case if 3V3 is unpowered, it should still output 1.2V... but this is less certain than in the previous case.

Is my breadboarded setup with wires all over the place causing significant interference?

Yes, solderless breadboards and switching converters are not really a good match, as these converters require very low layout inductance and solid decoupling so the fast current switching does not cause voltage spikes and other issues. Basically this chip switches 8A in... probably a couple tens of nanoseconds... so the difference between "it works fine" and "complete failure" is maybe 10nH... in other words about 1cm of wire. A thru-hole cap mounted on solderless breadboard has way more inductance than that. So basically, on a breadboard, every time your chip turns on the internal switch, its power supply wiring has so much inductance that its supply voltage will drop to zero during the switching. I have no idea what it will do when that happens, but usually it isn't good.

EDIT

So if you're using a XL4016 on the readymade PCB with the schematic provided in the question... I see this has potentiometers to set both output voltage and output current.

If this is to drive a Peltier cooler, controlling current will work as well or better than controlling voltage, and according to the schematic, it should be much easier to hack the module to control its output current than voltage.

On the original schematic, 7805 outputs 5V, then TL431 creates an accurate 2.5V reference. The "current pot" outputs an adjustable voltage corresponding to your current setting. Resistor at the bottom right converts output current to voltage, which is compared to the desired setting by the top opamp, which controls XC4016, and we have an adjustable current DC-DC.

So the board already has a circuit to control current according to the voltage generated by the pot. So all you have to do is feed it your DAC's output voltage.

Modification:

If you replace the 2.5V reference with a variable 0-2.5V this will control output current.

You can do that by removing the TL431, desoldering the 2k2 resistor, and using the correct pad (not the 5V one) to solder a wire to your DAC, feeding the control voltage with a 82k resistor. This forms a voltage divider with the 220k resistor to convert 3.3V into 2.5V.

Then the DAC ground needs to be connected to the XL4016 module ground which is IN-, not OUT- which is on the other side of the current sense resistor.

Do not connect OUT- to IN- as this would bypass the current sense resistor and the circuit would no longer be able to control current.

If the module worked as constant current source then this should work fine. The voltage setting pot will just set the maximum output voltage. The current setting pot will work as gain, allowing you to set the maximum output current when your DAC outputs 3V3. Looks convenient.

• Thanks @bobflux for the detailed reply. I've edited the post to include some more information on the use case. I see what you mean about the flaw with switching on, and 12V spikes, fortunately it is only powering a peltier module rated for 12V, so I don't anticipate that being a problem. Based on the new information, any suggestions welcome, particularly if there is a current output DAC (ideally built in a module like my MCP7425, rather than standlone - too advanced for me to build entirely). Commented Aug 4 at 19:29
• OK good! I edited the answer with a simpler way to do what you want. Commented Aug 4 at 20:07
• Have successfully implemented your plan today and it works a treat! Thank you very much for the time you took in giving a detailed answer. Must say those tiny SMD components were the smallest things I've ever soldered. Commented Aug 10 at 9:58
• Excellent news! Thanks for the feedback! Commented Aug 10 at 11:59

EDIT: I have done a test in the breadboard with a similar buck converter module. This configuration seems to work.

With Vdac between 2V and 5V you get 4V to 10V in Vout. It can be adjusted with the voltage divider R4,R5.

Sweping Vdac voltage, Vout changes smoothly.

The buck module I test is based in the AP3503F IC. What I did is connect the output of the opamp directly to the FB pin of the IC in the board. I also removed the resistors of the existing voltage divider, but I think that is not necessary. And DAC is actually a potentiometer set as voltage divider, for testing.

There was some rippling above 7V, about 200mV, I think that because the inductor in the module is only 4R7, that is recommended for 3.3V output in the datasheet. But with a capacitor of 22µF the ripple is removed.

EDIT: My initial answer was not correct. I have removed it.

• You've drawn an oscillator -- the loop gain between an op-amp (>80dB at DC) plus the internal error amp (no idea, maybe 60dB+?) and doubling of phase shift ensures instability. Commented Aug 4 at 16:19
• Well, maybe you are right. But I did something very similar, but taking the voltage of a shunt resistor in the low side, and it worked fine. If this is not correct I'll delete it.
– Gos
Commented Aug 4 at 16:25
• An op-amp driving the internal gain/compensation node (if so provided) can do that, and occasionally one gets away with it (to FB instead of COMP) for current feedback; I don't doubt offhand that you might've had a stable result, but I suspect there are more differences between your system and this one than you realize. Put another way: there is more nuance in the system than a two-sentence answer can express, so readers would be wise to doubt the veracity of such an answer. These critiques can be addressed by explaining where your experience is coming from (and how it might not apply here), Commented Aug 4 at 16:36
• or by editing the circuit (and formula) to a version without stability issues (e.g., using a fixed-gain summing amp rather than an open-loop op-amp; in the case where no amplification or inversion is required, this reduces to the resistor network in the OP). Commented Aug 4 at 16:36
• You are right, what I did was different. Anyway I have done a quick test based on that, also for my understanding, and edited the answer. This way seems to work. The DAC voltage is not mapped, just to quickly test. But I'm not sure if this is correct or a good idea. Otherwise maybe is better to delete the comment.
– Gos
Commented Aug 4 at 17:40

From TS: "The DAC in this case always going to act as a current sink?"

No, the DAC will always act as a current source.

Ignoring R3, select R1 and R2 to give 1/2 the desired maximum output voltage.

With a DAC voltage of 0V, select the value of R3 in parallel with R2 to give the desired maximum output voltage.

Then the DAC voltage will adjust the output voltage, with 0V giving the maximum output, 1.25V (equal to reference voltage) give 1/2 the maximum output, and twice the reference voltage (2.5V) giving zero output

(See example LTspice sim below for 20V maximum output with a converter that has a 2.2V reference voltage).

You don't need an added op amp.

• If the DAC output is below +1.25V, then it's sinking current. Commented Aug 4 at 17:38
• That is true. My mistake. Commented Aug 5 at 13:32