USB-C For Hackers: Build Your Own PSU

What if you wanted to build your own USB-C PSU? Good news – it’s easy enough! If you ever wanted to retrofit a decent DC PSU of yours to the USB-C standard, say, you got a Lenovo/HP/Dell 19V-20V charger brick and you’ve ever wished it were USB-C, today is the day when we do exactly that. To be fair, we will cheat a bit – but only a tiny bit, we won’t be deviating too much from the specification! And, to begin with, I’ll show you some exceptionally easy ways that you can turn your DC PSU into a USB-C compatible one, with a simple module or a few.

Turning a 20 V PSU into a USB-C PSU feels natural if you want to charge a laptop – those tend to request 20 V from a USB-C PSU anyway, so what’s the big deal? However, you can’t just put 20 V onto a USB-C connector – you have to add a fair bit of extra logic to make your newly christened USB-C PSU safe to use with 5 V devices, and this logic also requires you go through a few extra steps before 20 V appears on VBUS. Any USB-C PSU has to output 5 V first and foremost whenever a device is connected, up until a higher voltage is negotiated digitally, and the PSU may only switch to a higher voltage output when it’s requested to do so.

Now, for that, a PSU offers a list of profiles, and we looked into those profiles in the Replying PD article – each profile is four bytes that contain information about the profile voltage, maximum current that the device may draw at that voltage, and a few other details. For a PSU to be USB-C compliant, the USB-C specification says that, in addition to 5 V, you may also offer 9 V, 15 V, and 20 V.

Also, the specification says that if a PSU supports certain in-spec voltage like 15 V, it’s also required by the spec to offer all of the spec-defined voltages below the maximum one – for 15 V, that also requires supporting 9 V. Both of these are UX requirements, as opposed to technical requirements – it’s easier for device and PSU manufacturers to work with a small set of pre-defined voltages that majority of the chargers will support, but in reality, you can actually offer any voltage you want in the PSU advertisement; at worst, a device is going to refuse and contend with slowly charging from the 5 V output that you’re required to produce.

I’d like to walk you through how off-the-shelf USB-C PSUs work, all of the options you can use to to create one, and then, let’s build our own USB-C PSU from scratch!

All The Off-The-Shelf Options

These few caveats are already baked into USB-C PSUs. After all, with modern controller chips, it doesn’t take much to add USB-C output support to a generic PSU during manufacturing – all you really need is to use a PD controller IC that ties into the PSU’s feedback line, adds an inline current sensor, and controls a MOSFET to switch the power on and off, and this IC also takes care of the USB-C rules and regulations. With the FB pin under its control, the PD controller takes over the PSU’s output voltage regulation process and make the PSU output any voltage it could ever want, within reason.

This made it easy for manufacturers to produce USB-C PSUs – instead of wiring up the FB signal of your SMPS to a voltage divider like you normally would, you just wire it up to a separate block that does the whole PD part, wire that block to a USB-C PSU, and you’re golden! If you want to buy a reliable 12 V / 3 A PSU for your project, instead of working with barrel jack PSUs, it’s becoming way easier and cheaper to just buy a USB-C PSU and a trigger board.

As a benefit, by adjusting the PSUs feedback line, you can get all the intermediate voltages you could want – so, PSU makers don’t have to limit themselves to weird static voltages like 7.5 V and 11 V anymore. This last part also means that features like PPS (variable voltage and CC/CV) support are not about the way your PSU is built specifically, but merely about whether the PD controller IC in your PSU supports it – and the new generations of PSU-side PD controller ICs tend to support PPS by default, which means that finding a USB-C charger with PPS is soon going to become trivial, if it already isn’t.

Nowadays, there’s a number of such ICs on the market that you can use to seamlessly convert an old or new PSU design to USB-C, just by tapping into the feedback line inside the PSU, and you can get these ICs from Eastern and Western manufacturers alike. If you have an already-working DC PSU, however, you don’t have to disassemble it and solder a USB-C PSU module into the feedback input – there are more and  modules on the market that take a DC input, have a small PD controller chip, and also a buck (or even buck/boost!) converter to produce all the USB-C voltages a device could need!

Such boards are basically the opposite-world version of a PD trigger module – instead of getting DC out of a PD port, you create a PD port out of a DC source, with a buck/boost conversion in the middle that makes the whole ordeal a bit less efficient than direct conversion, but still hits the bullseye. You can find these boards on Aliexpress, and you can still distinguish these boards from PD trigger boards because they’ll have a big inductor on them, something that PD trigger boards don’t need.

