Constant current source design

In summary, the design is for a digital constant current source with a digitally controllable range of maximum current outputs. The input voltage range is 9 to 14 volts. The current source would be able to be turned on and off fairly rapidly (40Hz) via a digital signal. However, there is a problem with the use of a digital potentiometer in the circuit and testing has shown that resistance of the load resistor has a large impact on the current that is drawn, resulting in a current to level smaller than the current sources level.
  • #1
HHOboy
32
0
Hey guys,

I have been trying to design a constant current source that has a digitally controllable (μcontroller) range of maximum current outputs. Ideally the source would be able to be adjusted from .25mA to 2mA. The input voltage for the source would be in the range of 9 to 14 volts. Also I would like to be able to turn the source on and off fairly rapidly (40Hz) via a digital signal but have not really gotten to this aspect yet in my designs.

So far I have tried using an lm317 with a digital potentiometer to set the current level but have not had much success. Here is a picture of the basic circuit but in my case a 10kΩ digital potentiometer (MCP41010) is R1
lm317b.jpg


When testing the circuit with varying simulated load resistors for some reason the resistance of the load resistor has a large impact on the current that is drawn where it should be limited to a constant current assuming that the resistor is not too large and results in a current to a level smaller than the current sources level.
I believe there is a problem with the use of the digital potentiometer because I have had the circuit work with a regular analog potentiometer in its place. I do not know what the problem because I have measured the digital potentiometer's resistance with my multimeter and it seems to swing over the correct resistances with a code I wrote. Here is a rough arduino sketch to test it...

#include <SPI.h>

int bob = 10;

void setup()
{
pinMode(bob,OUTPUT);

SPI.begin();
}

void setvalue(int level)
{
byte command = B00010001;
digitalWrite(bob,LOW);
SPI.transfer(command);
SPI.transfer(level);
digitalWrite(bob,HIGH);
}

void loop()
{
int i = 0;
while(i<=255)
{
setvalue(i);
delay(1000);
i++;
}

while(i>=0)
{
setvalue(i);
delay(100);
i--;
}

}


I have also tried another method with a lesser know chip called the lm334 here is a pic of the basic design however I left off the amplifying transistor as well as R2 and R1 with R3 being the same digital potentiometer
http://www.bristolwatch.com/ccs/lm334.jpg

I had some success with this method as I got an output that could range from a current of .7mA to a current less than .01mA. One problem that I had was that I could not find an easy way to amplify the .7mA to 2mA because I am relativley new in electronics and do not have much experience with op-amp circuit design. The source also works by sinking current so that is also throwing me off. The only amplification method that I can figure is to use a PNP transistor as in the diagram but they all have gains that are much too high for my purpose.

It would be awesome if you guys have any suggestions for what I have already tried or any brand new ideas. I think my next attempt is to use a simple op-amp circuit with the digital potentiometer.
I was also looking into controlling the current with a pwm signal from the μcontroller but could not find much of anything.

Thanks for any help you can give!
 
Last edited by a moderator:
Engineering news on Phys.org
  • #2
Digital potentiometers are not reliable as variable resistors, only as potential dividers.
That is because their temperature coefficient is not matched to an external resistor.

Do you need a steady current or is the on/off duty cycle current from a PWM OK?
You require 0.25 to 2mA, but in steps of what size, or how many steps do you need?
 
  • Like
Likes 1 person
  • #3
Use a DAC. Use it to drive a voltage to current converter, or a current mirror.

There are current and voltage output DACs with variable reference inputs.
 
  • Like
Likes 1 person
  • #4
I don't know for sure, but two things to check:

LM117 datasheet at
http://www.ti.com/lit/ds/symlink/lm117.pdf
figure 15 suggests the device needs minimum current of a milliamp or two and you're trying to use it down to [STRIKE]1.4[/STRIKE] 1/4 milliamp. Figure 47 places a limit of 120 ohms on R1. That's consistent with current range in table on page 6, parameter "Load Regulation" which shows minimum current of 10 ma.
Could it be i have datasheet for a different LM117 than you're using ?

also suggested is a bypass capacitor on input, fig 1.


