CC/CV Benchtop Power Supply with a digital control loop. - Page 1
Forum section: electronics / projects

author: nike9307
author_rank: Contributor
timestamp: August 24, 2025, 07:14:53 pm
content: Hi all,I'd like to design a benchtop power supply with CC/CV with the following characteristics:- Vin USB C USB PD.- Vout 0-30V- Iout - 0-3A (5A is also optional)- Passive cooling or minimum active cooling - so switchmode PSU- Digital Control Loop, as in an MCU does the controller math.- Minimum ripple noise.I mostly want to experiment with the digital control loop concept, as i've never done it before and it looks like its would be fun.So far I'm partial to using the STM32G474 as it has fast ADCs, the FMAC co-processor for quicker 3p3z compensation, the high resolution timer and CCM RAM for qicker code execution during ISRs. Its an MCU family specifically designed for digital power control and it has cool peripherals to make it happen.I already got the B-G474E-DPOW1 dev kit and I've managed to get a normal constant voltage example working quite well on it. However I'm thinking about how i can get the constant current go work ok and more importantly how to switch between the CC and CV loops without overshooting like crazy. While I do get the math behind the CV control loop, I’m not quite sure how to get the CC control loop coefficients? Will they be the same as the one on the CV and just switch between the 2 loops outputs?If anyone can offer a good app note or a textbook (that’s not a full control theory textbook) or something regarding this, I’ll be grateful.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 24, 2025, 09:14:16 pm
content: Quote from: nike9307 on August 24, 2025, 07:14:53 pmThe CC/CV controller chips simply OR the control signal - examples : AP4306A,TL103,NCP4328

author: Marco
author_rank: Super Contributor
timestamp: August 24, 2025, 10:03:43 pm
content: You could copy the output part of dc2132a using two LT3081s, that design and the datasheet use a resistor to set the current limit, but it can be set with a separate current source too.

author: themadhippy
author_rank: Super Contributor
timestamp: August 24, 2025, 10:19:33 pm
content: might be worth taking a look at daves usupplyhttps://www.eevblog.com/projects/usupply/

author: nike9307
author_rank: Contributor
timestamp: August 25, 2025, 08:42:30 am
content: Guys, those are all analog control loops.I'm looking for the math to do it in a digital control loop - as in you put the voltage and current trough and ADC, get the digital signal into a micro, do the processing math inside the micro and then generate the PWM from the micro.

author: NE666
author_rank: Frequent Contributor
timestamp: August 25, 2025, 08:56:06 am
content: Doing it in the digital domain might be an interesting theory exercise but in terms of practical results, I imagine that the regulation will compare poorly to conventional analogue control.'Analog computers' have their uses.

author: ledtester
author_rank: Super Contributor
timestamp: August 25, 2025, 10:21:37 am
content: This was just discussed last month...https://www.eevblog.com/forum/microcontrollers/sensible-to-use-a-mcu-for-a-switching-(or-even-a-linear)-power-supply/

author: oz2cpu
author_rank: Frequent Contributor
timestamp: August 25, 2025, 10:54:44 am
content: today ADC DAC and PWMdigital control got all the speed and resolution needed, so it is clearly possible,if that is what you want, go for it , do it, tell us about it,you will have fun, and learn a lot,