If you want keywords, I could find a fair few by using “PD charger module” and then checking the pictures for visible inductors. One small exception is LiIon chargers with USB-C PD input, but it should be easy to filter these out by checking the title for any Lithium-Ion chemistry keyword references.

In the same vein, if you don’t want to wait for the Aliexpress package and need a USB-C output in a pinch, you can get a USB-C car charger for a lighter socket, as long as it’s got higher than 5 V (15 W) output capability – if the label says it supports higher-than-5 V voltages on USB-C, you should be in the clear. They’re basically the same “PD charger” modules but packaged into a lighter socket adapter, expecting 12 V or 24 V but likely okay with voltages inbetween.

Both the lighter adapter and the Aliexpress options are very technologically similar to the native USB-C PSU option – you get a buck/boost converter with the same IC tapping into its FB signal, or even an all-things-contained IC that does everything for you if you just give it an inductor and a few other parts. But if feeding either 5 V or 20 V is all there is to your usecase, you can get even simpler than that!

Specification Versus Reality

If you think that your 20 V PSU should be able to simply put 20 V onto USB-C, or you want to avoid conversion inefficiencies, maybe you’d like to try to make the most straightforward PSU possible, there’s absolutely a way to do it all! In a USB-C PSU, you can technically limit yourself to 5 V and 20 V outputs, switching between them using FETs: if a device can’t work with a 20 V profile, it won’t request it, so you might not be able to charge your Nintendo Switch or smartphone at higher than 5 V, but it will be just right for a laptop. You can even offer custom voltages and leave it it up to devices to accept those! For instance, 12 V is not a voltage defined in the USB-C specifications, but half of PSUs on the market offer it nevertheless, purely because a large amount of the PD PSU controller ICs out there have 12 V programmed into them as an option. So, 12 V is more of a USB-C tradition than an actual profile, and yet devices work with it – it’s a mainstay on trigger boards, too!

Now, Dell has produced such an adapter, converting a Dell laptop PSU to a USB-C charger, switching between 5 V and 20 V with FETs. I’ve referenced this adapter in my Power Delivery article as the way to convert a DC PSU to USB-C, back when my USB-C knowledge was about 10% of what it is now. You can still buy these adapters, from either Dell or Aliexpress, and they’re an inspiration for what I propose we build!

Let’s build a DC PSU to USB-C PSU adapter that talks to USB-C devices and can offer its high voltage passthrough when they request it – efficient, hackable, and a learning opportunity. For that, you need this adapter to provide 5 V first, at a certain amount of current – but even that amount of current can be custom, you could theoretically offer 500 mA at 5 V and be done with it, so you don’t need to use too powerful of a buck regulator. I’m going to use an AP63200 switching regulator, which can produce up to 5 V / 2 A from a 20 V source.

You also want to make sure your 20 V is reasonably noise-free, as the USB-C standard has some requirements for that. I’m going to be using OEM laptop PSUs from HP/Dell/ Lenovo, which tend to be of good quality compared to off-brand copies. Also, you want to know your PSU’s current capability – USB-C devices have a responsibility to monitor and temper their current consumption, so a typical laptop charger will only consume 5 A if your PSU says it can deliver 5 A, but if you tell your device you can deliver 5 A when your 20 V PSU can’t, your device might happily try and draw 5 A, triggering the overcurrent protection in the PSU. Thankfully, with the HP/Dell/Lenovo triad, their chargers have a mechanism to communicate current consumption, and with a few extra GPIOs and ADCs, I can just use that to check what kind of current we can provide!

Fast, Exact Transitions

The FET arrangement we need to switch between 5 V and 20 V output implies some requirements – you don’t want 20 V backfeeding into 5 V, and you also want the FETs to handle 3 A – 5 A of current through without breaking a sweat. When switching between 20 V and 5 V, you also want to make sure that 5 V power is not interrupted – the transition between 5 V and 20 V has to be reasonably smooth, without losing VCC. I’m going to use SI4909DY FETs, a pair of P-FETs in comfortable SO8, one pair for 5 V use and one for 20 V use, trying and keep the FETs gate voltage at about 10 V max, since that’s where the datasheet says these FETs work optimally. Let’s go through the wiring, which has some nuances – mind you, you can’t afford to feed 20 V into your 5 V rail!

You could use an ideal diode circuit of some sort for backfeeding prevention purpose, but I’ll use a pair of back-to-back FETs driven by NPN transistors, with two separate control GPIOs. For 20 V, I’ll use two FETs connected in parallel – that decreases Rds and heat dissipation; remember, as a rule, FETs in parallel balance each other and spread the current equally between themselves! I’m going to wire up one SI4909DY pair in series for 5 V use, and another with both FETs in parallel for 20 V use.

