One-Button USB-C PD Voltage Selector with CH224K and CH32V003

Original Instructables article: https://www.instructables.com/One-Button-Based-5-20V-USB-C-PD-Voltage-Selector/

I have worked with the CH224K USB PD sink controller before, a tiny IC that handles the entire PD negotiation for you. My previous build used fixed resistors to set the voltage. This time I wanted something more practical: a single-button selector that cycles through 5V, 9V, 12V, 15V, and 20V with LED indicators for each. The MCU I paired it with is the CH32V003F4P6 — a 32-bit RISC-V chip from WCH that costs about $0.10.

How It Works

The CH224K handles USB PD negotiation over the CC lines in the USB-C connector. Three configuration pins (CFG1, CFG2, CFG3) tell it which voltage to request from the charger. Drive these with a microcontroller and you can change voltage on the fly. The lookup table:

• 5V: CFG1=1, CFG2=X, CFG3=X
• 9V: CFG1=0, CFG2=0, CFG3=0
• 12V: CFG1=0, CFG2=0, CFG3=1
• 15V: CFG1=0, CFG2=1, CFG3=1
• 20V: CFG1=0, CFG2=1, CFG3=0

CH224K key features: supports PD 2.0 and 3.0, selectable 5–20V output, built-in CC pull-down resistors, Power Good (PG) output, SOP-10 package.

MCU — CH32V003F4P6

The CH32V003F4P6 is a QingKe 32-bit RISC-V MCU at ~$0.10, chosen deliberately so the controller does not cost more than the function it provides. It runs at 48MHz with 16KB flash, 2KB SRAM, and 18 GPIO pins. For this project I use 9 pins: 3 for the CH224K CFG lines, 5 for indicator LEDs, and 1 for the push button.

An LM317 linear regulator converts the variable PD rail (5–20V) to a stable 3.3V for the MCU supply. Critical note: set the LM317 potentiometer to 3.3V before soldering the MCU, powering it at an incorrect voltage will destroy the chip.

8766863365421711360

Schematic — CH224K CFG lines, LM317 supply, LEDs

Firmware

The firmware is minimal C written in WCH's MounRiver Studio. Three lookup arrays map mode index (0–4) to CFG pin states and the active LED pin. On each button press, the code reads the GPIO, applies a 20ms debounce delay, increments the mode index (wrapping at 4), then calls applyMode(). That function clears all LEDs, drives the three CFG pins from the lookup tables, and lights the correct LED. Boot defaults to 5V — the safest starting voltage since every PD charger supports it.

8766863538071982080

Compact 2-layer PCB from JLCPCB — USB-C left, LEDs and button right

Testing

I brought up the board with a USB meter in series for overcurrent protection. It worked first try. After confirming idle current, I switched to the charger directly and measured all five voltages with a multimeter, each one correct on button press.

8766863596380925952

Electronic Tips & Projects
PCB Trace Current Carrying Capability

How wide does this trace need to be? Get it wrong, too narrow for the current it carries. And the trace becomes a resistive heater: voltage drop, heat buildup, and eventually an open circuit. IPC-2221 is the standard that gives you the answer.

IPC-2221 Quick Reference

IPC-2221 provides empirical tables relating trace width, copper weight, and current capacity at a target temperature rise. A 10°C rise above ambient is a safe working limit for most designs.

1oz copper (35μm), external trace, 10°C rise:

• 0.5mm → ~0.9A

• 1.0mm → ~1.5A

• 2.0mm → ~2.7A

• 3.0mm → ~3.6A

Internal traces handle roughly 50–60% of the above values for the same width, they are buried in FR4 with no air cooling available.

Copper Weight

Standard PCB copper is 1oz (35μm per layer). Moving to 2oz doubles the cross-section and increases current capacity by roughly 40–50% for the same trace width. Heavy copper (3oz, 4oz+) is used in power converters and motor drives where 10A+ traces are needed. JLCPCB supports copper up to 13oz for specialty power PCBs.

8766766793509879808

Width vs. current chart — 1oz external traces (IPC-2221)

Layout Rules

Practical rules to follow during layout:

• Add a copper pour on top of high-current traces to double the effective cross-section without widening the routed track

• Use Saturn PCB Design Toolkit or JLCPCB's trace width calculator becausee IPC-2221 formulas are non-trivial to compute by hand

• JLCPCB's standard trace width tolerance is ±20%: a 1mm trace could be 0.8–1.2mm in production

• Always check voltage drop, not just thermal capacity: 2A through 100mm of 1mm 1oz trace drops about 68mV which is significant in low-voltage designs

