How do PSU achieve V/I control digitally ??? - Page 1
Forum section: electronics / projects

author: Swaroop 21
author_rank: Regular Contributor
timestamp: August 03, 2024, 01:34:49 pm
content: I have watched multiple videos of Dave taking apart lab PSU's, he always talks about the ADC which is used to measure voltage and Current and always wondered how do these precision PSU achieves digitally controlled voltage and current regulation over a wide range of voltage. Hence I suspected DACs but never saw Dave showing the DACs. I am interested in how they achieve that precision with a wide voltage range from 0-30 etc.

author: Andy Chee
author_rank: Super Contributor
timestamp: August 03, 2024, 02:00:43 pm
content: PSUs don't usually use DAC like in audio equipment.Most switchmode PSUs will use PWM control, with duty cycle control from 0% to 100%.PSUs could potentially use DAC, but it would likely be a microprocessor internal peripheral, not an external DAC chip.

author: Swaroop 21
author_rank: Regular Contributor
timestamp: August 03, 2024, 02:58:31 pm
content: won't the pwm create noise ?

author: thephil
author_rank: Regular Contributor
timestamp: August 03, 2024, 03:37:57 pm
content: Is sure does. SMPS are notorious for being noisy. Linear power supplies, on the other hand, use a mix of multiple transformer taps and linear regulators to control the voltage.

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 03, 2024, 04:50:35 pm
content: Quote from: Swaroop 21 on August 03, 2024, 02:58:31 pmWhen controlling a linear regulator the PWM signal is filtered to a stable DC level and the regulator will have some level of noise suppression on it's regulation input.All that is needed is a voltage controlled current source to set the constant current and a voltage controlled voltage regulator to set the constant voltage. You can search for schematics on the net and see how it can be done.Basically a DAC can easily be made with a PWM signal and a low pass filter. The lower the cutoff point of the filter and the higher the carrier frequency the less noise will come through.Switched mode power supplies are a different story all together. There the PWM is used to control the system under load and not to set the actual output voltage or current. The feedback signal is used for that and to make it variable either a potentiometer is used in the feedback loop or an extra voltage is injected into the feedback point.Quote from: thephil on August 03, 2024, 03:37:57 pmFor an adjustable output voltage on a laboratory power supply there is no direct need for multiple transformer taps. Just a single heavy duty linear regulator to control the output voltage over a wide range.

author: thephil
author_rank: Regular Contributor
timestamp: August 03, 2024, 05:35:37 pm
content: Quote from: pcprogrammer on August 03, 2024, 04:50:35 pmOf course, you can stick with a large regulator, but the mix is what most lab power supplies use. Using different taps dissipates a lot less heat than relying on a big fat regulator.

author: Faranight
author_rank: Unknown
timestamp: August 03, 2024, 06:44:39 pm
content: Quote from: Swaroop 21 on August 03, 2024, 02:58:31 pmSpread spectrum PWM PMIC's are sometimes used to reduce noise and harmonics.

author: PGPG
author_rank: Frequent Contributor
timestamp: August 04, 2024, 12:32:31 am
content: Quote from: Swaroop 21 on August 03, 2024, 01:34:49 pmYou didn't said what precision?Short search for laboratory supply gives me some with 30.00 at their display. 12 bit converter gives you 4096 results so it is enough to have 30V source with 0.01V precision and 12 bit ADC is nothing unusual.

author: Swaroop 21
author_rank: Regular Contributor
timestamp: August 04, 2024, 05:23:23 am
content: by precision I mean they achieve 10mV 100mV resolution steps to adjust

author: Swaroop 21
author_rank: Regular Contributor
timestamp: August 04, 2024, 05:39:40 am
content: Are there any application guides or something for RC pwm filter ? For example if I wanna use STM32 which has 16-Bit PWM etc ?

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 04, 2024, 05:56:20 am
content: Quote from: Swaroop 21 on August 04, 2024, 05:39:40 amA simple single order RC filter with a very low cutoff point can be used. The downside is slower response to change of the voltage, but for a power supply it probably will be ok. Just experiment a bit.Try it with a 150K resistor and a 10uF capacitor and see what it does. Cutoff point is ~1Hz so change stabilization time is ~1s. If this is to slow lower the resistor or the capacitor value.The carrier frequency of the PWM on the STM32??? won't be super high in 16 bit mode, depending of the type and the max main clock frequency, but will certainly do for something like this.