author: Marco
author_rank: Super Contributor
timestamp: August 25, 2025, 12:45:06 pm
content: Quote from: oz2cpu on August 25, 2025, 10:54:44 amWith a micro with fast comparators, you could also do a hybrid. Digital control loop for PWM, then if voltage/current exceeds limits use the comparators for pulse skipping (or a crowbar if you really want to stop the current fast). For when you really want those 10 extra microseconds of response time.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 25, 2025, 01:50:22 pm
content: I like the idea of designing your own power supply, but why go for 30V 3A? That makes it a quite ambitious project, getting rid of heat is a problem, and this also significantly drives up the cost (transformer, heatsink power devices). And you will definitely learn from it, but that does not mean that the end result will be a usable product.And besides, a 30V 3A power supply is boring, You can get them for EUR 100. (most are SMPS, but some such as the Korad are linear, even for that price range).I recommend to start with a smaller project. Even a power supply of 7 or so volts and 500mA is plenty to power a lot of microcontroller projects. And instead of going higher power, you can go to greater accuracy. This allows you do do power measurements for if you have projects that are to be powered by a battery later. Or you can use it as a programmable reference / calibration voltage.And what do you consider a "digital control loop". I've seen some designs (such as the Tuxgraphics) that have a simple power stage with a discrete BJT amplifier (applause for that), but this stage sags under load, and this needs adjustment via an ADC and DAC to keep the voltage steady. Such a control loop is quite slow (although you can get uC's with ADC and DAC of a few MHz these days).I consider LT1081 "cheating". Sure, it's easy to design with, but I don't like the price of that part considering it's mostly a glorified transistor / buffer. It can be the right part (its' apparently quite low noise, but how does that compare to a BJT? I would be more inclined to use an audio amplifier such as the TDA2050 (unfortunately obsolete) or the LM3886 or TDA7294. This also allows for a two (or 4) quadrant power supply, which can also be used as a (programmable) load or battery simulator.Quote from: oz2cpu on August 25, 2025, 10:54:44 amPWM is already a DAC (with a filter) but slow. It can be quite accurate (and linear), but it's slowness makes it only usable to create a setpoint.ST has some uC's that are meant for digital control of an SMPS. It has high resolution timer outputs, and fast ADC's which can shut of (or modify?) the PWM in case of over current detection or other faults. Is that the direction you want to go in?Your opening post is quite vague, and there are many choices to be made. Can you describe a block schematic of the sort of power supply you want to build?

author: ifonlyeverything
author_rank: Regular Contributor
timestamp: August 25, 2025, 01:57:24 pm
content: Would a digital PID (rather than digital type II/III compensator) be better in a situation like this?I found this design by TI that implements CC/CV digitally with PID.https://www.ti.com/jp/lit/ug/tidub90a/tidub90a.pdf

author: d-el
author_rank: Regular Contributor
timestamp: August 25, 2025, 02:10:45 pm
content: I was thinking about this. To achieve the parameters of an average linear CC/CV regulator, need to have a sampling frequency of Analog->Digital and Digital->Analog about 1-5 MHz. At the same time, have a regulator with a voltage change rate of at least 10 V per 1 ms (better if it is faster). I think that a GAN FET Buck at a frequency of 1-5 MHz and a small integrating capacitance of about 30-60 μF can help here.Has the fast hardware part already been implemented?Next, you need to debug the current and voltage regulators separately. Make a significant margin for stability by sacrificing speed. And the last step is to integrate a selector of software regulators for the smallest voltage/current setpoint.I think that a good debugger for this task will be Simulink. In it, you can assemble a similar DC/DC and debug the regulators.

author: d-el
author_rank: Regular Contributor
timestamp: August 25, 2025, 02:16:48 pm
content: Quote from: ifonlyeverything on August 25, 2025, 01:57:24 pmThis TI project positions itself as a DSP control ready DC-DC (AC-DC) converter for charging a battery. For this task, high speed is not required, unlike a benchtop laboratory power supply.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 25, 2025, 03:11:50 pm
content: Quote from: nike9307 on August 25, 2025, 08:42:30 amAh, OK, so you want to run something like an PID loop to do the adjustment.This is unusual for a linear power supply, but it is used by some (such as the not so good Tuxgraphics), and there is also a EUR 10 Kit on Aliexpress (red PCB and HD44780 LCD). Software for this last one is really bad. but it''s an ATmega328, so it's a good experimenters platform, and for that price it's a nice start with only a kit to solder.For building it yourself, first thing to consider is what sort of output stage you want. You need to amplify the DAC output (which makes anlog feedback to the (most often used) opamp trivial). An IC like the LT3081 also has an internal control loop. So what drivers do you want? BJT, FET, or some IC?One of the simplest would be to connect the adjustment pin of an LM317 directly to a 5V DAC. That will give you an output range of 1.25V to 6.25V.If you use a BJT or FET, then the output will sag with increased output current, and you have to adjust for that in software too.So the next thing to consider is how fast does your control loop need to be? Its not such a huge thing for a battery charger, but it is more important for a bench top power supply. If you have an 1Msps ADC and a 1Msps DAC, and a bit of software to control it, then you have a loop delay of around 3 to 5us, and you probably need to iterate over your loop for 4 or moresamples, That gets you a closed loop with a time constant of around 10 to 20us, so a 50KHz loop. Much less then even a simple opamp, but it can be acceptable. Is that within your expectations?

