For an electrochemical etching process I am trying to put together a battery powered, somewhat accurate current source able to provide 1mA to 5mA to a load with a varying resistance. (to be specific, it should be able to switch between 1mA, 2mA and 5mA to a load that is less than a few kΩ.)
The idea I had was to control the current through an NPN transistor using a low-pass filtered PWM signal from a microcontroller:
The values are chosen based on what I had lying around, making sure that the time constant of the low-pass filter is large enough to reduce the ripple somewhat, and R1 limits the output current to about 6mA. This results in the following simulated output current (red) when the duty cycle (blue) is swept from 0% to 100%:
I thought it would then be possible to use one of the analog inputs of the microcontroller to read out the voltage over the current limiting resistor R1 and use that to calculate the current through it according to Ohm's law. Then I could adjust the PWM duty cycle from the microcontroller using simple PI control.
The use of a microcontroller is convenient as I can show the measured current on a display without having to include a complete multimeter in the setup. Additionally it means I can switch between the target currents with a single button rather than having to use something like a potmeter to adjust the current with less precision.
After implementing this circuit though I ran into something unexpected. The PI control works well and quickly settles on the PWM where the calculated current through R1 is equal to the target current. If I use a multimeter to measure the current through R1 this also matches.
However, if I measure the current in series with the load I measure a current that is about 20% to 30% lower for all current settings. I am using a 220Ω load and the 5V microcontroller supply voltage as Vbat for testing. This supply should be sufficient to drive this load according to the previous plot which uses these parameters.
What could be the problem here? Did I overlook anything in the design? Is my multimeter at fault? :)
Thanks for any insights provided.