author: Swaroop 21
author_rank: Regular Contributor
timestamp: August 04, 2024, 10:47:50 am
content: With stm32f401ccu6 (Black Pill) the pwm frequency with 16-Bit is around 1.2Khz and 20.5Khz at 12 Bit mode.How will the frequency affect the working i.e Higher frequency / Lower frequency ??

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 04, 2024, 11:10:41 am
content: Quote from: Swaroop 21 on August 04, 2024, 10:47:50 amThe amount of ripple in the voltage after the filter will vary based on the frequency but the load of the circuit behind the filter also plays a role in this.You can experiment with this when you have an oscilloscope and monitor both the input and the output of the filter.

author: Swaroop 21
author_rank: Regular Contributor
timestamp: August 04, 2024, 11:32:55 am
content: I don't have a scope but I will try to simulate it. But even if I get the PWM to analog voltage how do I control the main power elements, voltage regulation and current regulation ?If I have a switching tracking pre-reg or even just a normal switching or linear element how do i control that with this limited voltage of 0 - 3.3V ?? I also have those MCP4725 12-Bit DACs but I don't know how to control the main element with their limited output of 5V or 3.3V. The feed back pins of switching or linear regulators are usually just a few volts so how will the PWM or the DAC output voltage correspond to the regulators feedback ?? This is what I am actually interested in so I can to my further work on a wirelessly controlled PSU. I am not that concerned about the super high resolution even 10mV or 100mV resolution will do also I don't care that much about the settling time just want it to be responsive enough.Going off topic here but I have a 48V Meanwell Supply which can go up to 52V so I am planning to hookup a buck converter and after which I will put my linear regulator and the buck converter will be offset by a few volts. But I can't get my head around how to control the feedback of this regulation digitally.

author: tszaboo
author_rank: Super Contributor
timestamp: August 04, 2024, 11:36:30 am
content: Quote from: Faranight on August 03, 2024, 06:44:39 pmIn which case the noise is still there but you smear it all over the spectrum, tricking measuring equipment to pass EMC/CE/FCC certifications.It's the electronics equivalent of Dieselgate IMHO.

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 04, 2024, 12:09:05 pm
content: Maybe reading something foundherewill help improve your understanding.One hint on how to regulate a buck or boost converter with an "external" voltage is, mix the feedback voltage with the external voltage by simply connecting the external voltage via a resistor to the feedback input pin. Output voltage will vary when the external voltage varies.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: August 04, 2024, 01:10:09 pm
content: Why not, you sure can!Even made one myself:Basic design is a discrete analog phase-interleave CC/CV control, with 0-5V range inputs, that are driven from a pair of MCP4922s; outputs are measured with a MCP3208. Header has 5V and SPI on it. (Well, one channel is phase interleave, the other is single phase. Hence the two input and two output terminal blocks, and the pair of dual DACs.)With an MCU instead, there are many options:- Many have an onboard DAC, that can be wired directly to a circuit as above.- Timers are ubiquitous; generating PWM into a filter makes a simple if slow DAC.- PWM can be passed direct to the inverter (open loop or slow closed loop) -- probably dangerous, not very responsive, but who knows?- Same, but with a protective latch (e.g. peak current mode control) plus per-cycle interrupt doing PID control -- basic protections in place, safer, but still subject to software error.- If elaborate configurable logic is available, the better part of a hardware digital control could be built (more likely a full FPGA though).- There are also some more specialized SMPS MCUs out there; I recall MCP has a PIC integrated with a peak-current-mode latch and gate driver, something like that.These would be hard to tell apart at a glance; the additional analog bits (filter), presence of SMPS controller, etc. would be the tip-off, but tracing much of the circuit may be necessary to identify the scheme.Digital controls are tricky to get right. Like, the last one I made was rather noisy; although it was a frequency-shift resonant control, and the dithering of that can contribute a lot more noise than other types might, but maybe it had to do with my sample timing, how I smoothed samples out to reduce ripple, etc., or just the natural tendency towards chaos that these systems can have. But it only needed to be stable over say 10s of ms, so the modest cycle-to-cycle variations average out, and I didn't have reason to investigate further.A basic buck converter with peak current control should be pretty easy to get within a few LSBs of correct (of whatever part of the control loop has the least ENOB; perhaps the current-setting DAC?), and then regulating output voltage and current to implement CC/CV operating region is just a slower PID loop.But I would actively discourage developing digital controls, until one knows absolutely everything that they are doing. Software hasexponentiallycombinatoriallymore ways of failing than analog circuits do. Using ICs as building blocks (SMPS controllers, etc.), you at least have some confidence that they tested that chip, if not exhaustively, then well enough to commit to the expense of tapeout and masks. For my part, I don't consider my above mentioned control particularly reliable -- itseems to workbut I have no way to truly test it, I have no illusions that it is infallible and reliable, that there aren't weird logic latchups, arithmetic errors, etc. in it, or that the platform itself is at all reliable (it seems to behave according to the datasheet/manual -- but how do youprovethat?)."Hardware eventually fails; software eventually works" - Michael HartungThat is, hardware can be correct once, at design/manufacture time, and go until its very atoms cease to cooperate (which, can be sooner than later, but "later" can be very long indeed). Software, after infinite updates, may eventually accomplish the thing that it was originally intended to, but I would go one further and say that software need never "work" at all, because in many projects, the priority is on more features, not less bugs.Others may not share my caution about software, and especially among say cheap power supplies, where the pressure is to knock out something quickly, tested only to work in the average case -- who knows. It's probably a good idea not to connect anything to such a power supply that is worth more than the supply, and not easily repaired in case of gross supply voltage mismatch.Tim