When I first built this circuit, I put the 20 V FETs back-to-back too, thinking that I’d add a protection mechanism in case one of the FETs got shorted, but they ended up dissipating too much power. So, instead, I’m adding a boot-time VBUS measurement check into the code, that will make the PSU shut down and show an error message in case the 20 V or 5 V FETs get shorted out.

Our PSU needs to support three states – no VBUS on its USB-C output port, 5 V VBUS output, and 20 V VBUS output. Here’s a diagram of how you can achieve these three states with four FETs, isolating VBUS from both the 5 V source and the 20 V source as well as you possibly can. The two FETs switching 5 V are driven individually so that it’s possible to enable 20 V FET while still having diode-separated 5 V on the line up until the very moment 20 V appears on the line. In 5 V mode, both of the FETs conduct and the diode is bypassed. Since we’re relying on the body diode for up to 1.5 A of current flowing through it, I’m adding a Schottky diode in parallel with the body diode, it’s just a good practice for reliability. Having a diode does create a drop in the 5 V voltage, but only in the transition period – it’s bypassed by its FET in 5 V output mode. As for putting the two 20 V FETs in parallel, if there’s no 20 V charger plugged in, 5 V could theoretically leak onto the 20 V rail, but since 5 V is only produced from 20 V, I don’t worry about that.

When it comes to the 20 V input, I’m adding two sockets that will be compatible with three kinds of laptop chargers – Dell- and HP-compatible large round plug, and Lenovo square plug, since these chargers are what I have laying around. The benefit of those is that all three have a third pin, for wattage detection – Dell uses an One-Wire EEPROM, HP has a high-value pulldown from VCC, and Lenovo has a pulldown to GND. Now, older Dell and HP PSUs tend to be set for 19 V or 18.5 V, so it’s also going to be a small experiment on how the USB-C peripherals in my posession react to voltages outside of the 20 V standard! If detection of any PSUs fails, I’ll just default to 3 A, to stay safe – this allows me to add a generic barrel jack in parallel and get 60 W charging without any identification, in case I’m ever stuck on an island with my laptop fully discharged, and all I have is handy is this board pre-programmed and a car battery.

Now, I’ve built this circuit on my PD experiments protoboard, and all that’s left is writing code for it. I’m going to follow the tradition of these articles and write the PD code in MicroPython, running it on a RP2040 with a FUSB302 attached, weaving this code into my small but growing PD stack as I go.

Next article, let’s go through the software, actually test this code on a few USB-C devices – and find out about a surprising and wonderful feature of USB-C that other hackers haven’t yet discovered, but we are about to!