Your MCP datasheet at
http://ww1.microchip.com/downloads/en/DeviceDoc/11195c.pdf
says it works fine as a rheostat, as you are doing, but section 4.1 (page 14) cautions you to limit current to 1 milliamp. You might get away with two...

So, first try your circuit with a couple different values of fixed R1 resistors to see whether your trouble lies with the digital rheostat or with the LM117's minimum current capability .
Latter seems to fit your symptom.

neat project. Hope you get it going.
 
Last edited:
  • Like
Likes 1 person
  • #5
er, um, by the way - don,t exceed Vdd on that MCP rheostat, see line "Voltage Range" in DC Characteristics tables on pages 2, 3, and 4, and "Absolute Maximum Ratings" page 5.
 
  • #6
edit - skip this post, i wasnt awake yet, see followup below old jim
I think my next attempt is to use a simple op-amp circuit with the digital potentiometer.

sounds good. 2ma is well within drive capability of everyday opamp. I like the LM324 for its universal availability and 25 cent price. And it'll work down to negative supply rail so single supply works well.

This thread has drawing of a current source i built decades ago:

https://www.physicsforums.com/showthread.php?t=580295

I needed 5 amperes hence the low ohm resistors and power mosfet.
Just wanted to show you the current sense method...

CUR_INJx.jpg


You could put your lamp where i have the the mosfet, forget the meter, and swap opamp's + & - inputs since we no longer invert with the mosfet...
Your digital pot would replace my R3R4.
Make current sense resistor (R1R2 ) = 2.5 K so 0 to 5 at wiper would give 2ma to zero current.

Observe the LM324 needs "headroom" so its supply must be a volt or two greater than lamp supply. I had +12 handy, +7 should work..

good luck !

old jim
 
Last edited:
  • #7
edit - skip this post, i wasnt awake yet, see followup below old jim

oops - single supply LM324 may not sink 2ma at zero out, it needs headroom on that end too if it is to accept current...
here's a DN article about that
http://edn.com/design/analog/4331069/Current-source-enables-op-amp-s-output-to-go-to-ground

do you have some negative available for pin 11? A volt should do.

old jim
 
Last edited:
  • #8
Wow ! Above two posts are what happens when one starts typing before his morning coffee...

LM324 will source 10 miliamps with ease

so a simple "follower with gain" would do your job

page 8 here
http://www.ehu.es/instru_virtualdaq/Planoak/LM324.pdf

figure "Non-inverting DC Gain"
lamp is R2
2.5K current sense is R1
0-5volts from your digital potentiometer into the + input gives 0 to 2 ma through your lamp

with three amplifiers left over !i'd like to delete those two prior posts...
but that's my vanity showing. Gotta own up to my mistakes.
Have a laugh on me !

old jim
 
Last edited:
  • #9
Hey Jim, Thanks for the reply, I wasn't planning on having any negative voltages available but there is a possibility that I could. I like the op-amp design and will try prototyping it and see what I can do. I think that I will give up on trying to use the digital pot as a rheostat with the lm317 due to the points you made in your first posts.

Regarding meBigGuy's post I like the idea and researched it a bit. I found a temperature independant current follower design in this picture

200px-Simple_bipolar_mirror.svg.png


I tried prototyping this circuit and had some success, I used ~2.5kΩ for the input resistor in the diagram (5V / 2.5kΩ = .002A). I also attached the PWM output (5V max) of my μcontroller to the Vin terminal in the diagram without any filtering. For the transistors I am using two 2N5088. When I "short" the output of the source (no load resistor) I get exactly 2mA, as I do when I use small resistor values such as 220Ω. When increase the resistance to 2kΩ the current draw drops off to around 1.8 mA which isn't a huge problem but it would be nice if it were more steady over load resistance changes. Maybe I need to be using different transistors, or a fancier current follower.

One more thing, if I end up using the current follower method I will want to use a filter to keep the choppy PWM signal out of the output. I found this filter designed for 5volt PWM and was wonder what thoughts you guys have on it. I believe that the potentiometer on the far right is for volume control and I am planning on leaving it out (the filter was designed to filter PWM that drives a speaker).

