Adjustable Constant Current Source and Constant Current Sink

by RobBest in Circuits > Microcontrollers

967 Views, 8 Favorites, 0 Comments

Adjustable Constant Current Source and Constant Current Sink

Front_Side_Thumbnail.jpg

An adjustable voltage is often easy to get or to build but if this is not always the case for an adjustable current. Sometimes I need a constant current but it is not always the same current. Instead of constantly making a different constant current source I decided to make an adjustable current source. And while I was building that, I added the feature that it could also sink a constant current.

This device can source a current or sink a current varying from 0 to 1000 mA. The main features are:

  1. Source a constant current
  2. Sink a constant current
  3. Timer with mAh calculation
  4. Auto-off when no current is flowing
  5. Calibration

The timer functionality was added later. It can be used to charge NiMH batteries. To fully charge an empty NiMH battery, it needs to be charged with 1/10th of its capacity for 14 hours.

Three buttons are used to control the device: UP, DOWN and ENTER. Feedback to the user is given using an SSD1306 display. For this device I added an on-board Ampere meter but this is not mandatory. You do need an Ampere meter for calibrating the device.

The hardware is controlled using a PIC16F1765, programmed with the JAL programming language.

An external power DC supply of 5 Volt is used to power the device. A 5 Volt DC adapter will do as long as it can supply the maximum current of 1 Ampere.

Supplies

You need to have the following components for this project:

  1. A breadboard
  2. 1 * PIC Microcontroller 16F1765
  3. 1 * SSD1306 display
  4. 1 * 3.3 Voltage Regulator LP2950
  5. Transistors: 1 * BD137, 1 * BC639
  6. Electrolytic capacitors: 100 uF/16V
  7. Ceramic capacitors: 2 * 1uF, 2 * 100 nF
  8. Resistors: 1 * 33k, 3 * 4k7, 2 * 1k, 2 * 220 Ohm, 1 Ohm/5Watt
  9. Leds 5mm: 1 * Red, 1 * Blue
  10. 2 * 5 Volt Relays with make and break contact
  11. 1 * DC Power Jack
  12. Optional: DC Ampere meter 1 Ampere, Header for PIC programmer

The Hardware Design

Schematic_Diagram.png

See the schematic diagram. The heart is formed by a 14-pin PIC16F1765 Microcontroller. The main reason for selecting this PIC is because it has both a 10-bit Analog to Digital Converter (ADC) and 10-bit Digital to Analog Converter (DAC) on board which gives the best resolution. If only a current source is needed, the relays and the transistor BC639 could be left out. The default position of the relays is for sourcing a current.

Another advantage of this PIC is that it has an on-board opamp. The on-board DAC cannot drive a high current and must be buffered. The on-board opamp is used for that purpose, which is capable of driving 100 mA which is more than sufficient for driving the BD137 power transistor directly. The BD137 is set-up as emitter follower.

After debugging the software, it took some time to get the device working correctly. The main issue was the SSD1306. This module can be – and was - connected to 5 Volt, but operates at 3.3 Volt. It uses an on-board voltage regulator for that. The IIC pins of the SSD1306 only operate on 3.3. Volt. Normally this would not be a problem when the PIC is operating at 5 Volt but it seems that the SSD1306 module creates a lot of noise on the IIC pins. This lead to data corruption for the SSD1306 and a very slow response of the device due to the errors on the IIC bus. This was solved by adding a low-drop LM2950 3.3 Volt regulator and supply both the SSD1306 and the PIC with his voltage. This change made it immune to the generated noise which was still present.

Building the Electronics

Board_Display.JPG
Board_PIC.JPG
Board_Relays.JPG
Back_Side.jpg

You can build the circuit on a breadboard, which I did. Due to the used cabinet the electronics was split over 2 boards, one for the SSD1306 and the PIC and one for the BD137, 1 Ohm resistor and the Relays. Make sure to connect a heat sink to the BD137.

The Software

The software is written using the JAL programming language. The software uses 5199 bytes of Flash and 227 bytes of RAM. This PIC can handle 8 kByte of Flash and 960 bytes of RAM so there is still space left to add some extra features to it. All in all around 1000 lines of JAL code where written using the JAL ADC library, JAL SSD1306 library, JAL IIC library, JAL High Endurance Flash (HEF) library and a general JAL library for printing text and data.

The software handles the buttons, the menus and the menu selections. All user settings are stored in non-volatile memory. This PIC uses High Endurance Flash for that instead of EEPROM. When the device is active the measurement using the ADC and the control of the current using the DAC is done in the main loop every 1 ms.

When the current source mode is active a red LED will be turned on, in current sink mode a blue LED will be turned on. In the manual more information can be found on how to operate the device.

Demonstration

Adjustable constant current source and constant current sink

The video shows the device in action after power, showing the following functionality.

  1. Calibrating the device to 1 Ampere
  2. Current source to charge an NiNH battery with 200 mA
  3. Current sink to discharge an NiMH battery with 400 mA
  4. Auto-off feature
  5. Capacity calculation feature

Have fun building your own project and looking forward to your reactions.