author: T3sl4co1l
author_rank: Super Contributor
timestamp: August 04, 2024, 01:16:22 pm
content: Quote from: tszaboo on August 04, 2024, 11:36:30 amThis is extremely disingenuous, if not outright insulting.The equivalent would be, somehow synchronizing the EUT with the analyzer sweep, so that the spectrum is spread exactlyaroundwhere the analyzer is looking at any given time.This would be very hard to arrange, at just any lab, but if you self-qualify, or just schmooze enough with a shady lab, I suppose you could pull it off."Dieselgate" was due to an extremely precisely defined and consistent test, easily gamed by watching for that program of steps; the perfect setup for an intentional bad-faith exploitation of that test. It's like playing Simon Says from a fixed written and agreed-upon script, that one could simply rehearse, no RNG or other variation involved.Don't accuse us of participating in such bad-faith actions.Tim

author: Kleinstein
author_rank: Super Contributor
timestamp: August 04, 2024, 01:36:35 pm
content: There are µCs with festures to specially support SMPS control. They than include provisions for peak current limits and other extra features. While some parts are a bit easier analog, others (like anti-wind up) are easier done digital. A difficulty with digital control is that the noise / stability is limited by the ADC. This makes it difficult to get very low noise, but a SMPS is usually a bit more noisy anyway. Especially for high power large systems the digital control can still make sense, as the switching frequency tends to be not that high and it is more about getting close to the limits set by that frequency. There can also be added functions for protection / start up.The normal lab supplies use analog control and just set the set points via DACs (including a PWM DAC of some type from cheap to highly linear).

author: Andy Chee
author_rank: Super Contributor
timestamp: August 04, 2024, 02:01:08 pm
content: Quote from: Swaroop 21 on August 04, 2024, 11:32:55 amThe PWM or DAC from a microcontroller may be 0-3.3V, but a simple opamp buffer can scale it to any voltage you need.If you have a specific example then please provide a schematic or block diagram. Otherwise my basic design for a 12F675 controlled LM317 power supply may confuse you when applied to your proposed project.Quote from: Swaroop 21 on August 04, 2024, 11:32:55 amThis sentence is not an engineering design specification.

author: tszaboo
author_rank: Super Contributor
timestamp: August 04, 2024, 06:03:23 pm
content: Quote from: T3sl4co1l on August 04, 2024, 01:16:22 pmFew facts. Spread spectrum doesn't actually reduce the noise. They do it to actually save money on the input filtering, see example belowhttps://www.ti.com/lit/an/slyt809/slyt809.pdfQuoteOh we got less peaks because the spectrum analyzer doesn't show one very big peak, but several small ones, less reduce input filteringLook at all the examples in the paper, noise was never actually reduced, just several smaller peaks are recorded instead of one big.Also the RBW settings of tests like IEC 61000 are well known and standardized, and it's easy to overcome with these software techniques. You don't need to synchronize it, just make sure to place the several smaller peaks sufficiently apart (RBW apart).It's a great example of following the letter of a law (stay below this emission line on a spectrum analyzer) while having complete disregard to the intention of the law (actually reduce EMI emissions).

author: T3sl4co1l
author_rank: Super Contributor
timestamp: August 04, 2024, 08:54:43 pm
content: Quote from: tszaboo on August 04, 2024, 06:03:23 pmSo? Radio receivers are narrow band. You've made no case here.Worse, you've not explained your accusation against EMC professionals. I have no recourse to but assume you meant it. Kindly fuck off, then.Tim

author: Swaroop 21
author_rank: Regular Contributor
timestamp: August 05, 2024, 06:42:50 am
content: Quote from: Andy Chee on August 04, 2024, 02:01:08 pmI haven't created any block diagram or such also I am not so concerned about the ripple, noise etc. as this is just an Idea for a DIY power supply. I am looking for the control section how it works. All the replies did help me clear my doubts. If you are ok with sharing your PIC and LM317 design. I will try to understand it.I got a example which relates to my idea:https://www.instructables.com/DIgital-Controlled-Bench-Power-Supply/