43 thoughts on “USB-C For Hackers: Build Your Own PSU

      1. This project is pretty much exactly what I wanted, but I don’t see much in the the project about a display or adjustablity. Does the project support an OLED display and adjustment via a potentiometer?

      1. Which, if you’ve priced out USB-C PD power supplies recently, is an awesome hack.

        They’re basically smart wall warts, but our local electronics store wants like 50 bucks for one, when I’ve got three or four discarded laptop power supplies in my closet.

        This is a very cool project, IMO.

        And then, of course, you can use all of your USB-C powered devices that you’ve made yourself with the power buddy / whatever. :)

        1. Alternatively they are available pre-made for $4 on Aliexpress. Have a Lenovo “slim tip” one side, and a USB C jack on the other.

          I for one lament the loss if 12v or 9v. Seems most supplies advertise one or the other. With PD.triggers being so cheap ($2 or so) it would be nice to convert all your small DC equipment to USB C. Like Cable Modem, electronic keyboard, Blu-Ray player, etc etc.

          I liked the hack that uses current controlled PD to make a battery charger.

    1. this is not a USB-C PSU, it’s a PSU powered from USB-C. That one, you can also build by following the Talking&Replying PD articles and then adding PPS request sending code (which is already in my stack!). When it comes to building an open-source PSU (esp one that can do PPS), I haven’t seen anything open-source that actually works.

  1. I just wrote a long comment which I LOST because of an unspecified error – something about filling fields. I had already signed in by email. THIS NEW COMMENT SYSTEM NEEDS FIXING BADLY!!!

  2. Great article – looking forward to more.

    One word of caution about “by adjusting the PSUs feedback line, you can get all the intermediate voltages you could want”. That’s safe to do with a power supply that’s designed for it, but resist the temptation to take apart your bog-standard laptop brick and change its feedback resistors. It’s designed to be stable with that amount of feedback, and any significant change could cause unwanted oscillation, noise, voltage instability, and possibly a dramatic release of magic smoke.

    Request to the powers that be at Hackaday: please PLEASE reinstate the “stay logged in” button for those of us who don’t have Google or Facebook accounts and log in by email instead. Having to sign in for every single comment is a powerful deterrent.

    1. WordPress VIP handles the comments for us, and none of this is/was done on our end. But, we _can_ submit bug reports, and they usually get acted on. It should be keeping you logged in automatically, AFAIK.

      When they switched up the comments, and they concluded that older cookies might be the problem because the multiple-logins weren’t necessary with newer accounts. I don’t know if they were testing the email-only logins, though.

      Can you clear out any old WordPress / Hackaday / Jetpack cookies and see if that fixes it? If it doesn’t, I’ll put in another bug report.

    2. Same; I cleared the cached stuff and still no luck with remembering the email-only method although i can at least select it from my browser’s fill suggestions rather than retype. Haven’t tried all possibilities e.g. other browser, other device, etc yet.

    1. as pelrun points out, this is not a USB-C PSU, this is a PSU powered from USB-C. Those have gotten pretty popular, which is lovely! “20V DC PSU to USB-C laptop charger conversion” is what’s missing from the open-source world, and what this article tackles.

    1. It’s the Altmode Friend devboard! The AF an open-source RP2040+FUSB302 module that can be used in any projects where you want PD (power sink, power source, DisplayPort, hub and so on), fully open-source, and the devboard is for making use of this module in +- any application you want (except high-speed signals, though I’ve used it to prototype PD code for DisplayPort too). There’s also the v3 of the AF module, where I’ve added a whole bunch of features like an onboard RGB LED and two small buttons – will push it sometime soon! As for the cell design, yes, it’s been super helpful to my own tinkering too! I’m soon going to release a devboard based on it – one thing I want to change, is changing circular THT pads to rectangular, seems like it’ll help solderability with no tradeoffs. You can get the pads from the devboard files, and I’ve also published the 4×4 proto pad footprint on Hackaday Discord at some point.

  3. The picture of ‘Dell to USB C’ is actually a Lenovo ‘Slim Tip’ adaptor. Slightly confusing. Also only about 4 bones and less than that for shipping if you have need of one.

  4. Can a USB-C power supply which has already negotiated with a device contact the device and re-negotiate?

    I’m guessing not. But I think that needs to be a thing before a power spec can be considered to be the one, final universal spec.

    The use case would be charging multiple devices from the same power supply. That would be more efficient than charging each with a separate supply right?

    Maybe there can be multiple rails at different voltages internally so that devices aren’t forced to pick the same voltage. But when one device is plugging along pulling the supply’s maximum rated current for it’s favorite voltage, then a second one is plugged in that wants that same voltage.. it would be nice to be able to re-negotiate the first at a lesser current in order to share the rail with the second.

    Or.. I guess it could just totally interrupt the connection to the first device making it think it has been unplugged then re-negotiate that way. Kind of a crude solution, especially if it might cause the device to decide to power down… but better than nothing.

      1. Charging lipos generally has two stages, first a constant current stage as the battery voltage rises to near 4.2v, followed by a constant voltage stage where the current slowly drops as the battery voltage asymptotically approaches the supply voltage.

        At no point does the charging *voltage* drop, and the decreasing current draw in the CV stage is purely a function of ohms law and is not something that has to be controlled by the system.

    1. You can send out a new Source_Capabilities (voltage&current profiles offered by the PSU) packet at any time with updated profiles, and the device is obliged to respond to it by picking a new profile out of the new profiles you’re offering! So, it’s absolutely a thing – this is how “100W but falls to 60W if you’ve plugged a new device into the second port” chargers work.So, yep, your multiple-device scenario is quite viable.

  5. I’ve also disabled NoScript so I’m feeling naked right now. I’m being prompted for a login – I’ll click the Reply button without filling in the fields and see what happens… Nope, the button isn’t active – I’ll have to enter my name and email again to post this. I just checked cookies and there’s now one for jetpack.wordpress.com – I’ve deleted it but it comes back every time I reload this page. I can’t think of anything else on my end that I might try changing. Has anyone else reported this behaviour?

    1. Worth noting that the post I’m now replying to was in fact an earlier post of my own, but it appears in the main branch instead of being nested under the comment of mine that I was replying to.

    1. yo, thank you! pretty sure you’re right! now, afaict this circuit has worked for me on the protoboard, so now, I gotta check why that is =D my suspicion is that I’ve actually assembled it the way you suggest, except without the zener diode, and then made an incorrect schematic for the article. Welp, the P-FET symbol for gate drive has to be replaced with N-FET symbol anyway, so ig gotta find time and fix this sometime soon!

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.