Design & Manufacturing
6 Layer PCB Stackup: What It Is and When to Use It

6-layer PCB cross-section showing layer arrangement

A 4-layer board often is not enough when a design mixes dense routing, high-speed signals, and distributed power nets. A 6-layer board gives you two extra routing layers, dedicated power and ground planes, and better EMI shielding, at a modest cost increase over 4-layer.

Standard Stackup

The most common 6-layer arrangement:

8766765757583630336

• L1 (Top): Signal + components
• L2: Ground plane
• L3: Signal (inner)
• L4: Power plane
• L5: Ground plane
• L6 (Bottom): Signal + components

L1 and L6 each sit directly next to a ground plane, giving every surface trace a clean, unbroken return path. L3 is sandwiched between L2 (ground) and L4 (power), shielded on both sides. Which makes it ideal for high-speed differential pairs or sensitive analog signals.

Design Guidelines

Tips for 6-layer board design:

• Route high-speed signals on L1, L6, or L3, all three have adjacent reference planes
• Use L4 as a partial power pour, not a full flood, full flooding between L4 and L5 can create parallel-plane resonance at high frequency
• Never route across a split in the reference plane on any layer, return current will detour and radiate
• If mixing high-speed digital and switching power on the same board, separate ground pours and stitch them at a single point near the input connector

8766765651665141760

Dielectric layer arrangement and typical thickness values

Via Considerations

Through-hole vias on a 6-layer board traverse all six layers even if only connecting L1 to L3. The unused stub adds capacitance and degrades signal quality above 1GHz. Options to fix it:

• Blind vias (e.g. L1–L2 only) remove the stub entirely for HDI routing
• Back-drilled vias eliminate the stub on through-hole vias for critical nets

JLCPCB supports blind, buried, and back-drilled vias, check their capabilities page for minimum drill sizes and allowed layer combinations before routing.

Design & Manufacturing
How to Route Differential Pairs on a PCB

Differential signaling is used in USB, HDMI, Ethernet, LVDS, and many other high-speed protocols because it rejects common-mode noise far better than single-ended traces. Getting it right on a PCB means more than placing two traces side by side.

Impedance Target

Both traces in a differential pair must have the same length and the same impedance. A mismatch converts differential signal to common-mode noise, causing jitter and bit errors. Common targets:

• USB 2.0: 90Ω differential
• USB 3.0 / LVDS: 100Ω differential
• Ethernet: 100Ω differential

Your PCB manufacturer's stackup calculator gives you the trace width and spacing to hit the target. JLCPCB offers controlled-impedance manufacturing with ±10% tolerance, specify it at the order stage.

Routing Rules

Practical rules for differential pairs:

• Route both traces simultaneously — use the differential pair mode in EasyEDA, KiCad, or Altium
• Keep traces tightly coupled: spacing within 3–5× trace width for the full length
• Match trace lengths: skew must stay under one unit interval (UI). For USB 2.0 at 480Mbps that is roughly 14mm
• If vias are necessary, place them on both traces at the same location
• Never route a differential pair over a split or gap in the reference plane
• Maintain at least 3× trace width clearance to adjacent single-ended nets

8766764784023027712

Matched-length pair with serpentine length compensation

Length Matching

Use serpentine meanders to compensate for length skew within a pair. Keep meander amplitude under 3× trace width to avoid adding excess parasitic inductance. Place meanders close to where the skew originates, not all bunched at the end of the route. Most EDA tools have a built-in length-matching tool that handles this automatically.

Design & Manufacturing
LM358 Based Simple Waveform Generator

Original Hackster article: https://www.hackster.io/sainisagar7294/lm358-based-simple-waveform-generator-79af29

LM358 waveform generator — square and triangular outputs

I needed a quick bench tool to verify small circuits and ICs without spending $50+ on a function generator. So I built one from a single LM358 op-amp for square and triangular waves up to 5kHz, for under $2.

Circuit

The design uses a Schmitt trigger relaxation oscillator for the square wave. R1 controls the capacitor charge/discharge time and sets the base frequency range. R2 and R3 form a voltage divider that sets the waveform midpoint reference (the ground line). A 100kΩ potentiometer makes frequency variable within the range.

A series RC integrator (R4 + C2) converts the square output into a triangular wave. The RC time constant must be larger than the square wave period, otherwise the capacitor does not have enough time to form a clean ramp.

Amplitude vs. Frequency

The triangular wave amplitude is inversely related to frequency. At low frequencies, the capacitor charges more per half-cycle and gives a larger swing. At high frequencies, it barely charges before polarity flips and the output shrinks. This is inherent to RC integration. Adding a second integrator stage approximates a sine wave, but amplitude drops sharply above 1kHz. For stable sine output, a Wien bridge or Hartley oscillator is the better choice.