author: Swaroop 21
author_rank: Regular Contributor
timestamp: August 05, 2024, 06:54:24 am
content: Quote from: pcprogrammer on August 04, 2024, 12:09:05 pmOkay, So that means basically superimposing the DAC output to the regulation feedback loop

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 05, 2024, 07:25:06 am
content: Quote from: Swaroop 21 on August 05, 2024, 06:54:24 amCorrect.

author: tszaboo
author_rank: Super Contributor
timestamp: August 05, 2024, 08:20:21 am
content: Quote from: T3sl4co1l on August 04, 2024, 08:54:43 pmHere are a few research papers with quantitative data on how spread spectrum increased BER in digital systems, or causes other issues:https://ieeexplore.ieee.org/document/8890636https://www.mdpi.com/2079-9292/9/1/60https://www.mdpi.com/2079-9292/10/12/1416https://ris.utwente.nl/ws/portalfiles/portal/268485429/2021_03_11_Rev10_L_EMC_PA_2020_.pdfI'm sure that you could find ample results that it improves EMC, and that it's good for AM radios. I'm not debating the effectiveness to improve the results in those cases. But I have an issue with the intention of the technique used instead of good system design. In large power converters proper filtering is costly, the parts used for them are large, and silicon is cheap. They utilize these to reduce system cost, and do it in the expense of emissions. A properly designed and filtered, shielded converter will emit less noise than an other one, filters omitted, and spread spectrum used to pass some tests. The first system is also going to cost more.Also I'm not appreciating the debate technique and language you are using.