dds_lowpass1251-360x89.jpg
 
  • #10
Hey Jim, saw your last reply after I finished writing mine, I will look for some LM324's I thought that I have some on hand and will begin prototyping it and let you know what happens.
 
  • #11
Hey Jim! I just got the circuit together and it is working great with an analog potentiometer and I expect it to work just as well with the digital potentiometer because it will not be in rheostat mode. I wanted to thank you for all of you and everyone else for all the help. I would consider this issue solved!
 
  • #12
If you can post a sketch we'd be interested to see it !

Congratulations on your progress, and thanks for sharing .
 
  • #13
Ok guys another question regarding this circuit. I am trying to use an oscillator circuit that I made in order to control the current source. The oscillator works fine but produces a signal with a DC offset, and the final output needs to be completely AC. In order to remove the offset I placed a .01μF ceramic disc capacitor in series with the output of the oscillator to the current source. I have attached a picture of the schematic for the oscillator circuit and current source.

Now normally the circuit does not work correctly because the opamp in the current source seems to stick to the upper supply rail. I was testing the circuit with my scope and found that when I probe the point between the capacitor and the opamp input and found that when it is probed then the output of the current source works as expected (verified with the other channel on the scope and a multimeter measuring the AC current output). I have made a video showing everything described here if you actually want to see what is going on on the scope. The video can be found here:

https://www.youtube.com/watch?v=t_LNwKp-bCU&feature=youtu.be

At first I thought something was very wrong with the design but the discovery with the scope leads me to believe that it may be an relatively simple fix and due to my little knowlage of AC circuits and opamps. Any help would be much appreciated. Thanks!
 

Attachments

  • IMAG0119.jpg
    IMAG0119.jpg
    21 KB · Views: 1,005
  • #14
Neat approach !

All opamps have a trait called "Input Bias Current" , a rather nondescriptive name. I've heard it called "Pump Out Current" which is a little more descriptive. What that is is a trickle of DC current that must be allowed to flow either into or out of the opamp's input pin.
Observe it's maybe 45nanoamps typical for Lm324, 200 max. Look at parameter "Input Bias Current" on this datasheet
http://www.ti.com/lit/ds/symlink/lm124-n.pdf

That small current produces a small DC voltage drop across the input resistor, notice if your input resistor were 1 megohm that'd be 45 millivolts.
But your input resistor is a capacitor which that small DC current will slowly charge to a substantial DC voltage , just as your 'scope shows..
The scope is probably 1 meg or 10 meg input and it provides the necessary DC path to circuit common for the input bias current. That's why it only works when your'e looking at it with scope.

When you study opamp tutorials you'll be cautioned about providing a DC path for those pesky bias currents. You just got to do it.

Patch a 1 meg from that opamp's + input to common and see if it straightens out.
 
  • #15
jim hardy has correctly spotted the DC input bias problem, but I still have a few concerns about this circuit.
Placing 1M from opamp +input to common may still make for a big offset voltage.
Rs * I_bias_max = 1M * 200nA = 0.2V

So instead consider moving the 0.01uF capacitor to between the digital pot and the op-amp that drives it.
That will both AC couple and provide a DC path to the opamp input through the digital pot.
At such a low frequency, you will need to increase the value of that coupling capacitor to 22uF.
As with your oscillator capacitors, it will need to be an AC capacitor, not a polarised electrolytic.

The 10k resistor remaining in series between the digital pot and the opamp +input is not needed.
It was there to correct the input voltage difference due to opamp input bias current.
10k * 200nA = 2 mV, which is unimportant, (and the wrong way), in this circuit.
Ideally it should have a value similar to “R” in parallel with the load resistance.
That is lower than the digital pot, so it is better to replace that 10k input resistor with a wire link.
 
  • #16
@ HHOboy.
Your oscillator is a low-pass feedback phase-shift oscillator.
I expect it to produce a sine-wave output clipped in amplitude by the (+) and (0) power supply rails.
To get an On–Off signal I would have expected you need a square-wave, not a sine-wave output.
With a phase-shift oscillator, that would require high-pass feedback elements, i.e. swapped R and C.
But there are much simpler controllable square-wave oscillators.

