Convert PWM to constant current (programmable current source)

Discussion in 'Analog & Mixed-Signal Design' started by Najossmith, Sep 12, 2018.

  1. Najossmith

    Thread Starter New Member

    Sep 12, 2018
    13
    0
    Hello,

    I am trying to create a pwm controlled current source, but I can't have the diode turning on and off as you might do with a transistor and LED where your eye "filters" the on and off to a constant on. I am trying to drive a laser and it needs to be on constantly.

    Similar circuit except the voltage source is an RC low pass filter with Vin over the cap. Current issue is that Vin and Vout do not follow each other as the PWM changes duty cycle.
    [​IMG] http://www.ecircuitcenter.com/Circuits/curr_src1/curr_src1.htm

    I need a 10mA - 100mA range over the load (laser diode). Currently using the AD842JN op amp, and the 2n2907 transistor.

    Thoughts, insight, wisdom?

    Thanks,
    Nathan
     
    Last edited: Sep 12, 2018
  2. danadak

    Well-Known Member

    Mar 10, 2018
    1,742
    355
    Something like this, filter PWM output and feed to
    OpAmp V+ (R1, R2 not needed). I = (15 - V+opamp) / R3

    upload_2018-9-12_19-57-46.png

    Regards, Dana.
     
    cmartinez likes this.
  3. crutschow

    Expert

    Mar 14, 2008
    20,057
    5,649
    That circuit should work.
    Post the exact circuit you are using.
     
  4. Najossmith

    Thread Starter New Member

    Sep 12, 2018
    13
    0
    Attached is the circuit I have put together.

    My problem occurs when I take the voltage across the cap and feed it into my non-inverting input. The voltage at the inputs, output, and the cap do not "follow" one another.

    I appreciate the timely response crutschow. Reading some of your older posts have really helped me get started.
     
  5. panic mode

    Senior Member

    Oct 10, 2011
    1,630
    450
    wrong transistor type, you are taking feedback on low side so transistor in this case need to be NPN.
     
  6. Najossmith

    Thread Starter New Member

    Sep 12, 2018
    13
    0
    Yea, that's pretty much what I have except my load is floating and not tied to the ground. I can get it to work with replacing the RC circuit with a lab supply, but once I attach it Vout and the inputs no longer "follower" each other. Any thoughts?

    And thanks for the two .pdfs, I have only skimmed them but they seem like great resources. I'll be sure to put more energy toward reading them in the morning.

    Nathan
     
  7. Najossmith

    Thread Starter New Member

    Sep 12, 2018
    13
    0
    I'll have to verify this tomorrow morning, but assuming my memory is correct (yikes) when I switched to a NPN I still did not have a functioning circuit. I know I tested a NPN as well, but I'm not sure if I switched something else as well... (bad troubleshooting, I know)

    I'll switch out the transistor type when I have it in front of me and I'll let you know what comes of it.

    Thanks,
    Nathan
     
  8. panic mode

    Senior Member

    Oct 10, 2011
    1,630
    450
    make sure that polarity is correct (E and C swapped?)
     
  9. ScottWang

    Moderator

    Aug 23, 2012
    6,366
    987
    Try to use an 1N4148(-|>|-) in parallel with a 100K to replace 47Ω and use an NPN to replace the PNP as in your first post.
     
  10. Bordodynov

    Well-Known Member

    May 20, 2015
    1,918
    578
    I think that using the AD842 operational amplifier is a bad idea in this case. The minimum supply voltage (total) is 10V. And I'm not sure that the circuit with it will be fixed with 100% negative feedback. The LT1221 chip, which is a complete analogue, has a stability with a gain of at least four.
    Tell what PWM parameters and what frequencies you want to modulate the laser. If you report this data, I will be able to draw and simulate the necessary scheme. By the way, in my collection there are models of lasers for which it is possible to set the laser parameters.
     
  11. danadak

    Well-Known Member

    Mar 10, 2018
    1,742
    355
    Last edited: Sep 13, 2018
  12. ebeowulf17

    Well-Known Member

    Aug 12, 2014
    2,469
    446
    What frequency is the PWM signal? The RC filter is going to have a really small time constant with only a 47 ohm resistor! Unless the frequency being filtered is really, really high, I don't think the RC filter is doing anything.

    I also question the value of the 27 ohm resistor. At 100mA, that will be dropping 2.7V. You'll also lose some voltage through the pass transistor. If you've got a 5V supply, you're running out of voltage for the laser pretty quickly. Depends on the Vop of the laser though. Maybe 27ohm is right.

    Anyway, at first glance I think you need to go back to NPN and get your RC filter values fixed. There should be loads of resources online to help pick suitable RC values, but if you need help with that here, you'll have to tell us the PWM frequency.
     
  13. Najossmith

    Thread Starter New Member

    Sep 12, 2018
    13
    0
    I need a current between 10 - 100 mA for the laser. Voltage max is 2.

    In terms of the minimum voltage being 10, if I had my Vcc and Vee to +/- 5 would that solve that concern?

    Thanks,
    Nathan
     
  14. Bordodynov

    Well-Known Member

    May 20, 2015
    1,918
    578
    I probably did not speak well. This operational amplifier is not suitable even with two power supplies ( + /- 5V).
    There will be oscillations of the current.
     
  15. Bordodynov

    Well-Known Member

    May 20, 2015
    1,918
    578
    Choose a different operational amplifier, with the power supply from one source and available to you. Do you need direct current, with the possibility of adjustment? If so, then there is no need for a fast amplifier!
     
  16. Najossmith

    Thread Starter New Member

    Sep 12, 2018
    13
    0
    PWM is 490 Hz.
     
  17. Najossmith

    Thread Starter New Member

    Sep 12, 2018
    13
    0

    Do you have a suggestion on the specs I would need on the new op amp?
     
  18. Najossmith

    Thread Starter New Member

    Sep 12, 2018
    13
    0
    How do I get to your collection?
     
  19. ebeowulf17

    Well-Known Member

    Aug 12, 2014
    2,469
    446
    Ok, so if freq = 490, then period = 1/490 = 0.00204 sec (2.04ms)

    Depending on how low you want your ripple to be (how smooth the signal needs to be,) you want the time constant of your RC filter to at least equal the period of your PWM signal, and probably be more like 5x the period.

    At 5x, you'd be looking at an RC time constant of ~10ms, which means when you change PWM duty cycle, it will take 10ms to reach 2/3 of the change, and 50ms to see the change fully take effect. I'm not sure if response time matters in your application. If so, you'll either need to accept more ripple in your current set point, or change to a higher PWM frequency.

    For the following example calculations, I'll use the 5x number, but you can adjust to suit once you see how it's done.

    The RC time constant (in seconds) is simply resistance (in ohms) times capacitance (in farads.) So, if we want an RC time constant of 0.01s (10ms,) then we need two numbers that equal 0.01 when multiplied together. Big caps get expensive, so let's start with something manageable, like 1uF.

    Converting the formula to solve for R, we go from:
    RC = R x C
    to:
    R = RC / C

    Since 1uF = 0.000001F, and our target is 0.01s, our resistance would need to be:
    0.01 / 0.000001 = 10,000 ohms (10k.)

    So, to get a nice smooth signal from a 490Hz source, you'd need a 1uF cap and a 10k resistor (or 0.1uF and 100k, etc...) and you'd have a 50ms response time. If you want faster response at the expense of more ripple, you can reduce those numbers somewhat, but I wouldn't go lower by more than maybe a factor of 5 (the ripple at that point will already be huge!) If you want faster response AND smooth signals, you'll need a higher PWM frequency.

    For comparison, I'm suggesting time constants of 2-10ms, and you've currently got a time constant of 0.000047 ms.
     
  20. ScottWang

    Moderator

    Aug 23, 2012
    6,366
    987
    Last edited: Sep 13, 2018
    cmartinez likes this.
Loading...