author: adeuring
author_rank: Contributor
timestamp: August 08, 2024, 04:15:12 pm
content: I am tinkering with a slightly more complicated solution than what is described in the "instructables" page (https://www.instructables.com/DIgital-Controlled-Bench-Power-Supply/) mentioned by Swaroop, but it allows to set the output voltage to values smaller than the feedback voltage of the buck regulator IC. A PDF of the schematics is attached.The core idea is to use analog subtractors with two adding and one subtracting input to set the feedback voltage of the buck regulator. The main drawback: Calculating the resistance values of the subtractor's resistors is a bit complicated. Not really difficult IMHO, as there are only linear equations. But the number of variables in the equations makes it a bit hard for me to handle them just with pen and paper. So I used SymPy (https://www.sympy.org/en/index.html), mostly, because it is free software and because I am quite familiar woth Python. Many pther computer algebra systems (see for examplehttps://en.wikipedia.org/wiki/List_of_computer_algebra_systemsfor a list) are probably also suitable for transforming and solving simewhat unwieldy linear equations.Let me start with a more simple version of the circuit.Assume (1) that the feedback input of the buck regulator U1 is directly connected to the output of the opamp U3A, not to the output of U3C, and (2) that the resistor R7 is not connected to U3A. Then U3A operates as a "text book subtractor". The output voltage of U3A (labeled V_fb_cv in the schematics) isCode:V_fb_cv = a * V_out - b * VdacV (1)(VdacV is the voltage at the "minus input" of the subtractor, generated by DAC U5.)The values of the resistors R4, R5, R8, R9 determine the gains a and b.The "control mechanism" of the buck regulator U1 tries to keep the voltage at its FB pin (same as the output voltage of U3A) at a certain value. (The XL4015 uses 1.25V.)Hence we can see from the equation above that the output voltage of the buck regulator depends linearly on the voltage of the DAC:Code:V_out = (V_fb_cv + b * VdacV) / a (2)All voltages in the circuit are positive, so the minimum output voltage of the buck regulator isCode:V_out = V_fb_cv / a (3)(OK, this is only true if the lowest voltage the DAC can produce is 0V.)Problem is that the value of a also determines the maximum output voltage. If we want to set both the min and max voltage, we need a bit more: Another voltage that increases the output voltage of U3A so that it can reach the buck regulator's threshold voltage even for small output voltages of the buck regulator.This is what the voltage reference U4 (a TL431) and R7 are for. When these components are used, the output voltage of U3A becomes:Code:V_fb_cv = a * V_out - b * VdacV + c * Vref (4)I don't know how common opamp based analog subtractors with more than two inputs are in textbooks, so this is just an unproven claim for now. I'll derive the equation later, and I'll also show how the resistor values can be calcutated. But let me first further explain the general idea of the circuit.If the equation (4) is solved for V_out, it becomes:Code:V_out = (V_fb_cv + b * VdacV - c * Vref) / a (5)Now we have three parameters (a, b, c) that allow to set the minimum and maximum output voltages as desired. (Well, of course, within the limits of what's possible with the used components...)Side note: The XL4015 can generate output voltages as low as 0.1V or so, perhaps even less, provided that there is a minimal load connected. This is what the constant current drain Q1 and R17 is for: It ensures that there is always a current of ca 1mA. Note that Q1 must be a self-conducting FET. (I know that the symbol I used for Q1 in the schematics is wrong: The vertical dashed line should be a simple straight line for this kind of FET. I was just too lazy to search in Kicad for a more appropriate symbol or to draw one myself...)The same subtractor circuit and a another DAC can be used to control the maximum output current. That's the DAC U6, U3B as the subtractor and U2 as an instrumentation amplifier.The remaining stuff is more or less "textbook circuitry":The diodes D2, D4 "select", together with R14, the larger of the output voltages of U2A amd U2B. In other words, they implement the switch between constant current and constant voltage mode. U3C, D3 and R10 compensate the voltage drop across D2 and D4 and the non-linear voltage/current relation of these diodes. I am not sure if the stock 1N4148 are the best choice for this purpose. But I think it does not matter that much in this case: The circuit works quite well even if the FB pin of the buck regulator is directly connected to the cathodes of D2 and D4.Now a more detailed discussion of the subtractor consisting of U3A, R4, R5, R7, R8, R9.I'll assume, as usual, an ideal opamp, i.e. infinite gain, infinite impedance of the inputs, no bias voltages etc to make the calculation easier.R9 is the usual feedback resistor that ensures that the voltages at the opamp inputs are equal.Kirchhoff's current rule for the node where the negative input of the opamp U3A is connected:Code:0 = I_r8 + I_r9I_r8, I_r9 are the currents flowing through R8 and R9, respectively. Since the opamp inputs are assumed to have inifintely high impedance, we don't need a term for the current flowing into pin 2 of U3.These currents can be expressed by the resistances and the voltages across the resistors:Code:0 = (VdacV - V_op_minus) / R8 + (V_fb_cv - V_op_minus) / R9 (6)Kirchhoff's current rule applied to the node where the positive input of U3A is connected:Code:0 = (V_out - V_op_plus) / R4 + (V_offset - V_op_plus) / R7 + (V_gnd - V_op_plus) / R5(The voltage names may be a bit confusing: V_out is the output voltage of the buck regulator, not the output voltage of U3A - the latter is called V_fb_cv ...)V_gnd is zero, so we can simplify a bit:Code:0 = (V_out - V_op_plus) / R4 + (V_offset - V_op_plus) / R8 + (V_op_plus) / R5 (7)As written at the start, these equations are a bit too unwieldy for me without help from a CAS, so I'll use SymPy from now on.Start an interactive Python shell.Code:pythonPython 3.12.3 (main, Jul 31 2024, 17:43:48) [GCC 13.2.0] on linuxType "help", "copyright", "credits" or "license" for more information.Import the Sympy functions, classes etc.Code:>>> from sympy import *Define SymPy symbols for all variables in the equations (6) and (7).Code:>>> R4, R5, R7, R8, R9 = symbols('R4 R5 R7 R8 R9')>>> VdacV, V_op_minus, V_fb_cv = symbols('VdacV V_op_minus V_fb_cv')>>> V_out, V_op_plus, V_offset = symbols('V_out V_op_plus V_offset')Create SymPy objects for Kirchhoff's current equations (6) and (7), using the symbols defined above.Code:>>> eq6 = Eq(0, (VdacV - V_op_minus) / R8 + (V_fb_cv - V_op_minus) / R9)>>>>>> eq7 = Eq(0, (V_out - V_op_plus) / R4 + (V_offset - V_op_plus) / R7 - V_op_plus / R5)Solve equation (6) to get an expression for V_op_minus. (Note: The function returns a Python list to account for the situation that an equation has more than one solution. Since we have a simple linear equation, we can "blindly" select the first (and only) solution at index 0 of the list.)Code:>>> v_op_minus_expr = solve(eq6, V_op_minus)>>> pprint(v_op_minus_expr)$$\frac{R_{8} V_{fb cv} + R_{9} V_{dacV}}{R_{8} + R_{9}}$$The voltages at positive and the negative inputs of U3A are equal, so we can substitute the variable V_op_plus in eq7 with the expression v_op_minus_expr.Code:>>> subtractor_eq = eq7.subs(dict(V_op_plus=v_op_minus_expr))>>> pprint(subtractor_eq)$$0 = \frac{V_{offset} - \frac{R_{8} V_{fb cv} + R_{9} V_{dacV}}{R_{8} + R_{9}}}{R_{7}} - \frac{R_{8} V_{fb cv} + R_{9} V_{dacV}}{R_{5} \left(R_{8} + R_{9}\right)} + \frac{V_{out} - \frac{R_{8} V_{fb cv} + R_{9} V_{dacV}}{R_{8} + R_{9}}}{R_{4}}$$Solving this equation for V_fb_cv, the output voltage of the subtractor, shows the relation between output voltage, input voltages and resistor values.Code:>>> v_fb_cv_expr = solve(subtractor_eq, V_fb_cv)>>> pprint(v_fb_cv_expr)$$\frac{R_{4} R_{5} R_{8} V_{offset} - R_{4} R_{5} R_{9} V_{dacV} + R_{4} R_{5} R_{9} V_{offset} - R_{4} R_{7} R_{9} V_{dacV} + R_{5} R_{7} R_{8} V_{out} - R_{5} R_{7} R_{9} V_{dacV} + R_{5} R_{7} R_{9} V_{out}}{R_{8} \left(R_{4} R_{5} + R_{4} R_{7} + R_{5} R_{7}\right)}$$So the output voltage of the subtractor is indeed a linear function of the input voltages, but the coefficients a, b, c from equation (5) turn out to be somewhat convoluted looking combinations of R4, R5, R7, R8, R9. But it is not that difficult to let SymPy (or another CAS) calculate the resistances.First step: Specify the minimum and maximum output voltage of the buck regulator. Swaroop mentioned a voltage range 0V to 30V, so let's use these values.It is very unlikely that the following calculation will yield values for at least two of R4, R5, R7, R8, R9 that are close to resistances that appear in the stock E24 or even E48 series. One option is to use some potentiometers – but the last equation above shows that each resistance impacts the gain of all inputs. Hence the adjustment procedure will probably be quite fiddly/tedious/complicated.But the whole circuit is intended to be used together with a microcontroller, so we can do the calbration in software. So let's use a slightly extended voltage range of the buck regulator output in the calculation, say, -1V to 31V. These voltages shall be generated for the minimum and maximum DAC output voltages, respectively. My example schmatice uses an MCP4725, powered with 3.3V, so the min DAC output is 0V and the max value is 3.3V. (Yeah, the datasheet of the MCP4725 says that the max voltage is 3.3 * 4095/4096. But we can safely ignore this minor difference.)Next, the equations above contain two variables whose value is determined by components: V_offset is generated by U4, a TL431, so this variable can be replaced with the number 2.5 (for 2.5V). The XL4015 keeps the voltage at its feedback pin at 1.25V, so we also have a value for V_fb_cv.Let's substitute the two latter values in subtractor_eq:Code:>>> subtractor_eq_2 = subtractor_eq.subs(... dict(V_offset=Rational(25, 10), V_fb_cv=Rational(125, 100)))>>> pprint(subtractor_eq_2)$$0 = \frac{\frac{5}{2} - \frac{\frac{5 R_{8}}{4} + R_{9} V_{dacV}}{R_{8} + R_{9}}}{R_{7}} - \frac{\frac{5 R_{8}}{4} + R_{9} V_{dacV}}{R_{5} \left(R_{8} + R_{9}\right)} + \frac{V_{out} - \frac{\frac{5 R_{8}}{4} + R_{9} V_{dacV}}{R_{8} + R_{9}}}{R_{4}}$$(SymPy provides the class Rational. Using this class for numbers – or the class Integer where that makes sense – allows SymPy to perform more accurate calculations compared with the usual floating point numbers. Not that important in this case, but nevertheless nice.)Now we have an equation that describes the relation between the DAC output voltage (VdacV), the buck regulator output voltage (V_out) and five resistances.We already defined two constraints: VdacV = 0V -> V_out = -1V and VdacV = 3.3V -> V_out = 31V. But there is a third constraint that I did not notice at first: The voltage range at the inputs of U3A, which is sort of a "working range" of the feedback loop of the opamp: The DAC U4 determines the voltage at the negative input of the subtractor U3A and the buck regulator increases or decreases its outout voltage until the voltage at the positive input of U3A equals the volatge at the negative input. I did not yet delve deeper into the theory how the subtractor "integrates" into the feedback loop of the buck regulator, but simply assumed that it might be reasonable to let changes of VdacV have the same "impact" on the input voltages of U3A as changes of V_fb_cv. That's easy to calculate: Solve equation (6) for V_op_minus, this gives the relatively simple linear expressionCode:V_op_minus = VdacV * R9 / (R8 + R9) + V_fb_cv * (1 - R9 / (R8 + R9))Now let the "gains" R9 / (R8 + R9) and (1 - R9 / (R8 + R9)) be equal. The result is simple: R9 should have the same value as R8.Side note: One should also check that the input voltages are in the allowed common mode voltage range of the opamp. But this is the case in my circuit. The usual datasheets state that the input voltage can go down to the negative supply voltage and up to the positive supply voltage minus 1V. So the lower limit is not a problem. Since the supply voltage is 5V and since the DAC will produce less than 3.3V at the negative input, the common mode voltage range of the opamp is no concern here.This leaves us with four resistance values that need to be determined (R4, R5, R7, R8, R9, with R8 = R9) and two constraints.We can simply choose two values: Let R5, R8 and R9 be 100 kOhm. These values can be substituted in subtractor_eq_2Code:>>> subtractor_eq_3 = subtractor_eq_2.subs(... dict(R5=Integer(100_000), R8=Integer(100_000), R9=Integer(100_000)))>>> pprint(subtractor_eq_2)$$0 = - \frac{V_{dacV}}{200000} - \frac{1}{160000} + \frac{\frac{15}{8} - \frac{V_{dacV}}{2}}{R_{7}} + \frac{- \frac{V_{dacV}}{2} + V_{out} - \frac{5}{8}}{R_{4}}$$Now substitute the voltages of one constraint, VdacV = 0V -> V_out = -1V, in subtractor_eq_3 and solve this equation for one of the remaining unknown resistor values, R7:Code:>>> r7_equation = subtractor_eq_3.subs(dict(VdacV=Integer(0), V_out=Integer(-1)))>>> pprint(r7_equation)1 15 130 = - ────── + ──── - ────160000 8⋅R₇ 8⋅R₄$$0 = - \frac{1}{160000} + \frac{15}{8 R_{7}} - \frac{13}{8 R_{4}}$$Code:>>> r7_expr = solve(r7_equation, R7)>>> pprint(r7_expr)$$\frac{300000 R_{4}}{R_{4} + 260000}$$Now we can substitute VdacV and V_out with the values from the second constraint, VdacV = 3.3V -> V_out = 31V and r7 with the expression from the previous step.Code:>>> r4_equation = subtractor_eq_3.subs(... dict(VdacV=Rational(33, 10), V_out=Integer(31), R7 = r7_expr))>>> pprint(r4_equation)$$0 = - \frac{91}{4000000} + \frac{3 \left(R_{4} + 260000\right)}{4000000 R_{4}} + \frac{1149}{40 R_{4}}$$SymPy can solve this equation for R4:Code:>>> r4_value = solve(r4_equation, R4)>>> pprint(r4_value)$$\frac{14460000}{11}$$Code:>>> # R4 as a floating point number:>>> float(r4_value)1314545.4545454546Finally, we can insert r4_value into r7_expr to get the value of R7:Code:>>> r7_value = r7_expr.subs(dict(R4=r4_value))>>> pprint(r7_value)$$\frac{108450000}{433}$$Code:>>> float(r7_value)250461.89376443418Now let's see what the output voltage range is when we use standard resistor values: Set R4 to 1.3 MOhm and R7 to 240 kOhm.First we need to solve subtractor_eq for V_out.Code:>>> V_out_expr = solve(subtractor_eq, V_out)>>> pprint(V_out_expr)$$\frac{R_{4} R_{5} R_{8} V_{fb cv} - R_{4} R_{5} R_{8} V_{offset} + R_{4} R_{5} R_{9} V_{dacV} - R_{4} R_{5} R_{9} V_{offset} + R_{4} R_{7} R_{8} V_{fb cv} + R_{4} R_{7} R_{9} V_{dacV} + R_{5} R_{7} R_{8} V_{fb cv} + R_{5} R_{7} R_{9} V_{dacV}}{R_{5} R_{7} \left(R_{8} + R_{9}\right)}$$Now substitute the symbols for constant voltages and the resistor with specific values:Code:>>> V_out_expr_2 = V_out_expr.subs(dict(... V_fb_cv=Rational(125, 100),... V_offset=Rational(25, 10),... R4=Integer(1_300_000),... R5=Integer(100_000),... R7=Integer(240_000),... R8=Integer(100_000),... R9=Integer(100_000)))>>> pprint(V_out_expr_2)$$\frac{233 V_{dacV}}{24} - \frac{45}{32}$$Substitute VdacV with the min and max values:Code:>>> pprint(V_out_expr_2.subs(dict(VdacV=0)))$$- \frac{45}{32}$$Code:>>> float(V_out_expr_2.subs(dict(VdacV=0)))-1.40625>>> pprint(V_out_expr_2.subs(dict(VdacV=Rational(33, 10))))$$\frac{4901}{160}$$Code:>>> float(V_out_expr_2.subs(dict(VdacV=Rational(33, 10))))30.63125Some final steps would be to check the "impact" of the tolerances of the resistor values on the output voltage range and to calculate the step size of the buck regulator output voltage. I won't do this here – hopefully you got the idea how to do that with SymPy.Final remarks:In a sense this is a bit "design wankery". After all:1. Is it really so important to get small voltages out of a stock buck regulator chip?2. If the low buck regulator output voltage is important and if the usage of an analog subtractor and opamps in general look reasonable: One can avoid all the calculations above when the subtractor has the same gain for all its inputs. In this case the equations shown above become much simpler. The different gains required in this application can be implemented by using additional opamps. The LM324 is good enough for this application, it is cheap, so the cost increase should not be a concern.But for me it was fun to see if I can design a "minimalist subtractor" with SymPy.[Edit: replaced a duplicate definition of subtractor_eq_2 with a definition of subtracot_eq_3. Thanks to Swaroop for notifying me about this error.]

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 08, 2024, 04:53:49 pm
content: To keep in style with EEVblog.Dave Jones (the one without the squid face) is using an MCP4716 DAC to generate an analog output voltage. It is the easy (but more expensive) way out. PWM + filtering is also possible, but it need some attention to detail to the filtering to get to a stable DC voltage while still being quick enough to change the setpoints.https://www.eevblog.com/files/uSupplyBenchRevC.pdfIn these modern times, direct DAC's are more often used for programmable voltage references, but PWM based voltage references have been built in the past and these can have a 20bit or more accurate DC levels.I have done some experiments in this direction and it's not very difficult to get quite accurate DC levels with a fine resolution and low ripple in a simulation, but if you also want low noise and accurate DC levels, you also need an accurate voltage reference (which drives up the price) and PCB layout also becomes more important.For the current limit, Dave just does it in software in the uSupply, which will make the loop very slow. For a faster response, you can generate an analog voltage with a DAC (or PWM) and then use a comparator to compare the setpoint with the actual measured analog current.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: August 08, 2024, 05:12:46 pm
content: FYI, we have MathJax running here:$$ V_\text{out} = \frac{ V_{\text{fb}_\text{cv}} + b V_\text{dac} V }{ a } \tag{2} $$You might have LaTeX output from your CAS tool that can be easily pasted hereTim

author: Smokey
author_rank: Super Contributor
timestamp: August 08, 2024, 06:10:13 pm
content: For examples of digital microcontroller controlled supplies, look to motor controllers/inverters. They are essentially just big, high power, multi-channel, power supplies (or high bandwidth current sources depending on how you look at it).TI TMS320F DSP series has pretty much everything you need built in.

author: Swaroop 21
author_rank: Regular Contributor
timestamp: August 09, 2024, 03:53:57 am
content: Quote from: adeuring on August 08, 2024, 04:15:12 pmOhh Thank You so Much for the detailed explanation

author: Swaroop 21
author_rank: Regular Contributor
timestamp: August 09, 2024, 03:58:51 am
content: Quote from: Smokey on August 08, 2024, 06:10:13 pmProblem with using such DSPs is they are hard to get here locally in India. I would have to order them from Mouser or DigiKey which the shipping would cost me more than the actual DSP itself. Neither does AliExpress Ship to India. Hence I am stuck with using something which is available on the Websites in my country.STM32F401 Seems to be a good choice as it has 16-Bit PWM output with frequency of 1.1Khz. and is also pretty cheap about $3

author: Andy Chee
author_rank: Super Contributor
timestamp: August 09, 2024, 07:25:53 am
content: Quote from: Swaroop 21 on August 09, 2024, 03:58:51 amWhat websites are in your country? It would help us to see the part availability that you are stuck with.

author: Kleinstein
author_rank: Super Contributor
timestamp: August 09, 2024, 09:07:40 am
content: There are 2 different versions of digital "control".1) using some kind of DAC to create the set point votlages and use a linear regulator to do the actual control.This way is easy and would not need a specially good µC.2) using ADC to measure the actual current and voltage fast and with high resolution. This way not only needs a relatively fast µC, but also good ADCs. This version is more tricky and usually ends up with high noise. It may still be OK for a SMPS, that is a bit more noisy anyway.

author: Swaroop 21
author_rank: Regular Contributor
timestamp: August 10, 2024, 07:01:21 am
content: Quote from: Andy Chee on August 09, 2024, 07:25:53 amOnly a Few Trusted Websites:https://robu.in/https://electronicscomp.com/https://evelta.comhttps://quartzcomponents.comhttps://ktron.in/The 3rd Website "elvelta.com" is the only website with a few "exotic" Chips / Evaluation boards. Others are just basically jellybean components.Other way is to go to the local market Named Lamington Road also known as the "Electronics Hub of Mumbai". Would take many days to find in the stores here