8766763648473669632

Schematic — square wave generator with RC integrator

Components and PCB

Components needed:
• LM358 op-amp
• Resistors: 180kΩ, 68kΩ, 39kΩ, 220Ω
• 100nF capacitor
• 100kΩ potentiometer
• Dual-rail power supply

PCB designed in EasyEDA. Square wave amplitude scales with supply voltage. For a fixed-amplitude triangular output, add a third op-amp gain stage on the output. Gerbers available in the original article, change R1/C1 values to shift the frequency range.

8766763704430149632

PCB prototype — both outputs tested

Electronic Tips & Projects
Li-ion Batteries Got a New Charging Module TP5100

Original Hackster article: https://www.hackster.io/sainisagar7294/li-ion-batteries-got-a-new-charging-module-d04a46

TP5100-based dual-cell Li-ion charging module

I am building a portable lab bench power supply that needs two Li-ion cells in series (8.4V total). The problem: standard TP4056 modules only handle a single 4.2V cell. I needed something that could charge both 4.2V single and 8.4V dual packs from a 12V adapter. That is where the TP5100 comes in a switching-mode charger with a single pin to select between 1S and 2S operation.

8766762928223727616

TP5100 Overview

The TP5100 is a step-down switching charger running at 400kHz. It accepts 5V–18V input and delivers up to 2A of programmable charging current via an external sense resistor. All protection is built in: input overcurrent, undervoltage, over-temperature, short circuit, and reverse battery.

Key specs:
• Input: 5V–18V (covers 12V adapters)
• Max charging current: 2A (programmable)
• Switching frequency: 400kHz
• Cell configuration: 1S (4.2V) or 2S (8.4V) via onboard solder pad

Charging Phases

The IC steps through three phases automatically:

  1. Trickle: if the battery is over-discharged below 2.8V, charges at 1/10th of max current until it recovers.
  2. Constant current: charges at the set max current until voltage nears the target.
  3. Constant voltage: holds at 4.2V (or 8.4V); current tapers to ~0.07C, then terminates.

Two onboard LEDs show live charge status.

8766763045760843776

Circuit with 1S/2S selection and sense resistor

8766763008968003584

Compact PCB with separated input/output sections

Testing

Important: this module does not support balance charging. For 2S packs, use identical cells from the same batch and manufacturer so initial capacities are matched.

8766763103285317632

Results 1S cell pre-charged at 4.1V: ~300mA (CV taper phase). 2S pack: ~500mA. Both are expected since cells were near full. All protection features tested and working.

Electronic Tips & Projects
Fast Charging Module for Lithium Batteries

Original Hackster article: https://www.hackster.io/sainisagar7294/fast-charging-module-for-lithium-batteries-a1eaae

IP2312-based 3A fast-charging module

The TP4056 is one of the most popular Li-ion charging modules. It is cheap, widely available, and paired with a built-in protection IC. But it uses a linear voltage regulator internally, which means significant heat at higher currents and a practical ceiling of around 450mA before the module gets too hot to handle. I built a custom board around the IP2312, a buck-based charging IC that delivers up to 3A at 94% efficiency.

8766761662903009280

Why IP2312?

Unlike the TP4056, the IP2312 uses a built-in buck converter running at 750kHz which means far less heat, far better efficiency. All protection features (overvoltage, undervoltage, over-temperature, trickle charging, short circuit) are packed into the IC itself, so no separate protection chip is needed.

Key specs:
• Input: 4.5–5.5V via USB-C or solder pads
• Max charging current: 3A (set via external resistor)
• Default nominal current: 2.1A
• Efficiency: 94% at 3.7V/2A
• Trickle charge current: 100mA
• Standby current: 40µA
• Overvoltage cutoff: Vin > 5.6V
• Battery voltage support: 4.20V / 4.30V / 4.35V / 4.40V

8766761712228294656

Schematic — buck converter section and filter stage

PCB Design

I kept the same form factor as the TP4056 board for a drop-in upgrade. Charging current is set by solder pads on the PCB back — left floating, it defaults to 2.1A. The layout follows input-to-output flow to isolate switching transients. The NTC pin is pulled down with a 51kΩ resistor as I am using this as a breakout board. Two status LEDs monitor charging.

8766761747984736256

PCB — same footprint as TP4056, USB-C input

Testing

I powered up with a 100mA current-limited supply first worked first try. Then charged a 3.9V Li-ion at default settings. Comparison with the same 4.0V battery:
• TP4056: 450mA
• IP2312: ~1A