I believed that the original requirement was for a gated, 50% duty On/Off oscillator.
With Off being a Zero current, and On being a programmable current.

Now that you have AC coupling, there will be positive and negative controlled currents.
That will produce positive and negative output voltages across the load.
With the sine wave there will be a short low current period, there will be no 50% duty Off.

Maybe AC coupling with the 0.01uF capacitor was a distraction and should never have been inserted.
The 50% duty cycle problem being all along due to the sine-wave oscillator output.
 
  • #17
So instead consider moving the 0.01uF capacitor to between the digital pot and the op-amp that drives it.
That will both AC couple and provide a DC path to the opamp input through the digital pot.
At such a low frequency, you will need to increase the value of that coupling capacitor to 22uF.
As with your oscillator capacitors, it will need to be an AC capacitor, not a polarised electrolytic.

The digital pot needs to be handed signal that lies between its supply rails so i don't think it can handle negative . The cap needs to stay on its output side.

Agreed with Baluncore the 10K is not needed.

Since you're driving the rightmost LM324 as a follower, Zin is very high so the cap can remain small; Baluncore and i differ there..

At 40 hz a 0.01uf cap is 398kohms , so using a 1 meg resistor to provide return path for bias current won't hurt you frequency wise. You've already seen that with your scope.
frequency rolloff starts when Xc = R,
and
Xc = 1/(2∏fc) .

If you went to a 0.1uf cap and 100K resistor it'd assure offset due to max input bias current of 200na stays less than 20 millivolts (0.2ua X 1/10 meg = 20mv)

your youtube was great, you clearly stated the question and i enjoyed the 'scope work.

Nice Job. Keep us posted.
 
Last edited:
  • #18
Unfortunately I do not have bandwidth or capacity for youtube.
Does the oscillator generate a sine or a square wave ?
I still think AC coupling is the problem, not the solution.
 
  • #19
It was a very decent looking sine wave;
quadrature oscillator , fig 8 here
http://www.ti.com/sc/docs/apps/msp/journal/aug2000/aug_07.pdf


AC coupling with no provision for bleeding away bias current was sure enough the problem.
Shorting the cap should give him sinewave centered around ( 2.5 volts X pot setting)/(Rsense) .

Maybe he'll try it for us ?
 
  • #20
Sorry guys I had to work last night and this morning but now I have some free time. I put a 1MΩ resistor between the input of the opamp and ground as suggested and that has done the trick! Also I removed the 10kΩ resistor that you guys said was unnecessary and that seems fine as well.

I wanted to thank Jim for the excellent explanation of the pump out current, it makes sense and I can add it to the list of things I have learned from this project.

Regarding Baluncore thanks for the point that the 10KΩ resistor is unnecessary. Also the current output does need to be true AC not just alternating between 0V and 5V, and it does need to be a sine wave as well.

I have attached several pictures so that you guys can see the final product and so Baluncore can see the wave because of the youtube problems. The first picture is just the updated breadboard you may be able to see the 1MΩ resistor behind the cap on the left of the board, also I removed the 10kΩ resistor and replaced it with a wire connection. The second picture is the waveform that I get on the simulated load resistor(in this pic it is 2KΩ). The third picture is the same as the second but I raised the value of the load resistor to 4.7KΩ and you can see the corresponding increase in amplitude to maintain a constant current of approximately .30ma AC. Also it should be noted that I am not probing that capacitor in the second and third pictures, so the problem is fixed .

Now I plan on trying to reduce the distortion that can be seen on the top of the sine wave and bring the frequency closer to 40 Hz. I think that getting some more precise components for the oscillator and putting the circuit on a proper proto board will help some.

Thank you guys for all of your help I really appreciate it and learned a lot!
 

Attachments

  • IMAG0126.jpg
    IMAG0126.jpg
    52.8 KB · Views: 925
  • IMAG0123.jpg
    IMAG0123.jpg
    33.3 KB · Views: 899
  • IMAG0124.jpg
    IMAG0124.jpg
    32.3 KB · Views: 872
  • #21
It's useful to remember the key characteristic of an ideal constant current source or a Norton source: it looks like a high impedance/resistance.