author: Marco
author_rank: Super Contributor
timestamp: August 25, 2025, 03:12:21 pm
content: Quote from: ifonlyeverything on August 25, 2025, 01:57:24 pmThere is no significant lag time.If you know the voltage and load current, you can calculate exactly the necessary pulse width needed to hit your target voltage at the middle of the ripple if the load current stays constant. Why would you use anything else?

author: voltsandjolts
author_rank: Unknown
timestamp: August 25, 2025, 03:19:36 pm
content: Quote from: nike9307 on August 25, 2025, 08:42:30 amMay I suggest making a two quadrant psu, just to stand out from the crowd a little, and perhaps add more interest for you.

author: Marco
author_rank: Super Contributor
timestamp: August 25, 2025, 04:18:01 pm
content: A two quadrant PSU with a fully digital control loop would be a first I think.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 25, 2025, 04:19:54 pm
content: Quote from: voltsandjolts on August 25, 2025, 03:19:36 pmMy idea also (mentioned earlier audio amplifiers as example).A two quadrant power supply can also be easily turned into a four quadrant power supply, by simply changing the "GND" reference.If you start with a (IC or discrete, audio) AB amplifier, you can change the reference to either the positive, negative or center rail.With such a power supply (even if it's a small one such as 15V 200mA) it's also attractive to build at least two of them, so you can use them to power circuits with a symmetrical power supply, or use them as poor man's SMU's and do things like transistor curve tracers in software.There really are very many directions in which you can take a project like this. So what direction do you want to go?Building a bog standard 30V 3A power supply is both the least interesting and more expensive options. Also consider you're likely to blow up a bunch of end stages during design, and debugging. That's yet another reason to start with something more modest.

author: nike9307
author_rank: Contributor
timestamp: August 25, 2025, 06:33:41 pm
content: Damn that got way more responses than i imagined. Ok here goes. I'm answering in no particular order.Quote from: NE666 on August 25, 2025, 08:56:06 amI have tried in on a small scale with the dev kit i mentioned. The MOSFET driving circuit in that is quite basic, so i drive the transistors at a fairly slow 200Khz and i have designed the 3p3z compensator to a crossover frequency of 8Khz. It works quite well with those parameters. For the full version I'm planning to go to 1Mhz switching frequency and a crossover of at least 50Khz. This is quite a good result to be honest. Just a few years ago we were using worse off the shelf DC-DC convertors.And yes when i use all of the CPU peripherals like the FMAC and the CCM RAM, i'll be able to do the control look in 1uS during the IRQ of the ADC. This is why i got the dev kit, so i can test this.Quote from: ledtester on August 25, 2025, 10:21:37 amThank you. That is a good discussion and i did read it before posting, but it didn't answer my original question.Quote from: ifonlyeverything on August 25, 2025, 01:57:24 pmI tried both on the dev kit. 3p3z tends to be quicker and that also tracks with others who've done testing like that.Quote from: d-el on August 25, 2025, 02:10:45 pmI've not used Simulink in almost 10 years. Basically since i finished Uni. Has it gotten any more user friendly since then? Up untill now i was looking at this tool to generate the coefficients -https://biricha.com/tools-and-downloads/st/and i read again some control theory to remember what the math was around control loops and how to tune them.Quote from: voltsandjolts on August 25, 2025, 03:19:36 pmThat would be pretty darn sweet to be fair. However that would require a huge heatsink to sink current - aka an electronic load. At that point it would be closer to an SMU. SMUs tend to be quite bulky and i'm aiming for small size. And yes 30V/3A is kind of boring, but there's a reason why its an "industry standard" - its very usable. I have like 5 supplies that are 30V 3A and i use them dail. I can get by with them for most projects. I just want a smaller version for home use and i want to explore tech I've not had the chance to.

author: Marco
author_rank: Super Contributor
timestamp: August 25, 2025, 07:05:49 pm
content: Quote from: nike9307 on August 25, 2025, 06:33:41 pmCould use a micro-inverter and feed it back into the grid

author: voltsandjolts
author_rank: Unknown
timestamp: August 25, 2025, 07:10:04 pm
content: Quote from: Marco on August 25, 2025, 07:05:49 pmYeh, I've been pricing some ITech psu's that do exactly that. Nice trick.

author: nike9307
author_rank: Contributor
timestamp: August 25, 2025, 07:14:07 pm
content: Quote from: Marco on August 25, 2025, 07:05:49 pmThat is a pretty cool idea. I wounder why off the shelf SMUs dont do it? Probably something to do with the grid messing with the performance? I'd have to think more on this question.Anyhow, this would require to get power line level voltages to the small case i've closen. While it may be possible, i'm not sure its apt for a project i'll be working on in my spare time. I want to explore new concepts for me, in a reasnable time frame.

author: Marco
author_rank: Super Contributor
timestamp: August 25, 2025, 07:21:06 pm
content: There's only a few countries where it's 100% legal to use a small feed back inverter on a normal socket. Germany is one.

author: nike9307
author_rank: Contributor
timestamp: August 25, 2025, 07:50:10 pm
content: Oh yes, you could injure or kill someone working on the powerlines while he thought the power is down/he removed the fuse. Good point.

author: dzwer
author_rank: Contributor
timestamp: August 25, 2025, 08:04:29 pm
content: There are MCUs for this purpose, like this:https://www.st.com/en/evaluation-tools/32f3348discovery.htmlHere is some useful info:https://tech-en.netlify.app/articles/en508768/index.html

author: Marco
author_rank: Super Contributor
timestamp: August 25, 2025, 08:04:49 pm
content: The micro-inverters have anti-islanding, that's not the problem.But a section of the circuit could see the additive current of the fuse value and the inverter feed in ... and that suddenly sends electricians with OCD into a tizzy.

author: nike9307
author_rank: Contributor
timestamp: August 25, 2025, 08:17:09 pm
content: Quote from: dzwer on August 25, 2025, 08:04:29 pmI'm actually looking at using the F334's bigger brother the G474. It has similar peripherals, but its newer and it runs at higher clock rater. The article is interesting. He just switches between the CC and CV loops and hopes to get a good enough edge response. I guess i'll try making something similar and see how well it works out on my setup. Thans you dzwer

author: nike9307
author_rank: Contributor
timestamp: August 25, 2025, 08:20:02 pm
content: Quote from: Marco on August 25, 2025, 08:04:49 pmMakes sense. Still I'd prefer to not make illegal stuff by accident, since i dont know the law around this where i live.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 26, 2025, 05:02:26 am
content: Quote from: nike9307 on August 25, 2025, 08:17:09 pmYou should at least have a power output stage with a hardware current limit design, one that keeps peak currents legal.That covers sudden short circuits and abrupt overloads (like something failing on the bench!) in hardware.It's only a small step from there to define a DAC defined upper current setpoint, which the protection hardware at least respects, you can always operate just under that with your control loops.