8766761802590109696

More than double the charging rate. Heat was minimal at full load, confirming the 94% efficiency claim. All protection features tested normal.

Electronic Tips & Projects
An Optocoupler Does More Than Just Isolate a Circuit

One of the biggest challenges in electronic design is connecting low-voltage control circuits to high-voltage or electrically noisy systems without compromising safety or reliability. Direct electrical connections can expose microcontrollers to voltage spikes, ground potential differences, and electrical noise that may cause communication errors or even permanent damage.

An optocoupler, also known as an opto-isolator, solves this problem by transferring signals using light instead of a direct electrical connection. Inside the package, an LED converts the electrical signal into light, while a phototransistor (or another photosensitive device) receives that light and recreates the signal on the isolated side.

Although the signal passes through the device, there is no direct electrical path between the input and output circuits, making optocouplers an essential component in industrial automation, power electronics, and embedded systems.

image.png

Why Electrical Isolation Matters

Electrical isolation protects sensitive electronics from hazardous voltages and unwanted electrical interference. It also helps eliminate problems caused by different ground potentials between two systems.

For example, a 3.3V microcontroller can safely control a 24V PLC input or monitor an industrial sensor through an optocoupler without sharing the same electrical ground.

Isolation becomes especially important in applications involving AC mains, motor drives, industrial automation, battery management systems, and high-power switching circuits.

image.png

Common Applications

Optocouplers are found in many products that require safe signal isolation.

Typical applications include PLC input and output modules, relay driver circuits, MOSFET and IGBT gate drivers, switching power supplies, industrial communication interfaces, and zero-cross detection circuits.

Although modern digital isolators are becoming increasingly popular for high-speed communication, optocouplers remain one of the most economical and widely available isolation solutions for general-purpose embedded systems.

image.png

Recommended Devices

The following optocouplers are commonly used in embedded and industrial electronics.

Device Output Type Typical Applications
PC817 Phototransistor General-purpose signal isolation
EL817 Phototransistor Embedded systems and industrial control
TLP281 Phototransistor PLC interfaces and digital inputs
6N137 High-speed Logic Output High-speed digital communication and SPI isolation

When selecting an optocoupler, consider the isolation voltage, current transfer ratio (CTR),** switching speed**, and output type to ensure it matches your application's requirements.

An optocoupler does much more than separate two circuits. It protects sensitive electronics, improves system reliability, and enables safe communication between low-voltage controllers and high-voltage equipment. Choosing the right optocoupler for the application can significantly improve both safety and long-term performance.

#ElectronicTips# #ElectronicComponents# #Optocoupler# #Isolation# #EmbeddedSystems# #IndustrialElectronics#

Electronic Tips & Projects
TVS Diodes Stay Quiet Until They're Needed Most

Most electronic circuits spend their entire operating life under normal voltage conditions. However, unexpected events such as electrostatic discharge (ESD), cable hot-plugging, inductive switching, or nearby lightning can generate very short but extremely high voltage spikes. Although these transients often last only a few nanoseconds or microseconds, they can permanently damage sensitive integrated circuits.

This is where a Transient Voltage Suppressor (TVS) diode becomes valuable. Under normal operating conditions, it remains almost invisible to the circuit. But when an abnormal voltage spike appears, the TVS diode reacts almost instantly, diverting the excess energy away from protected components.

For this reason, TVS diodes are widely used in industrial equipment, automotive electronics, USB interfaces, communication ports, and many embedded systems that connect to the outside world.

image.png

How a TVS Diode Works

Unlike a standard rectifier diode, a TVS diode is designed specifically for transient protection rather than normal current conduction.

During normal operation, the TVS diode has very high impedance and draws almost no current. When the voltage exceeds its specified breakdown level, it quickly enters avalanche conduction, providing a low-resistance path that diverts the surge energy to ground.

Because its response time is measured in picoseconds or nanoseconds, a TVS diode can often react before sensitive ICs experience destructive voltage levels.

image.png

Common Applications

TVS diodes are commonly installed wherever external cables connect to electronic equipment.

Typical examples include USB ports, RS-485 communication networks, CAN bus systems, Ethernet interfaces, automotive power inputs, and industrial control equipment. These connections are frequently exposed to electrostatic discharge and electrical transients, making surge protection an important part of reliable system design.

Although TVS diodes improve protection, selecting the correct working voltage and package remains essential to ensure proper operation without interfering with normal circuit performance.

image.png

Recommended Devices

Several TVS diodes are widely used depending on the operating voltage and application.