The problem with many of the designs discussed is they are low impedance as seen looking into the current source which means they don't behave much like ideal current sources. The reason is most are implemented with an emitter or source as the output. Emitters, sources (and cathodes) are low impedance. This is the "fail" of using a conventional 3-terminal type of regulator. Thus they resemble ideal voltage sources or Thevenin sources.

What you want instead is a collector or drain (or anode) instead. Thus a current mirror is a good choice. Also you can flip a conventional 3-terminal implementation to output from a collector (usually by switching the NPN of a voltage regulator with a PNP and making some biasing/feedback modifications such as using current sensing to generate the feedback signal).
 
  • #22
HHOboy said:
I plan on trying to reduce the distortion that can be seen on the top of the sine wave
The flat top is due to the amplitude being set by the opamp output hitting the supply rail limits on the amplifier stage where you pick off the sine wave.

To greatly reduce the flat top you must limit the amplitude in the LPF after the take off point. That will allow all three low-pass filter stages in the feedback oscillator to remove the odd harmonic distortion before the signal is used.

Attached is a crude first approach to softer amplitude limiting.
 

Attachments

  • Amp_regulation.jpg
    Amp_regulation.jpg
    18.3 KB · Views: 828
  • #23
jsgruszynski said:
The problem with many of the designs discussed is they are low impedance as seen looking into the current source which means they don't behave much like ideal current sources.
I believe you are not considering that the load is in the negative feedback loop of the op-amp.
That is the game changer.
 
  • #24
Hey OldJim,

Your insight is really helpful. I'm doing something similar to what HHO did only this time I want a current source that can supply between 100 and 160 mA in steps of 5mA for use to control air flow in a pneumatic valve at 24V constant DC supply. Will appreciate your help. Thank you!
 
Last edited:
  • #25
So is the object to apply known current to (presumably the coil of) some device that controls airflow ?

What is the resistance of that device? In other words, will 24 volt supply have a few left over for the current controlling circuit ?

How are these "current steps" to be controlled ? Simple selector switch?

A simple LM317 voltage regulator with a current-setting resistor between OUT and ADJ pins seems easy...
http://diyaudioprojects.com/Technical/Current-Regulator/ see fig 2
probably should heat sink the LM317

do the arithmetic to size your parts for the power they'll have to handle.
 
  • #26
