Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Constant current source design

  1. May 30, 2014 #1
    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 [Broken]

    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: May 6, 2017
  2. jcsd
  3. May 30, 2014 #2

    Baluncore

    User Avatar
    Science Advisor

    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?
     
  4. May 30, 2014 #3

    meBigGuy

    User Avatar
    Gold Member

    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.
     
  5. May 30, 2014 #4

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    I dont 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: May 30, 2014
  6. May 30, 2014 #5

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    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.
     
  7. May 30, 2014 #6

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    edit - skip this post, i wasnt awake yet, see followup below old jim
    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: May 30, 2014
  8. May 30, 2014 #7

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    Last edited: May 30, 2014
  9. May 30, 2014 #8

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    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: May 30, 2014
  10. May 30, 2014 #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
     
  11. May 30, 2014 #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.
     
  12. Jun 4, 2014 #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!
     
  13. Jun 4, 2014 #12

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    If you can post a sketch we'd be interested to see it !

    Congratulations on your progress, and thanks for sharing .
     
  14. Jun 25, 2014 #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!
     

    Attached Files:

  15. Jun 25, 2014 #14

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    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 gotta do it.

    Patch a 1 meg from that opamp's + input to common and see if it straightens out.
     
  16. Jun 25, 2014 #15

    Baluncore

    User Avatar
    Science Advisor

    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.
     
  17. Jun 25, 2014 #16

    Baluncore

    User Avatar
    Science Advisor

    @ 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.
     
  18. Jun 25, 2014 #17

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    The digital pot needs to be handed signal that lies between its supply rails so i dont 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: Jun 25, 2014
  19. Jun 25, 2014 #18

    Baluncore

    User Avatar
    Science Advisor

    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.
     
  20. Jun 25, 2014 #19

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    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 ?
     
  21. Jun 26, 2014 #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!
     

    Attached Files:

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Constant current source design
  1. Constant current source? (Replies: 45)

Loading...