- C++ 65.7%
- C 31.1%
- Objective-C 3.2%
| .vscode | ||
| docs | ||
| firmware/backups | ||
| lib | ||
| src | ||
| .gitattributes | ||
| .gitignore | ||
| AGENTS.md | ||
| platformio.ini | ||
| README.md | ||
Pocket DC Supply
Firmware and hardware documentation for a compact adjustable DC power supply based on an ATmega328P and an XL4015 buck converter.
The fast constant-voltage and constant-current loops are implemented in analog hardware. The firmware provides the user interface, setpoint DAC control, measurements, slow output correction, fan control, temperature monitoring, and operating modes.
Main hardware
- ATmega328P-AU, 16 MHz, 5 V
- XL4015 buck converter
- two MCP4725 DACs for voltage and current setpoints
- ADS1115 ADC for output measurements
- LM75 temperature sensor
- 16x2 HD44780-compatible LCD with an I2C backpack at
0x3F - separate I2C fan-control module at
0x31 - USBasp ISP programmer
The current hardware schematic is available at docs/hardware/Circuit.png. Read the accompanying hardware notes, because two labels in this schematic do not describe the assembled unit. The separate fan controller is documented in docs/hardware/Fan_control.png.
Repository structure
Pocket_DC_supply/
├── .vscode/ VS Code extension recommendation
├── docs/ architecture, build, and hardware documentation
├── firmware/backups/ immutable as-read recovery artifacts
├── lib/ project-local third-party libraries
├── src/ firmware source code
│ └── Menu locations/ screens for the current flat menu
├── AGENTS.md rules and context for coding agents
└── platformio.ini portable PlatformIO configuration
Build
Install Visual Studio Code and the official PlatformIO IDE extension, open the repository folder, then use the PlatformIO Build task. From a PlatformIO terminal the equivalent command is:
pio run
Upload through USBasp:
pio run --target upload
No dependency on Z:\SERVER_projects\Libraries or on a separately installed
AVRDUDESS directory remains. Details are in docs/BUILDING.md.
Firmware map
src/main.cpp— initialization and main loopsrc/debug_uart.h— compile-time TX-only UART diagnosticssrc/lead_compensation.h— automatic lead-resistance calibration and compensationsrc/control.h— encoder/button handling and current menu editingsrc/measurements.h— ADC conversion, DAC output, and slow CV/CC correctionsrc/display.h— LCD setup and screen dispatchsrc/settings.handsrc/eeprom_operation.h— persistent settingssrc/fan.handsrc/temp_check.h— cooling and temperaturesrc/Menu locations/— individual UI screens
See docs/ARCHITECTURE.md before changing control or regulation behavior. Planned work is ordered in docs/ROADMAP.md, and the proposed UART debug connection is in docs/DEBUGGING.md. ADS1115 conversion and ALERT/RDY details are documented in docs/ADS1115.md, and the fail-safe power-on sequence is documented in docs/SAFE_STARTUP.md.
Recovery baseline
The Flash image and fuse configuration read from the working physical device
are indexed in firmware/backups. The current dated
baseline contains tested v1.4 Debug Flash and a complete EEPROM capture that
match source commit d7c8d06. An older v1.5.0 Flash-only recovery image is also
preserved, but its matching source is unavailable. Read each baseline's
metadata before restoring it.
Hardware validation records are indexed in docs/test-results.
Project status
The assembled supply has been used under different loads for approximately two
years. Firmware V.1.16 retains the fail-safe startup, calibrated ADS1115
voltage ranges, and V2 diagnostic protocol from earlier revisions. Dynamic
Arduino String use was removed, and the Debug build now uses a compact
integer formatter plus a polling TX-only UART. These footprint changes do not
alter the release regulation algorithm. A persistent Vtrim range setting now
scales the existing voltage-dependent AUTO-correction envelope from 50% to
200%. The earlier ADS1115 repair and CV/CC baseline remain documented
separately. It also adds a bounded CONTINUITY TEST mode for unpowered boards,
using 0.50 V, a 20 mA current limit, a variable resistance tone, and protected
restoration of normal supply setpoints. Runtime fault handling, regulation
refinements, and menu refactoring will be handled in later reviewable commits.
Every output-OFF path now closes the MOS gate and commands both DACs to zero. The requested U/I values remain in RAM/EEPROM and are restored to both DACs before the gate can reopen. ADC regulation is suspended while the gate is low so background measurements cannot reapply a nonzero DAC code.
V.1.16 adds optional two-lead voltage-drop compensation. A guided calibration
uses a bounded 0.25 V / 0.25 A test, detects a shorted lead pair, waits three
seconds, averages 20 resistance samples, and stores the loop resistance in
milliohms. In CV mode the firmware adds I * Rlead to the connector voltage,
bounded to 1 V and the existing input/20 V and power limits. See
docs/LEAD_COMPENSATION.md.