Sun Deqing Turns a Low-Cost Microcontroller Into a Configurable USB Power Delivery Sink
Despite lacking a USB PD PHY, this clever hack lets a WCH CH552 negotiate a USB Power Delivery connection.
New York University adjunct professor Sun Deqing, co-founder and creative technologist at Think Create, has published a library which lets a low-cost microcontroller stand in for a more expensive USB Power Delivery (USB PD) chip — negotiating the required voltage and current from a compatible power supply.
"This project uses a general-purpose microcontroller ([the WCH] CH552) to receive and send USB PD signals over CC lines without any PHY peripheral," Deqing explains of his work. "An analog comparator and a timer receive the signal. A GPIO [General-Purpose Input/Output pin] with clamping diodes transmits the signal. The sample code makes CH552 act as a USB PD sink controller and requests a programmable voltage from a PD/PPS charger."
While Deqing's project focuses on the WCH CH552, an extremely low-cost eight-bit microcontroller with enhanced E8051 core and up to a 24MHz clock speed, it is claimed to be portable to "any general-purpose microcontroller" — providing it offers an analog-to-digital converter (ADC), comparator, and at least two digital outputs.
"USB PD uses BMC (Biphase Mark Code) over the CC lines in the USB Type-C connector to exchange data between the source and sink devices,' Deqing writes of the circuit's operation. "However, the maximum voltage of the communication is about 1~1.2V, so it can not directly interface with the digital IO of a microcontroller."
That low-voltage signal is picked up using an analog comparator with a 0.6V reference, with a timer providing the ability to decode the BMC signal into binary. The microcontroller's output, meanwhile, is clamped to 1V using a 1k resistor, standard diode, and two Schottky diodes. The cathode of the series of diodes connects to another GPIO to make the clamping controllable," the maker explains, "so any digital output will be clamped to 0~1V output."
"If a simpler circuit is desired," Deqing adds, "a CH549 [microcontroller] can also be used. The code will utilize the internal voltage reference and low voltage output capability."
A schematic and source code for the project have been published to GitHub, under a public domain license.