August 18, 2026

Precision in Every Ampere: Engineering a Versatile Constant Current Generator with the PIC16F1765

precision-in-every-ampere-engineering-a-versatile-constant-current-generator-with-the-pic16f1765

precision-in-every-ampere-engineering-a-versatile-constant-current-generator-with-the-pic16f1765

In the world of electronics, stability is the ultimate currency. Whether one is characterizing a high-performance LED, conducting chemical electrolysis, or charging sensitive battery chemistries, the ability to maintain a precise, unwavering current regardless of load impedance is a hallmark of professional-grade test equipment. A new project, centered around the Microchip PIC16F1765 microcontroller, brings this industrial-grade functionality to the maker’s workbench. By integrating both constant current sourcing and sinking capabilities into a single, compact device, this project offers a highly flexible solution for laboratory-grade current control ranging from 0 to 1,000 mA.


Main Facts: A Dual-Mode Power Solution

At its core, this project addresses a common gap in hobbyist toolkits: the lack of a reliable, programmable constant current source that can also act as a load (a "sink"). Most standard power supplies operate in constant voltage mode, which can be catastrophic for current-sensitive components.

The device distinguishes itself through several key technical capabilities:

  • Dual-Operation Modes: The unit seamlessly toggles between sourcing current (providing power to a load) and sinking current (acting as an electronic load to discharge a battery).
  • Dynamic Range: Users can dial in precise current values from 0 to 1,000 mA.
  • Integrated Intelligence: The system features a built-in timer and mAh calculation logic, making it an ideal tool for characterizing NiMH battery capacity.
  • Safety and Efficiency: The firmware includes an automatic shutdown feature triggered when current flow ceases, preventing unnecessary energy draw and protecting the hardware.
  • User Interface: Control is handled via a tactile three-button interface (UP, DOWN, ENTER) paired with an SSD1306 OLED display for real-time telemetry.

Chronology: From Concept to Calibration

The development of this project followed a rigorous engineering path, prioritizing signal integrity and thermal management.

Phase 1: Architecture and Component Selection

The selection of the PIC16F1765 was deliberate. Unlike general-purpose 8-bit microcontrollers, the 1765 series features an integrated 10-bit Analog-to-Digital Converter (ADC) and a 10-bit Digital-to-Analog Converter (DAC). Crucially, it includes an integrated operational amplifier, which allows the microcontroller to drive a BD137 power transistor in an emitter-follower configuration without requiring external op-amps.

Phase 2: Solving the Noise Floor

During the prototype phase, the development team encountered significant interference on the I²C bus. The high-frequency switching and the demands of the SSD1306 display created data corruption, leading to unstable current readings. The team successfully resolved this by implementing a dedicated LP2950 regulator to provide a clean, isolated 3.3 V supply to both the display and the microcontroller. This architectural tweak effectively decoupled the digital noise from the analog control loop.

How to Build a Variable Constant Current Source with Sink Function – Open-Electronics

Phase 3: Assembly and Thermal Optimization

To accommodate the physical constraints of an enclosure, the circuit was split into two distinct boards. The first board houses the "brain"—the PIC16F1765 and the OLED display—while the second board carries the high-current path, including the BD137 transistor, a 1 Ω power resistor, and the relays responsible for switching between source and sink modes. The team emphasized that the BD137 must be fitted with a robust heat sink, as the device is designed to handle up to 1 A, which generates significant thermal energy in the transistor.


Supporting Data: Firmware and Precision

The logic driving this system is written in the JAL (Just Another Language) programming language, chosen for its efficiency in handling hardware-level tasks.

Real-Time Control Loop

The firmware operates on a 1-millisecond update cycle. This rapid polling ensures that any fluctuations in load resistance are met with an instantaneous correction from the microcontroller’s internal DAC. By utilizing the PIC’s High Endurance Flash (HEF) memory, the device stores user-defined settings and calibration constants securely, ensuring that the unit retains its accuracy even after power cycles.

Calibration and Accuracy

To ensure the device meets the needs of precision electronics work, the system includes a software-based calibration routine. By connecting an external high-accuracy ammeter, the user can map the software’s internal DAC values to the actual output current. The LEDs—red for sourcing and blue for sinking—provide immediate visual confirmation of the operating mode, a small but vital detail for preventing accidental short-circuits during testing.


Official Responses and Implications for Makers

The implications of this project for the maker community are profound. By providing a low-cost, open-architecture alternative to commercial electronic loads, this project lowers the barrier to entry for battery testing and semiconductor characterization.

Professional Utility

In an interview-style reflection on the project’s utility, the developers highlighted that the integration of mAh calculation is perhaps the most requested feature for modern hobbyists. "When you are dealing with battery rejuvenation or capacity testing," the project lead noted, "you need to know exactly how much energy went in or out. Having this calculated on-device removes the need for external data logging equipment."

How to Build a Variable Constant Current Source with Sink Function – Open-Electronics

The Future of DIY Test Equipment

The design demonstrates that one does not need a high-end lab bench to achieve high-end results. By carefully considering PCB layout, component isolation, and thermal dissipation, an engineer can achieve performance levels that rival entry-level commercial units. The use of a simple 5 V supply, provided it can handle the 1 A current load, makes this tool highly portable.


Technical Implications for Future Iterations

Looking forward, the architecture of this device offers significant room for expansion. The modular nature of the current firmware allows for potential upgrades, such as:

  1. USB Serial Integration: Implementing a USB-to-UART bridge would allow the device to stream data to a computer for real-time graphing of discharge curves.
  2. Expanded Voltage Range: While the current iteration is optimized for a 5 V rail, implementing a buck-boost topology could allow for testing of higher-voltage battery packs or LED arrays.
  3. Advanced Profiles: The current firmware could be updated to support multi-stage charging profiles (e.g., constant current followed by constant voltage), further increasing its utility for professional battery management.

Conclusion

The PIC16F1765-based current generator is more than just a circuit; it is a testament to the power of well-considered embedded design. It proves that with a solid understanding of analog-digital interfacing, noise mitigation, and efficient firmware coding, makers can build tools that significantly enhance their diagnostic capabilities.

For those looking to replicate this project, the assembly is straightforward, provided one respects the thermal requirements of the BD137 transistor. Whether you are a student learning the fundamentals of transistor control or a seasoned engineer in need of a compact, reliable current sink for your desktop, this project stands as a definitive reference for modern electronic test equipment design.

As the landscape of hobbyist electronics continues to evolve, the demand for such precise, versatile, and documented projects will only increase, driving further innovation in the open-source hardware space. By mastering the principles demonstrated in this current generator, builders are well-equipped to tackle more complex challenges in power management and beyond.