Device Working Voltage Typical Applications
PESD5V0S1BA 5V USB data lines and GPIO protection
SMBJ5.0A 5V Power input surge protection
SMBJ12A 12V Industrial control systems
SMAJ24A 24V Automotive and industrial power rails

Always choose a TVS diode based on its working voltage (VRWM),** clamping voltage**, peak pulse power rating, and the expected surge environment.

A TVS diode spends most of its life doing nothing—but that is exactly what makes it valuable. It quietly monitors the circuit until a damaging voltage surge appears, then reacts within nanoseconds to help protect sensitive electronics. Adding the correct TVS diode is often one of the simplest and most effective ways to improve the reliability of an electronic design.

#ElectronicTips# #ElectronicComponents# #TVSDiode# #CircuitProtection# #EmbeddedSystems# #PowerElectronics#

Electronic Tips & Projects
A Schottky Diode Isn't Just Another Diode

At first glance, a Schottky diode looks no different from an ordinary rectifier diode. Both allow current to flow in one direction while blocking it in the opposite direction. Because of this similarity, many beginners assume they can be used interchangeably.

Schottky diodes are designed for different priorities. They have a much lower forward voltage drop and switch significantly faster than conventional silicon diodes. These characteristics make them a popular choice in switching power supplies, battery-powered devices, and high-speed digital circuits where efficiency and fast response are important.

Choosing the right diode isn't simply about its current or voltage rating—it also depends on how quickly it needs to respond and how much power loss your application can tolerate.

image.png

Why Forward Voltage Matters

Whenever current flows through a diode, part of the electrical energy is lost as heat due to the diode's forward voltage drop.

For example, a standard silicon diode typically drops around 0.7V, while a Schottky diode usually drops between 0.2V and 0.4V, depending on the device and operating current. That difference may seem small, but in low-voltage circuits it can noticeably improve efficiency and reduce heat generation.

This is one reason Schottky diodes are commonly found in DC-DC converters, battery-powered equipment, and power distribution circuits.

image.png

Where You'll Commonly Find Schottky Diodes

Because of their fast-switching speed and low forward voltage, Schottky diodes appear in many modern electronic products.

Common applications include switching regulators, reverse polarity protection, freewheeling diodes for inductive loads, battery charging circuits, and solar power systems. They're also widely used in portable devices where maximizing battery life is an important design goal.

While Schottky diodes offer many advantages, they usually have higher reverse leakage current than standard silicon diodes. This trade-off should always be considered when selecting a device for low-power or high-temperature applications.

image.png

Recommended Devices

The following Schottky diodes are widely used in embedded systems and power electronics:

Device VRRM IF Typical Applications
1N5819 40V 1A General-purpose Schottky circuits
SS14 40V 1A SMD embedded and IoT boards
SS34 40V 3A DC-DC converters and power distribution
MBR1045 45V 10A High-current power supplies and industrial applications

Always verify the maximum reverse voltage, forward current, package type, and thermal requirements before selecting a replacement device.

Schottky diodes may look like ordinary silicon diodes, but their electrical characteristics make them better suited for many modern electronic designs. Understanding their lower forward voltage, faster switching speed, and practical limitations helps engineers choose the right diode for better efficiency and more reliable circuits.

#ElectronicTips# #ElectronicComponents# #SchottkyDiode# #PowerElectronics# #EmbeddedSystems# #CircuitDesign#

Electronic Tips & Projects
Designing for Repairability: A Practical Guide for Engineers

Designing consumer products with repairability in mind starts with modularity. Break down the device into subassemblies that can be individually accessed and replaced without specialized tools. For example, using standard screws instead of adhesive or proprietary fasteners makes battery and screen replacements straightforward. This approach not only extends product lifespan but also reduces electronic waste.

Another key aspect is component standardization. Using widely available parts like USB-C ports, common battery sizes, and socketed processors allows users to source replacements easily. Avoid integrating components onto a single board if possible; separate modules for Wi-Fi, Bluetooth, and power management simplify repairs. Clear labeling and color coding further guide technicians during disassembly.

Consider the disassembly sequence. Components that fail more often, such as batteries and fans, should be the easiest to reach. Design snap-fit clips that can be released with a spudger instead of permanent plastic welds. Provide service manuals or step-by-step guides to empower users to attempt repairs safely.

Finally, balance repairability with other constraints like cost and durability. While it may add slight upfront expense, the long-term savings for consumers and the environment are substantial. By prioritizing repairability, engineers can build products that last, foster customer loyalty, and contribute to a more sustainable future.

#DFA# #EngineeringDrawings#

Mechanical Design