Thanks for your reply old Jim.
Yes, the object that controls airflow is the PVQ-33-5G-16-01 from SMC OPneumatics (page 9 of http://content.smcetech.com/pdf/PVQ.pdf)
The resistance really is nowhere explicitly stated only that it generates 4W at the 165mA max current and 0W at 0mA.
For the system I am designing, I am using the position of an object which is being tracked by a kinect camera as feedback to control the current. A digital rheostat would be ideal but from the earlier discussion on this thread, I hear it is not really as reliable as external pots "due to the temperature coefficient".
I desire for the current to be digitally controlled from my microcontroller but I would be glad to hear from you about any other ideas.
 
  • #27
  • Like
Likes jim hardy
  • #28
Well you can easily figure its resistance from power and current. I assume you're familiar with Ohm's law?
Lexilighty said:
4W at the 165mA max current and 0W at 0mA.
i come up with it'll use the whole 24 volts at 165ma. A higher supply, say thirty volts might be more convenient...
further, this line in datasheet sort of hints that a somewhat higher voltage source may be desirable:
Caution
Power Source Selection
This product makes proportional control possible with constant current.
If controlled with voltage, the output flow rate cannot be kept constant due to current fluctuation.
Use stable DC power source of sufficient capacity without much ripple.

Since you're using a closed loop high precision doesn't seem very important , you'll adjust current to put the object where it belongs ?I gather you'll want 13 discrete current values :: 100, 105, 110, 115... 160 ma?
That'll take only four binary bits .

Several different approaches come to mind.
There's plenty of good folks here with genuine expertise
i think it'd be good to hear from you what is your experience level, for that'll guide folks to recommend appropriate suggestions.
e.g. :
Is this a real hardware project or computer simulation ?
Is this a breadboard project or can you solder surface mount ?
Does your computer have logic level IO pins like an Arduino, PWM, or do you plan on serial ?

old jim

PS that's a really interesting valve you found.
Likewise MBG's Analog Devices current controller.
 
  • #29
Hi Old Jim,

Again thanks for your reply. To pick apart your questions sequentially, here are my answers:

(i) Yes, I'll adjust the current to put the object where it belongs;
(ii) It is a real hardware project;
(iii) Surface mount is not something I have done before but through-hole vero board projects is my area of expertise.
(iv) I am using the National Instrument's myRIO device for the functions you have described. I could do the PWM or serial on the myRIO.

My question, which approach would you recommend: to use the LM317 you earlier prescribed or go for the DAC of MeBigGuy? I am not so good at programming SPI devices which is why I am a tad wary of MBG's approach.
 
Last edited:
  • #30
Lexilighty said:
My question, which approach would you recommend: to use the LM317 you earlier prescribed or go for the DAC of MeBigGuy? I am not so good at programming SPI devices though which is why I am a tad wary of MBG's approach.

Looking at the National RIO information (which gives me overload), i see a couple of analog outputs.

So i think i'd try MBG's approach , because it looks like the RIO itself has a DAC that can do what the AD5446 does in that appnote.
You'll learn to use the DAC.
I once used a DAC that spoke only I^2C, ; stumbling up that learning curve was mildly painful but worthwhile.

You'll need a little more than 24 volt supply
and i'd try an inexpensive everyday opamp liike LM324, which has added advantage it's suitable for single supply.

Be advised I've never even seen a National RIO - so solicit second opinions.

Lastly that solenoid valve must have inductive and inertial time constants so be prepared to protect the pass transistor and maybe time-condition your feedback for stability.

old jim
 
  • #31
In addition to the above, I have an L298N dual H-bridge (http://www.ebay.com/itm/like/231419432905?lpid=82) with datasheet here: https://www.sparkfun.com/datasheets/Robotics/L298_H_Bridge.pdf.

I tried PWM on the outA to the valve last week but was not much successful. I could only achieve full on or full off scenario with those. I realize this might not be contributing to the conversation but I have a hunch I could control output current with this dual bridge since its datasheet says a related stuff about using it to control solenoid valves in the intro.
 
  • #32
Oops, I am just reading Old Jim's reply. Yes, I actually ordered the LM324 opamp yesterday. My question about this op amp is can it do up to 165mA load on its output?
If so, are you suggesting I use it to replace the AD8510 or OP1177 in the figures in MBG's post?
Thanks, Science Advisor! :)
 
  • #33
Lexilighty said:
My question about this op amp is can it do up to 165mA load on its output?

no, check its datasheet. There exist opamps that can deliver such current but they're expensive. I used LM12's, good for 8 amps, when they were only about $20 but last time i looked they'd gone up to over $80.

Lexilighty said:
If so, are you suggesting I use it to replace the AD8510 or OP1177 in the figures in MBG's post?

It'd replace the OP1177 .
Read up on that National Instruments computer you're using. If it has analog out,
then see fig 2 here, from that Analog device MBG linked: http://www.analog.com/static/imported-files/circuit_notes/CN0151.pdf
Do you see that the opamp is connected as a follower that will make 100milliamps per volt applied to pin 4 three? That stout FET handles the current for it.
 
Last edited:
  • #34
Oh yeah cool. I will be trying this out in the next few days when my order arrives. Once again, thank you!
 
  • #35
I think it was meBigGuy who solved this one.

If that National gizmo has its own internal DAC to make analog out , your task is simplified a lot.

I hope you'll keep us posted.
 

Similar threads

  • Electrical Engineering
Replies
20
Views
6K
Replies
5
Views
1K
  • Electrical Engineering
Replies
19
Views
3K
  • Electrical Engineering
Replies
3
Views
226
  • Electrical Engineering
Replies
10
Views
1K
  • Electrical Engineering
Replies
5
Views
1K
  • Electrical Engineering
Replies
6
Views
6K
  • Electrical Engineering
Replies
3
Views
1K
Replies
8
Views
767
  • Electrical Engineering
Replies
14
Views
813
Back
Top